Curity와 함께 사용하는 OpenID Connect
Curity와 함께 사용하는 OpenID Connect (OpenID Connect with Curity)
이 문서는 Kong Gateway와 Curity Identity Server를 Phantom Token 패턴으로 연동해 토큰 introspection을 구성하는 방법을 설명해요. OpenID Connect 플러그인이 들어오는 불투명(opaque) 액세스 토큰을 introspection하면, Curity Identity Server가 응답으로 JWT를 돌려주죠. 플러그인은 이 과정에서 필요한 스코프가 있는지 검증하고, 스코프가 맞지 않으면 업스트림 접근을 거부해요. 접근이 허용되면 JWT가 헤더에 담겨 업스트림으로 전달되고, decK나 Admin API를 이용한 플러그인 설정 방법도 함께 소개해요
출처: 문서
본문
Curity와 함께 OpenID Connect 사용v3.14+
Phantom Token 패턴을 사용해 인트로스펙션을 수행하도록 Kong Gateway와 Curity Identity Server를 통합해요.
OpenID Connect 플러그인은 들어오는 불투명(opaque) 액세스 토큰을 인트로스펙션하고, Curity Identity Server의 인트로스펙션 응답에서 JWT를 받아요. 인트로스펙션의 일부로서, OpenID Connect 플러그인은 인트로스펙션된 토큰에 필요한 스코프가 존재하는지 검증해요.
- 이 예제는
config.upstream_headers를 사용해 경로 배열(path array)로 클레임을 매핑해요. 이렇게 하면 토큰 페이로드의 어떤 깊이에 있는 클레임이든 접근할 수 있어요. - 올바른 스코프가 없으면, 요청된 업스트림 서비스에 대한 접근이 거부돼요.
- 접근이 허용되면, 인트로스펙션 응답의 JWT가 헤더에 추가되어 업스트림 서비스로 전달되고, 거기서 사용될 수 있어요.
전제 조건
-
Phantom Token 방식으로 구성된 인트로스펙션 엔드포인트.
환경 변수
-
ISSUER: IdP의 발급자(issuer) 인증 URL이에요. Curity의 경우 일반적으로 다음과 같아요:https://idsvr.example.com/oauth/v2/oauth-anonymous. -
CLIENT_ID: 플러그인이 IdP의 인증된 엔드포인트를 호출할 때 사용하는 클라이언트 ID예요. -
CLIENT_SECRET: Curity에 연결하는 데 필요한 클라이언트 시크릿이에요. -
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" }}
scopes_required:
- openid
hide_credentials: true
upstream_access_token_header: nil
upstream_headers:
- header: x-phantom-token
path:
- phantom_token
auth_methods:
- introspection
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'"
],
"scopes_required": [
"openid"
],
"hide_credentials": true,
"upstream_access_token_header": "nil",
"upstream_headers": [
{
"header": "x-phantom-token",
"path": [
"phantom_token"
]
}
],
"auth_methods": [
"introspection"
],
"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'"
],
"scopes_required": [
"openid"
],
"hide_credentials": true,
"upstream_access_token_header": "nil",
"upstream_headers": [
{
"header": "x-phantom-token",
"path": [
"phantom_token"
]
}
],
"auth_methods": [
"introspection"
],
"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'
scopes_required:
- openid
hide_credentials: true
upstream_access_token_header: nil
upstream_headers:
- header: x-phantom-token
path:
- phantom_token
auth_methods:
- introspection
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 플러그인을 생성하려면 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]
scopes_required = ["openid"]
hide_credentials = true
upstream_access_token_header = "nil"
upstream_headers = [
{
header = "x-phantom-token"
path = ["phantom_token"]
} ]
auth_methods = ["introspection"]
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
}
서비스
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" }}
scopes_required:
- openid
hide_credentials: true
upstream_access_token_header: nil
upstream_headers:
- header: x-phantom-token
path:
- phantom_token
auth_methods:
- introspection
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'"
],
"scopes_required": [
"openid"
],
"hide_credentials": true,
"upstream_access_token_header": "nil",
"upstream_headers": [
{
"header": "x-phantom-token",
"path": [
"phantom_token"
]
}
],
"auth_methods": [
"introspection"
],
"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'"
],
"scopes_required": [
"openid"
],
"hide_credentials": true,
"upstream_access_token_header": "nil",
"upstream_headers": [
{
"header": "x-phantom-token",
"path": [
"phantom_token"
]
}
],
"auth_methods": [
"introspection"
],
"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'
scopes_required:
- openid
hide_credentials: true
upstream_access_token_header: nil
upstream_headers:
- header: x-phantom-token
path:
- phantom_token
auth_methods:
- introspection
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 플러그인을 생성하려면 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]
scopes_required = ["openid"]
hide_credentials = true
upstream_access_token_header = "nil"
upstream_headers = [
{
header = "x-phantom-token"
path = ["phantom_token"]
} ]
auth_methods = ["introspection"]
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
}
라우트
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" }}
scopes_required:
- openid
hide_credentials: true
upstream_access_token_header: nil
upstream_headers:
- header: x-phantom-token
path:
- phantom_token
auth_methods:
- introspection
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'"
],
"scopes_required": [
"openid"
],
"hide_credentials": true,
"upstream_access_token_header": "nil",
"upstream_headers": [
{
"header": "x-phantom-token",
"path": [
"phantom_token"
]
}
],
"auth_methods": [
"introspection"
],
"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'"
],
"scopes_required": [
"openid"
],
"hide_credentials": true,
"upstream_access_token_header": "nil",
"upstream_headers": [
{
"header": "x-phantom-token",
"path": [
"phantom_token"
]
}
],
"auth_methods": [
"introspection"
],
"cache_tokens_salt": "'$TOKEN_SALT'"
}
}
'
다음 플레이스홀더는 여러분의 값으로 꼭 바꿔야 해요:
-
region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
routeId: 플러그인 구성이 대상으로 삼을 라우트의id예요.
리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API reference 문서를 참고하세요.
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'
scopes_required:
- openid
hide_credentials: true
upstream_access_token_header: nil
upstream_headers:
- header: x-phantom-token
path:
- phantom_token
auth_methods:
- introspection
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 플러그인을 생성하려면 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]
scopes_required = ["openid"]
hide_credentials = true
upstream_access_token_header = "nil"
upstream_headers = [
{
header = "x-phantom-token"
path = ["phantom_token"]
} ]
auth_methods = ["introspection"]
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)
- Kong Gateway에서 OpenID Connect 플러그인의 개념과 동작 방식을 먼저 살펴보면 좋아요 — OpenID Connect in Kong Gateway
- Kong Gateway가 지원하는 인증 방식 전반을 이해하는 데 도움이 돼요 — Authentication in Kong Gateway
- 예제에서 사용한
config.upstream_headers설정의 스키마와 상세 옵션을 확인할 수 있어요 —config.upstream_headers - decK로
kong.yaml설정 파일을 작성하는 기본 방법을 배울 수 있어요 —kong.yaml - OpenID Connect 관련 다른 튜토리얼도 이어서 살펴볼 수 있어요 — OpenID Connect tutorials