OpenID Connect 액터 토큰을 사용한 토큰 교환
OpenID Connect 액터 토큰을 사용한 토큰 교환 (Token exchange with an actor token)
OpenID Connect 플러그인을 사용하면 토큰 교환 요청에 액터 토큰(actor token)을 포함할 수 있어요. 액터 토큰은 사용자를 대신해 작업을 수행하는 주체의 신원을 나타내는 토큰이에요. 백엔드 서비스나 AI 에이전트가 사용자를 대신해 동작하는 위임 시나리오에서 유용하고, Okta처럼 특정 토큰 교환 그랜트에서 액터 토큰을 요구하는 IdP에도 필요해요. 이 문서에서는 Kong Gateway가 요청 헤더에서 액터 토큰을 읽어 토큰 교환 요청에 함께 담아 보내는 예제를 단계별로 살펴봐요
출처: 문서
본문
액터 토큰을 사용한 토큰 교환v3.16+
서브젝트를 대신해 행동하는 당사자의 신원을 나타내는 액터 토큰을 토큰 교환 요청에 포함시키려면 OpenID Connect 플러그인을 사용하세요. 이 기능은 사용자를 대신해 동작하는 백엔드 서비스나 AI 에이전트 같은 위임 시나리오에서 유용하고, 특정 토큰 교환 그랜트에서 액터 토큰을 기대하는 아이덴티티 프로바이더(예: Okta)에게는 필수적이에요.
이 예제에서는 Kong Gateway가 요청 헤더에서 액터 토큰을 읽어서, 서브젝트 토큰과 함께 토큰 교환 요청에 포함시켜요.
OIDC 플러그인에서 토큰 교환이 동작하는 방식은 다음과 같아요:
sequenceDiagram
participant C as 클라이언트
(예: 모바일 앱)
participant K as 게이트웨이
participant A as 인가 서버
(예: Keycloak)
participant U as 업스트림
(백엔드 서비스,
예: httpbin)
C->>K: 서브젝트 토큰을 포함한 요청
activate K
note over K: 서브젝트 토큰 검증
(iss, exp, nbf)
K->>A: 토큰 교환 요청
activate A
A-->>K: 교환된 액세스 토큰
deactivate A
K->>K: 교환된 토큰 검증
K->>U: 교환된 토큰을 담은 프록시 요청
activate U
U-->>K: 응답
deactivate U
K-->>C: 응답
deactivate K
토큰 교환 지원에 대해 더 자세히 알아보려면 토큰 교환 레퍼런스 문서를 확인하세요.
사전 요구 사항
- 토큰 교환을 지원하고, 교환 과정에서 액터 토큰을 받아들이는 아이덴티티 프로바이더.
환경 변수
-
ISSUER: 들어오는 요청의 토큰을 발급한 인가 서버의 issuer 인증 URL이에요. 예를 들어 Keycloak을 IdP로 사용한다면 issuer URL은 다음과 같아요:http://localhost:8080/realms/example-realm. -
CLIENT_ID: 플러그인이 IdP의 인증된 엔드포인트를 호출할 때 사용하는 클라이언트 ID예요. -
CLIENT_SECRET: IdP에 연결할 때 필요한 클라이언트 시크릿이에요. -
ACTOR_TOKEN_HEADER: 액터 토큰을 담고 있는 요청 헤더의 이름이에요. 예를 들면X-Actor-Token이 있어요. Kong Gateway가 이 헤더를 교환 요청에 포함시키게 하려면, 클라이언트나 업스트림 서비스가 들어오는 요청에 이 헤더를 설정해야 해요. -
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:
- bearer
token_exchange:
subject_token_issuers:
- issuer: ${{ env "DECK_ISSUER" }}
conditions:
missing_audience:
has_audience:
missing_scopes:
- profile
has_scopes:
request:
empty_audience: false
scopes:
empty_scopes: false
audience:
actor_token:
source: header
header_name: ${{ env "DECK_ACTOR_TOKEN_HEADER" }}
type: urn:ietf:params:oauth:token-type:access_token
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": [
"bearer"
],
"token_exchange": {
"subject_token_issuers": [
{
"issuer": "'$ISSUER'",
"conditions": {
"missing_audience": null,
"has_audience": null,
"missing_scopes": [
"profile"
],
"has_scopes": null
}
}
],
"request": {
"empty_audience": false,
"scopes": null,
"empty_scopes": false,
"audience": null,
"actor_token": {
"source": "header",
"header_name": "'$ACTOR_TOKEN_HEADER'",
"type": "urn:ietf:params:oauth:token-type:access_token"
}
}
},
"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": [
"bearer"
],
"token_exchange": {
"subject_token_issuers": [
{
"issuer": "'$ISSUER'",
"conditions": {
"missing_audience": null,
"has_audience": null,
"missing_scopes": [
"profile"
],
"has_scopes": null
}
}
],
"request": {
"empty_audience": false,
"scopes": null,
"empty_scopes": false,
"audience": null,
"actor_token": {
"source": "header",
"header_name": "'$ACTOR_TOKEN_HEADER'",
"type": "urn:ietf:params:oauth:token-type:access_token"
}
}
},
"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:
- bearer
token_exchange:
subject_token_issuers:
- issuer: '$ISSUER'
conditions:
missing_audience:
has_audience:
missing_scopes:
- profile
has_scopes:
request:
empty_audience: false
scopes:
empty_scopes: false
audience:
actor_token:
source: header
header_name: '$ACTOR_TOKEN_HEADER'
type: urn:ietf:params:oauth:token-type:access_token
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]
client_auth = ["client_secret_post"]
auth_methods = ["bearer"]
token_exchange = {
subject_token_issuers = [
{
issuer = var.issuer
conditions = {
missing_audience =
has_audience =
missing_scopes = ["profile"]
has_scopes =
}
} ]
request = {
empty_audience = false
scopes =
empty_scopes = false
audience =
actor_token = {
source = "header"
header_name = var.actor_token_header
type = "urn:ietf:params:oauth:token-type:access_token"
}
}
}
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 "actor_token_header" {
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:
- bearer
token_exchange:
subject_token_issuers:
- issuer: ${{ env "DECK_ISSUER" }}
conditions:
missing_audience:
has_audience:
missing_scopes:
- profile
has_scopes:
request:
empty_audience: false
scopes:
empty_scopes: false
audience:
actor_token:
source: header
header_name: ${{ env "DECK_ACTOR_TOKEN_HEADER" }}
type: urn:ietf:params:oauth:token-type:access_token
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": [
"bearer"
],
"token_exchange": {
"subject_token_issuers": [
{
"issuer": "'$ISSUER'",
"conditions": {
"missing_audience": null,
"has_audience": null,
"missing_scopes": [
"profile"
],
"has_scopes": null
}
}
],
"request": {
"empty_audience": false,
"scopes": null,
"empty_scopes": false,
"audience": null,
"actor_token": {
"source": "header",
"header_name": "'$ACTOR_TOKEN_HEADER'",
"type": "urn:ietf:params:oauth:token-type:access_token"
}
}
},
"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": [
"bearer"
],
"token_exchange": {
"subject_token_issuers": [
{
"issuer": "'$ISSUER'",
"conditions": {
"missing_audience": null,
"has_audience": null,
"missing_scopes": [
"profile"
],
"has_scopes": null
}
}
],
"request": {
"empty_audience": false,
"scopes": null,
"empty_scopes": false,
"audience": null,
"actor_token": {
"source": "header",
"header_name": "'$ACTOR_TOKEN_HEADER'",
"type": "urn:ietf:params:oauth:token-type:access_token"
}
}
},
"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:
- bearer
token_exchange:
subject_token_issuers:
- issuer: '$ISSUER'
conditions:
missing_audience:
has_audience:
missing_scopes:
- profile
has_scopes:
request:
empty_audience: false
scopes:
empty_scopes: false
audience:
actor_token:
source: header
header_name: '$ACTOR_TOKEN_HEADER'
type: urn:ietf:params:oauth:token-type:access_token
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]
client_auth = ["client_secret_post"]
auth_methods = ["bearer"]
token_exchange = {
subject_token_issuers = [
{
issuer = var.issuer
conditions = {
missing_audience =
has_audience =
missing_scopes = ["profile"]
has_scopes =
}
} ]
request = {
empty_audience = false
scopes =
empty_scopes = false
audience =
actor_token = {
source = "header"
header_name = var.actor_token_header
type = "urn:ietf:params:oauth:token-type:access_token"
}
}
}
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 "actor_token_header" {
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:
- bearer
token_exchange:
subject_token_issuers:
- issuer: ${{ env "DECK_ISSUER" }}
conditions:
missing_audience:
has_audience:
missing_scopes:
- profile
has_scopes:
request:
empty_audience: false
scopes:
empty_scopes: false
audience:
actor_token:
source: header
header_name: ${{ env "DECK_ACTOR_TOKEN_HEADER" }}
type: urn:ietf:params:oauth:token-type:access_token
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": [
"bearer"
],
"token_exchange": {
"subject_token_issuers": [
{
"issuer": "'$ISSUER'",
"conditions": {
"missing_audience": null,
"has_audience": null,
"missing_scopes": [
"profile"
],
"has_scopes": null
}
}
],
"request": {
"empty_audience": false,
"scopes": null,
"empty_scopes": false,
"audience": null,
"actor_token": {
"source": "header",
"header_name": "'$ACTOR_TOKEN_HEADER'",
"type": "urn:ietf:params:oauth:token-type:access_token"
}
}
},
"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": [
"bearer"
],
"token_exchange": {
"subject_token_issuers": [
{
"issuer": "'$ISSUER'",
"conditions": {
"missing_audience": null,
"has_audience": null,
"missing_scopes": [
"profile"
],
"has_scopes": null
}
}
],
"request": {
"empty_audience": false,
"scopes": null,
"empty_scopes": false,
"audience": null,
"actor_token": {
"source": "header",
"header_name": "'$ACTOR_TOKEN_HEADER'",
"type": "urn:ietf:params:oauth:token-type:access_token"
}
}
},
"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:
- bearer
token_exchange:
subject_token_issuers:
- issuer: '$ISSUER'
conditions:
missing_audience:
has_audience:
missing_scopes:
- profile
has_scopes:
request:
empty_audience: false
scopes:
empty_scopes: false
audience:
actor_token:
source: header
header_name: '$ACTOR_TOKEN_HEADER'
type: urn:ietf:params:oauth:token-type:access_token
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]
client_auth = ["client_secret_post"]
auth_methods = ["bearer"]
token_exchange = {
subject_token_issuers = [
{
issuer = var.issuer
conditions = {
missing_audience =
has_audience =
missing_scopes = ["profile"]
has_scopes =
}
} ]
request = {
empty_audience = false
scopes =
empty_scopes = false
audience =
actor_token = {
source = "header"
header_name = var.actor_token_header
type = "urn:ietf:params:oauth:token-type:access_token"
}
}
}
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 "actor_token_header" {
type = string
}
variable "token_salt" {
type = string
}
관련 리소스
더 알아보기 (Learn more)
- 토큰 교환 지원에 대한 상세 참조 문서예요 — Token exchange reference
- Kong Gateway에서 OpenID Connect 플러그인의 전반적인 동작 방식을 설명해요 — OpenID Connect in Kong Gateway
- Kong Gateway의 인증 개념을 넓게 다루는 문서예요 — Authentication in Kong Gateway
- OpenID Connect 관련 실습 튜토리얼을 모아서 볼 수 있어요 — OpenID Connect tutorials
- decK에서
kong.yaml구성 파일을 시작하는 방법을 안내해요 —kong.yaml