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

OpenID Connect: Kong Identity와 함께 헤더에 클라이언트 자격 증명 부여

원문 보기 위키 갱신

OpenID Connect: Kong Identity와 함께 헤더에 클라이언트 자격 증명 부여 (Client credentials grant in header with Kong Identity)

이 문서에서는 Kong Identity를 ID 제공자로 사용하여 OpenID Connect 플러그인을 클라이언트 자격 증명 부여 방식으로 설정하는 방법을 설명해요. 클라이언트 자격 증명을 헤더에 담아 보내는 방식을 중점적으로 다루며, 필요에 따라 본문이나 쿼리 파라미터로도 보낼 수 있어요. 또한 사전 준비 사항, 환경 변수 설정, 플러그인 구성 방법을 단계별로 안내해요.

출처: 문서

본문

헤더에서 Kong Identityv1.0+를 사용한 클라이언트 자격 증명 승인

OpenID Connect 플러그인을 클라이언트 자격 증명 승인과 함께 구성하세요.

클라이언트 자격 증명 승인이 작동하는 방식은 다음과 같아요.

 
sequenceDiagram
    autonumber
    participant client as 클라이언트 
(예: 모바일 앱) participant kong as 게이트웨이 participant idp as IdP
(예: Keycloak) participant httpbin as 업스트림
(업스트림 서비스,
예: httpbin) activate client activate kong client->>kong: 기본 인증을 사용한
서비스 deactivate client kong->>kong: 기본 인증 자격 증명
로드 activate idp kong->>idp: IdP/token
클라이언트 자격 증명 사용 deactivate kong idp->>idp: 클라이언트 인증 activate kong idp->>kong: 토큰 반환 deactivate idp kong->>kong: 토큰 검증 activate httpbin kong->>httpbin: 액세스 토큰으로 요청 httpbin->>kong: 응답 deactivate httpbin activate client kong->>client: 응답 deactivate kong deactivate client

이 예제에서는 플러그인이 헤더로 전송된 클라이언트 자격 증명만 허용하지만, client_credentials_param_type 파라미터를 body, query 또는 이 값들의 조합으로 설정할 수도 있어요.

이 예제는 Konnect에 호스팅된 Kong Identity 인증 서버를 사용해요. Keycloak 같은 외부 인증 서버를 사용하려면 클라이언트 자격 증명 승인으로 OpenID Connect 구성을 참조하세요.

참고: config.client_auth를 client_secret_post로 설정하면 IdP에 대한 연결을 테스트할 수 있지만, 프로덕션에서는 더 안전한 인증 방법을 사용하는 것을 권장해요. 지원되는 클라이언트 인증 방법 중에서 사용할 수 있어요.

사전 요구 사항

환경 변수

  • ISSUER: IdP의 발급자 인증 URL이에요. 이 예제는 Kong Identity를 IdP로 사용하므로, 발급자 URL은 https://xxx.<region>.identity.konghq.tech/auth와 같은 형태예요.

  • CLIENT_ID: 플러그인이 IdP의 인증된 엔드포인트를 호출할 때 사용하는 클라이언트 ID예요.

  • CLIENT_SECRET: IdP에 연결하는 데 필요한 클라이언트 시크릿이에요.

  • DIRECTORY_NAME: 주체 조회에 사용되는 Kong Identity 디렉터리 이름이에요.

  • TOKEN_SALT: decK(v1.59 이상)에서 필요로 하는 임의의 문자열로, 세션 자격 증명이 동기화될 때마다 재생성되지 않도록 해요. 이 파라미터는 다른 형식에서는 선택 사항이에요. 예를 들어 openssl rand -base64 16으로 생성할 수 있어요.

플러그인 설정

전역

decK

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

_format_version: "3.0"
plugins:
  - name: openid-connect
    config:
      issuer: ${{ env "DECK_ISSUER" }}
      client_id:
      - ${{ env "DECK_CLIENT_ID" }}
      client_secret:
      - ${{ env "DECK_CLIENT_SECRET" }}
      client_auth:
      - client_secret_post
      auth_methods:
      - client_credentials
      client_credentials_param_type:
      - header
      principals:
        enabled: true
        directory: ${{ env "DECK_DIRECTORY_NAME" }}
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

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

Konnect API

다음 요청을 보내세요:

curl -X POST https://{region}.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": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "client_auth": [
          "client_secret_post"
        ],
        "auth_methods": [
          "client_credentials"
        ],
        "client_credentials_param_type": [
          "header"
        ],
        "principals": {
          "enabled": true,
          "directory": "'$DIRECTORY_NAME'"
        },
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요.
  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요.
  • controlPlaneId: 컨트롤 플레인의 id예요.

지역별 URL과 개인 액세스 토큰에 대한 자세한 내용은 Konnect Control Planes Config API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
  labels:
    global: 'true'
config:
  issuer: '$ISSUER'
  client_id:
  - '$CLIENT_ID'
  client_secret:
  - '$CLIENT_SECRET'
  client_auth:
  - client_secret_post
  auth_methods:
  - client_credentials
  client_credentials_param_type:
  - header
  principals:
    enabled: true
    directory: '$DIRECTORY_NAME'
  cache_tokens_salt: '$TOKEN_SALT'
plugin: openid-connect
" | 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 Gateway Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_openid_connect" "my_openid_connect" {
  enabled = true

  config = {
    issuer = var.issuer
    client_id = [var.client_id]
    client_secret = [var.client_secret]
    client_auth = ["client_secret_post"]
    auth_methods = ["client_credentials"]
    client_credentials_param_type = ["header"]

    principals = {
      enabled = true
      directory = var.directory_name
    }
    cache_tokens_salt = var.token_salt
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

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

variable "issuer" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "directory_name" {
  type = string
}
variable "token_salt" {
  type = string
}

서비스

decK

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

_format_version: "3.0"
plugins:
  - name: openid-connect
    service: serviceName|Id
    config:
      issuer: ${{ env "DECK_ISSUER" }}
      client_id:
      - ${{ env "DECK_CLIENT_ID" }}
      client_secret:
      - ${{ env "DECK_CLIENT_SECRET" }}
      client_auth:
      - client_secret_post
      auth_methods:
      - client_credentials
      client_credentials_param_type:
      - header
      principals:
        enabled: true
        directory: ${{ env "DECK_DIRECTORY_NAME" }}
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

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

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

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

다음 요청을 보내세요:

curl -X POST https://{region}.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": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "client_auth": [
          "client_secret_post"
        ],
        "auth_methods": [
          "client_credentials"
        ],
        "client_credentials_param_type": [
          "header"
        ],
        "principals": {
          "enabled": true,
          "directory": "'$DIRECTORY_NAME'"
        },
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요.
  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요.
  • controlPlaneId: 컨트롤 플레인의 id예요.
  • serviceId: 플러그인 구성이 대상으로 하는 서비스의 id예요.

지역별 URL과 개인 액세스 토큰에 대한 자세한 내용은 Konnect Control Planes Config API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  issuer: '$ISSUER'
  client_id:
  - '$CLIENT_ID'
  client_secret:
  - '$CLIENT_SECRET'
  client_auth:
  - client_secret_post
  auth_methods:
  - client_credentials
  client_credentials_param_type:
  - header
  principals:
    enabled: true
    directory: '$DIRECTORY_NAME'
  cache_tokens_salt: '$TOKEN_SALT'
plugin: openid-connect
" | 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 Gateway Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_openid_connect" "my_openid_connect" {
  enabled = true

  config = {
    issuer = var.issuer
    client_id = [var.client_id]
    client_secret = [var.client_secret]
    client_auth = ["client_secret_post"]
    auth_methods = ["client_credentials"]
    client_credentials_param_type = ["header"]

    principals = {
      enabled = true
      directory = var.directory_name
    }
    cache_tokens_salt = var.token_salt
  }

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

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

variable "issuer" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "directory_name" {
  type = string
}
variable "token_salt" {
  type = string
}

라우트

decK

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

_format_version: "3.0"
plugins:
  - name: openid-connect
    route: routeName|Id
    config:
      issuer: ${{ env "DECK_ISSUER" }}
      client_id:
      - ${{ env "DECK_CLIENT_ID" }}
      client_secret:
      - ${{ env "DECK_CLIENT_SECRET" }}
      client_auth:
      - client_secret_post
      auth_methods:
      - client_credentials
      client_credentials_param_type:
      - header
      principals:
        enabled: true
        directory: ${{ env "DECK_DIRECTORY_NAME" }}
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

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

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

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

다음 요청을 보내세요:

curl -X POST https://{region}.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": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "client_auth": [
          "client_secret_post"
        ],
        "auth_methods": [
          "client_credentials"
        ],
        "client_credentials_param_type": [
          "header"
        ],
        "principals": {
          "enabled": true,
          "directory": "'$DIRECTORY_NAME'"
        },
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 꼭 바꾸세요:

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요.
  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요.
  • controlPlaneId: 컨트롤 플레인의 id예요.
  • routeId: 플러그인 구성이 대상으로 하는 라우트의 id예요.

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

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  issuer: '$ISSUER'
  client_id:
  - '$CLIENT_ID'
  client_secret:
  - '$CLIENT_SECRET'
  client_auth:
  - client_secret_post
  auth_methods:
  - client_credentials
  client_credentials_param_type:
  - header
  principals:
    enabled: true
    directory: '$DIRECTORY_NAME'
  cache_tokens_salt: '$TOKEN_SALT'
plugin: openid-connect
" | 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 Gateway Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_openid_connect" "my_openid_connect" {
  enabled = true

  config = {
    issuer = var.issuer
    client_id = [var.client_id]
    client_secret = [var.client_secret]
    client_auth = ["client_secret_post"]
    auth_methods = ["client_credentials"]
    client_credentials_param_type = ["header"]

    principals = {
      enabled = true
      directory = var.directory_name
    }
    cache_tokens_salt = var.token_salt
  }

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

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

variable "issuer" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "directory_name" {
  type = string
}
variable "token_salt" {
  type = string
}

관련 리소스

더 알아보기 (Learn more)