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

OpenID Connect: Consumer 인가

원문 보기 위키 갱신

OpenID Connect: Consumer 인가 (Consumer authorization)

OpenID Connect 플러그인으로 Consumer를 IdP 사용자에 매핑하는 방법을 알려드려요. password 인증을 예시로 하지만 다른 인증 방식도 지원해요. 전제 조건과 환경 변수 설정부터 플러그인 구성까지 단계별로 설명해요.

출처: 문서

본문

소비자 인증 v1.0+

OpenID Connect 플러그인으로 소비자 매핑을 구성해요.

이 예시는 비밀번호 인증을 사용하지만, 소비자와 함께 지원되는 모든 인증 유형을 사용할 수 있어요.

Kong Gateway 3.14보다 오래된 버전을 사용 중이라면 consumer_claims 대신 consumer_claim을 사용하세요.

소비자를 IdP 사용자에 매핑하도록 OpenID Connect 플러그인을 설정하는 전체 예시는 OpenID Connect를 소비자 인증과 함께 구성하기를 참조하세요.

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

전제 조건

  • 구성된 ID 공급자(IdP)

  • config.consumer_claim에 정의된 값과 일치하는 사용자 이름을 가진 소비자가 최소 하나 있어야 해요.

환경 변수

  • ISSUER: IdP의 발급자 인증 URL이에요. 예를 들어 Keycloak을 IdP로 사용하는 경우 발급자 URL은 다음과 같아요: http://localhost:8080/realms/example-realm

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

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

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

플러그인 설정

Global

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:
      - password
      consumer_claims:
      - - preferred_username
      consumer_by:
      - username
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

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

Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "client_auth": [
          "client_secret_post"
        ],
        "auth_methods": [
          "password"
        ],
        "consumer_claims": [
          [
            "preferred_username"
          ]
        ],
        "consumer_by": [
          "username"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '
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": [
          "password"
        ],
        "consumer_claims": [
          [
            "preferred_username"
          ]
        ],
        "consumer_by": [
          "username"
        ],
        "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:
  - password
  consumer_claims:
  - - preferred_username
  consumer_by:
  - username
  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 = ["password"]
    consumer_claims = [["preferred_username"]]
    consumer_by = ["username"]
    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 "token_salt" {
  type = string
}

Service

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:
      - password
      consumer_claims:
      - - preferred_username
      consumer_by:
      - username
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

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

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

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

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "client_auth": [
          "client_secret_post"
        ],
        "auth_methods": [
          "password"
        ],
        "consumer_claims": [
          [
            "preferred_username"
          ]
        ],
        "consumer_by": [
          "username"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

  • 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": [
          "password"
        ],
        "consumer_claims": [
          [
            "preferred_username"
          ]
        ],
        "consumer_by": [
          "username"
        ],
        "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:
  - password
  consumer_claims:
  - - preferred_username
  consumer_by:
  - username
  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 = ["password"]
    consumer_claims = [["preferred_username"]]
    consumer_by = ["username"]
    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 "token_salt" {
  type = string
}

Route

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:
      - password
      consumer_claims:
      - - preferred_username
      consumer_by:
      - username
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

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

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

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

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "client_auth": [
          "client_secret_post"
        ],
        "auth_methods": [
          "password"
        ],
        "consumer_claims": [
          [
            "preferred_username"
          ]
        ],
        "consumer_by": [
          "username"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

다음 자리표시자를 자신의 값으로 교체하세요:

  • 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": [
          "password"
        ],
        "consumer_claims": [
          [
            "preferred_username"
          ]
        ],
        "consumer_by": [
          "username"
        ],
        "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:
  - password
  consumer_claims:
  - - preferred_username
  consumer_by:
  - username
  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 = ["password"]
    consumer_claims = [["preferred_username"]]
    consumer_by = ["username"]
    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 "token_salt" {
  type = string
}

더 알아보기 (Learn more)