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

Key Auth: Konnect에서 외부 Consumer를 위한 Realms

원문 보기 위키 갱신

이 문서에서는 Key Auth 플러그인의 identity_realms 필드를 설정하여 Konnect에서 중앙 관리되는 Consumer를 인증하는 방법을 알려드려요. Data Plane은 동일한 리전의 realm에만 접근할 수 있으며, realm의 우선순위를 지정할 수 있어요. decK, Konnect API, KIC를 통해 플러그인을 설정하는 방법을 단계별로 설명해요.

출처: 문서

본문

Konnectv3.10+에서 외부 Consumer를 위한 Realm

Key Auth 플러그인의 identity_realms 필드를 구성하여 Konnect에서 중앙 관리되는 consumer를 인증할 수 있어요. 데이터 플레인은 배포된 동일한 리전의 realm에만 연결할 수 있어요.

identity_realms는 기본적으로 컨트롤 플레인으로 범위가 지정돼요(scope: cp). identity_realms를 구성하는 순서에 따라 데이터 플레인이 제공된 API 키를 인증하려고 시도하는 우선순위가 결정돼요. 자세한 내용은 realm 우선순위 참조를 확인하세요.

이 예제의 전체 튜토리얼은 Konnect에서 중앙 관리 Consumer 생성을 참조하세요.

사전 요구 사항

  • Konnect에서 연결된 컨트롤 플레인이 있는 realm을 구성했어요. /realms 엔드포인트로 이 작업을 할 수 있어요.

  • 데이터 플레인이 Konnect에 네트워크 연결되어 identity 엔드포인트 https://{region}.identity.konghq.com에 도달할 수 있어요. 데이터 플레인은 배포된 동일한 리전의 realm에만 연결할 수 있어요.

환경 변수

  • REGION: Konnect 인스턴스의 리전이에요.

  • REALM_ID: 사전 요구 사항에서 생성한 realm의 ID예요.

플러그인 설정

글로벌

decK

이 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: key-auth
    config:
      key_names:
      - apikey
      identity_realms:
      - scope: realm
        region: ${{ env "DECK_REGION" }}
        id: ${{ env "DECK_REALM_ID" }}
      - scope: cp

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

Konnect API

다음 요청을 보내세요:

curl -X POST https://.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "key-auth",
      "config": {
        "key_names": [
          "apikey"
        ],
        "identity_realms": [
          {
            "scope": "realm",
            "region": "'$REGION'",
            "id": "'$REALM_ID'"
          },
          {
            "scope": "cp"
          }
        ]
      }
    }
    '

다음 플레이스홀더를 자신의 값으로 바꾸는 것을 잊지 마세요:

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

  • controlPlaneId: 컨트롤 플레인의 id예요.

리전별 URL과 개인 액세스 토큰에 대한 자세한 내용은 Konnect 컨트롤 플레인 구성 API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
  labels:
    global: 'true'
config:
  key_names:
  - apikey
  identity_realms:
  - scope: realm
    region: '$REGION'
    id: '$REALM_ID'
  - scope: cp
plugin: key-auth
" | 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/"
}

Konnect 게이트웨이 플러그인을 생성하려면 다음을 Terraform 구성에 추가하세요:

resource "konnect_gateway_plugin_key_auth" "my_key_auth" {
  enabled = true

  config = {
    key_names = ["apikey"]
    identity_realms = [
      {
        scope = "realm"
        region = var.region
        id = var.realm_id
      }, 

      {
        scope = "cp"
      }    ]
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

이 예제에서는 다음 변수를 매니페스트에 추가해야 해요. TF_VAR_name=value를 설정하여 런타임에 값을 지정할 수 있어요.

variable "region" {
  type = string
}
variable "realm_id" {
  type = string
}

서비스

decK

이 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: key-auth
    service: serviceName|Id
    config:
      key_names:
      - apikey
      identity_realms:
      - scope: realm
        region: ${{ env "DECK_REGION" }}
        id: ${{ env "DECK_REALM_ID" }}
      - scope: cp

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

다음 플레이스홀더를 자신의 값으로 바꾸는 것을 잊지 마세요:

  • serviceName|Id: 플러그인 구성이 대상으로 하는 서비스의 id 또는 name이에요.
Konnect API

다음 요청을 보내세요:

curl -X POST https://.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "key-auth",
      "config": {
        "key_names": [
          "apikey"
        ],
        "identity_realms": [
          {
            "scope": "realm",
            "region": "'$REGION'",
            "id": "'$REALM_ID'"
          },
          {
            "scope": "cp"
          }
        ]
      }
    }
    '

다음 플레이스홀더를 자신의 값으로 바꾸는 것을 잊지 마세요:

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

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • serviceId: 플러그인 구성이 대상으로 하는 서비스의 id예요.

리전별 URL과 개인 액세스 토큰에 대한 자세한 내용은 Konnect 컨트롤 플레인 구성 API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  key_names:
  - apikey
  identity_realms:
  - scope: realm
    region: '$REGION'
    id: '$REALM_ID'
  - scope: cp
plugin: key-auth
" | kubectl apply -f -

다음으로, service 리소스에 주석을 추가하여 KongPlugin 리소스를 적용하세요:

kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=
Terraform
사전 요구 사항: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

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

Konnect 게이트웨이 플러그인을 생성하려면 다음을 Terraform 구성에 추가하세요:

resource "konnect_gateway_plugin_key_auth" "my_key_auth" {
  enabled = true

  config = {
    key_names = ["apikey"]
    identity_realms = [
      {
        scope = "realm"
        region = var.region
        id = var.realm_id
      }, 

      {
        scope = "cp"
      }    ]
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  service = {
    id = konnect_gateway_service.my_service.id
  }
}

이 예제에서는 다음 변수를 매니페스트에 추가해야 해요. TF_VAR_name=value를 설정하여 런타임에 값을 지정할 수 있어요.

variable "region" {
  type = string
}
variable "realm_id" {
  type = string
}

라우트

decK

이 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: key-auth
    route: routeName|Id
    config:
      key_names:
      - apikey
      identity_realms:
      - scope: realm
        region: ${{ env "DECK_REGION" }}
        id: ${{ env "DECK_REALM_ID" }}
      - scope: cp

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

다음 플레이스홀더를 자신의 값으로 바꾸는 것을 잊지 마세요:

  • routeName|Id: 플러그인 구성이 대상으로 하는 라우트의 id 또는 name이에요.
Konnect API

다음 요청을 보내세요:

curl -X POST https://.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "key-auth",
      "config": {
        "key_names": [
          "apikey"
        ],
        "identity_realms": [
          {
            "scope": "realm",
            "region": "'$REGION'",
            "id": "'$REALM_ID'"
          },
          {
            "scope": "cp"
          }
        ]
      }
    }
    '

다음 플레이스홀더를 자신의 값으로 바꾸는 것을 잊지 마세요:

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

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • routeId: 플러그인 구성이 대상으로 하는 라우트의 id예요.

리전별 URL과 개인 액세스 토큰에 대한 자세한 내용은 Konnect 컨트롤 플레인 구성 API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  key_names:
  - apikey
  identity_realms:
  - scope: realm
    region: '$REGION'
    id: '$REALM_ID'
  - scope: cp
plugin: key-auth
" | kubectl apply -f -

다음으로, httproute 또는 ingress 리소스에 주석을 추가하여 KongPlugin 리소스를 적용하세요:

Gateway API
kubectl annotate -n kong httproute  konghq.com/plugins=
Ingress
kubectl annotate -n kong ingress  konghq.com/plugins=
Terraform
사전 요구 사항: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

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

Konnect 게이트웨이 플러그인을 생성하려면 다음을 Terraform 구성에 추가하세요:

resource "konnect_gateway_plugin_key_auth" "my_key_auth" {
  enabled = true

  config = {
    key_names = ["apikey"]
    identity_realms = [
      {
        scope = "realm"
        region = var.region
        id = var.realm_id
      }, 

      {
        scope = "cp"
      }    ]
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  route = {
    id = konnect_gateway_route.my_route.id
  }
}

이 예제에서는 다음 변수를 매니페스트에 추가해야 해요. TF_VAR_name=value를 설정하여 런타임에 값을 지정할 수 있어요.

variable "region" {
  type = string
}
variable "realm_id" {
  type = string
}

관련 리소스

더 알아보기 (Learn more)