본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

컨슈머

원문 보기 위키 갱신

컨슈머 (Consumer)

컨슈머는 Kong Gateway가 관리하는 API를 사용하는 외부 클라이언트를 식별하는 엔티티예요, 애플리케이션이나 서비스, 사용자를 대표할 수 있어서 인증과 접근 제어, 사용량 추적의 기본 단위가 돼요, 이 문서에서는 컨슈머의 개념과 인증·레이트 리밋 같은 대표 활용 사례, v3.10부터 지원되는 중앙 집중식 관리 방식까지 차근차근 살펴봐요

출처: 문서

본문

Consumer란 무엇인가요?

Consumer는 Kong Gateway가 관리하는 API를 소비하거나 사용하는 외부 클라이언트를 식별하는 개체예요. Consumer는 여러분의 API와 상호작용하는 애플리케이션, 서비스 또는 사용자를 나타낼 수 있어요. Consumer가 항상 사람인 것은 아니기 때문에, Kong Gateway는 서비스를 "소비(consume)"한다는 의미에서 이들을 Consumer라고 불러요. Kong Gateway를 사용하면 Consumer를 정의하고 관리하고, 접근 제어 정책을 적용하고, API 사용량을 모니터링할 수 있어요.

Consumer는 API 접근 제어, 사용량 추적, 보안 확보에 필수적이에요. Consumer는 키 인증, OAuth 또는 기타 인증·권한 부여 메커니즘으로 식별돼요. 예를 들어 Gateway Service나 Route에 Basic Auth 플러그인을 추가하면 Consumer를 식별하거나, 자격 증명이 유효하지 않을 때 접근을 차단할 수 있어요.

플러그인을 Consumer에 직접 붙이면 rate limit 같은 특정 제어를 Consumer 수준에서 관리할 수 있어요.

 
flowchart LR

Consumer(Consumer 
entity)
Service(Gateway 
Service)
Auth(Auth
plugin)
Upstream[Service 
application]
RL["Rate Limiting 
plugin"]

Client --pass
credentials--> Service
subgraph id1 ["`**KONG GATEWAY**`"]
    subgraph padding[ ]

subgraph Authenticate ["Consumer Identity Added"]
    direction LR
    Service --> Auth
    Auth--identify 
    Consumer-->Consumer
    end
end

Consumer--> RL
end
RL --apply 
per-Consumer
rate limiting--> Upstream

style Authenticate stroke-dasharray: 5 5
style padding stroke:none!important,fill:none!important

  

Consumer의 사용 사례

Consumer의 일반적인 사용 사례는 다음과 같아요:

인증

설명: 클라이언트 인증은 Consumer를 설정하는 가장 흔한 이유예요. 인증 플러그인을 사용하고 있다면 자격 증명을 가진 Consumer가 필요해요.

Rate limiting

설명: 티어를 기준으로 특정 Consumer에 rate limiting을 적용해요.

변환

설명: Consumer에 따라 응답 본문에서 값을 추가하거나 제거해요.

중앙 관리형 Consumer v3.10+

Consumer는 Konnect 리전에 범위가 지정되어 중앙에서 관리되거나, control plane에 범위가 지정될 수 있어요.

중앙화된 Consumer 관리는 다음과 같은 이점을 제공해요:

  • Consumer 아이덴티티를 중앙에서 설정: 여러 control plane에서 정의하는 대신 Consumer를 한 번만 정의해요.
  • 중복된 Consumer 구성으로 인한 충돌 방지: 여러 control plane에서 Consumer 아이덴티티 변경 사항을 복제할 필요가 없고, Consumer 구성이 충돌하지 않아요.
  • control plane과 data plane 간 구성 동기화 문제 감소: 중앙에서 관리되는 Consumer는 control plane에서 data plane으로 내려보내는 구성에 포함되지 않기 때문에, 구성 크기와 지연 시간이 줄어들어요.

중앙 관리형 Consumer는 control plane 외부에 존재하기 때문에, 여러 control plane에서 사용될 수 있어요.

다음 표를 참고하면 중앙 관리형 Consumer를 사용해야 할지, control plane에 범위가 지정된 Consumer를 사용해야 할지 판단하는 데 도움이 돼요:

하나 이상의 control plane에서 Consumer 아이덴티티 공유

중앙 관리형 Consumer: 지원 control plane 범위 Consumer: 미지원

지원되는 인증 방식

중앙 관리형 Consumer: Key auth control plane 범위 Consumer: 모두

플러그인을 Consumer에 직접 범위 지정

중앙 관리형 Consumer: 미지원 control plane 범위 Consumer: 지원

플러그인을 Consumer Group에 범위 지정

중앙 관리형 Consumer: 지원 control plane 범위 Consumer: 지원

Konnect Consumers API를 사용하면 Consumer를 중앙에서 관리할 수 있어요. 이러한 Consumer에 대한 CRUD 권한은 Org Admin과 control plane Admin에게만 있어요.

Consumer를 중앙에서 생성할 때는 realm에 할당해야 해요. realm은 조직 경계로 정의되는 아이덴티티를 중심으로 Consumer를 그룹화하는 것으로, 예를 들어 production realm이나 development realm이 있어요. realm은 Konnect의 지리적 리전에 연결돼요. 또한 중앙 관리형 Consumer가 인증할 수 있으려면 특정 Key Authentication 구성이 설정되어 있어야 해요.

전체 튜토리얼은 Konnect에서 중앙 관리형 Consumer 생성을 참고하세요.

참고: Konnect에서 KIC를 사용해 data plane 노드를 관리하고 있다면, data plane에 cluster_telemetry_endpoint를 설정했는지 확인하세요. data plane 노드를 설정할 때 여러분의 cluster_telemetry_endpoint 값을 확인할 수 있어요.

Consumer 설정하기

decK

다음은 example-consumer라는 새로운 Consumer를 생성하는 구성이에요:

_format_version: "3.0"
consumers:
  - custom_id: example-consumer-id
    username: example-consumer
    tags:
    - silver-tier

{: data-file="kong.yaml" data-tool="deck" }

Admin API

Consumer를 생성하려면 Admin API의 /consumers 엔드포인트를 호출하세요.

curl -i -X POST http://localhost:8001/consumers/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "custom_id": "example-consumer-id",
      "username": "example-consumer",
      "tags": [
        "silver-tier"
      ]
    }
    '

Konnect API

Consumer를 생성하려면 Konnect control plane config API의 /consumers 엔드포인트를 호출하세요.

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumers/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "custom_id": "example-consumer-id",
      "username": "example-consumer",
      "tags": [
        "silver-tier"
      ]
    }
    '

다음 플레이스홀더는 반드시 여러분의 값으로 바꾸세요:

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요.

  • KONNECT_TOKEN: Konnect 계정에 연결된 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: control plane의 id예요.

리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API reference를 참고하세요.

KIC

echo "
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
  name: example-consumer
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
    konghq.com/tags: silver-tier
custom_id: example-consumer-id
username: example-consumer
" | kubectl apply -f -

Terraform

필수 조건: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_consumer" "my_consumer" {
  custom_id = "example-consumer-id"
  username = "example-consumer"
  tags = ["silver-tier"]

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

UI

다음은 example-consumer라는 새로운 Consumer를 생성하는 방법이에요:

  1. Gateway 인스턴스로 이동하세요:
  • Konnect 사이드바에서 API Gateway > Gateways를 클릭한 다음, control plane을 선택하세요.
  • Kong Manager에서는 Workspace를 선택하세요.
  1. Consumers로 이동하세요:
  • Konnect에서는 control plane 안에 있는 Consumers 탭을 클릭하세요.
  • Kong Manager에서는 사이드바에서 Consumers를 열어 주세요.
  1. New consumer를 클릭하세요.
  2. Username에 example-consumer를, Custom ID에 example-consumer-id를 입력하세요.
  3. Save를 클릭하세요.

스키마

{
  "additionalProperties": false,
  "description": "The Consumer object represents a consumer - or a user - of a Service. You can either rely on Kong as the primary datastore, or you can map the consumer list with your database to keep consistency between Kong and your existing primary datastore.",
  "example": {
    "custom_id": "4200",
    "id": "8a388226-80e8-4027-a486-25e4f7db5d21",
    "tags": [
      "silver-tier"
    ],
    "username": "bob-the-builder"
  },
  "properties": {
    "created_at": {
      "description": "Unix epoch when the resource was created.",
      "nullable": true,
      "type": "integer"
    },
    "custom_id": {
      "description": "Field for storing an existing unique ID for the Consumer - useful for mapping Kong with users in your existing database. You must send either this field or `username` with the request.",
      "nullable": true,
      "type": "string"
    },
    "id": {
      "description": "A string representing a UUID (universally unique identifier).",
      "nullable": true,
      "type": "string"
    },
    "tags": {
      "description": "An optional set of strings associated with the Consumer for grouping and filtering.",
      "items": {
        "description": "A string representing a tag.",
        "type": "string"
      },
      "nullable": true,
      "type": "array"
    },
    "updated_at": {
      "description": "Unix epoch when the resource was last updated.",
      "nullable": true,
      "type": "integer"
    },
    "username": {
      "description": "The unique username of the Consumer. You must send either this field or `custom_id` with the request.",
      "nullable": true,
      "type": "string"
    }
  },
  "type": "object"
}

자주 묻는 질문(FAQ)

  • 자격 증명이란 무엇이고, 왜 필요한가요? 다양한 인증 메커니즘을 통해 Consumer를 인증하려면 자격 증명이 필요해요. 자격 증명 유형은 사용하려는 인증 플러그인에 따라 달라져요.

    예를 들어 Key Authentication 플러그인은 API 키가 필요하고, Basic Authentication 플러그인은 사용자 이름과 비밀번호 쌍이 필요해요.

  • Consumer와 Application은 어떻게 다른가요? Application은 개발자가 Kong 관리 팀의 개입 없이 필요한 자격 증명을 생성해서 Kong Gateway나 Konnect가 관리하는 API에 접근할 수 있게 해줘요. Application은 Developer Portal을 사용해 관리돼요.

    Consumer의 경우에는 Kong 팀이 Consumer를 생성하고, 자격 증명을 만들고, API에 접근해야 하는 개발자에게 전달해요.

  • Consumer와 Developer는 어떻게 다른가요? Developer는 Developer Portal에 등록한 사람이에요. Developer는 애플리케이션을 만들고 자격 증명을 직접 관리할 수 있어요.

    Consumer는 Kong Gateway 구성의 일부이며, 여러분의 관리자가 관리해요.

  • Consumer와 RBAC User는 어떻게 다른가요? RBAC User는 Kong Manager의 사용자이고, Consumer는 Gateway 자체가 프록시하는 서비스의 사용자예요.

  • 어떤 플러그인을 Consumer에 범위 지정할 수 있나요? 인증 플러그인과 라우팅을 제어하는 플러그인을 제외하면, 대부분의 플러그인은 Consumer에 범위 지정할 수 있어요.

    전체 목록은 plugin scopes compatibility reference에서 확인할 수 있어요.

  • 인증 플러그인을 Consumer에 범위 지정할 수 있나요? 아니요. 인증 플러그인은 Route, Service 또는 전역 중 하나에 범위 지정해야 해요.

  • decK으로 Consumer를 관리할 수 있나요? 네, decK으로 Consumer를 관리할 수 있어요. 다만 Consumer 수가 많으면 동기화 시간이 오래 걸리니 주의하세요.

    decK으로 많은 수의 Consumer를 관리하려면, Consumer를 Consumer Group에 넣고 구성의 나머지 부분과 분리해서 관리하는 페더레이션 구성 관리 방식을 추천해요.

관련 리소스

더 알아보기 (Learn more)