OpenID Connect: discovery 대신 커스텀 JWKS 엔드포인트 사용하기
OpenID Connect: discovery 대신 커스텀 JWKS 엔드포인트 사용하기 (Use a custom JWKS endpoint for discovery)
OpenID Connect 플러그인은 기본적으로 IdP의 discovery 과정에서 반환되는 jwks_uri를 사용하는데, 이 문서에서는 그 대신 쓸 커스텀 JWKS 엔드포인트를 설정하는 방법을 다뤄요. IdP가 표준과 다른 JWKS 엔드포인트를 제공할 때 특히 유용한 옵션이에요. 필요한 환경 변수를 확인하고, decK와 Admin API, Konnect API 세 가지 방식으로 플러그인을 설정하는 예시를 단계별로 보여줘요. 여러 JWKS 엔드포인트를 fallback으로 두고 싶을 때는 extra_jwks_uris를 쓰는 별도 예시 문서를 참고하라고도 안내해요
출처: 문서
본문
discovery에 커스텀 JWKS 엔드포인트 사용하기v3.14+
OpenID Connect 플러그인이 내부 discovery 메커니즘이 반환하는 엔드포인트 대신 사용할 커스텀 JWKS 엔드포인트를 설정해요. IdP가 비표준 JWKS 엔드포인트를 제공할 때 유용해요.
이 옵션은 extra_jwks_uris와 비슷하지만, 여러 폴백 옵션을 제공하는 대신 엔드포인트를 재정의해요.
여러 JWKS 엔드포인트를 사용해야 한다면 여러 IdP를 위한 토큰 검증 예제를 참고하세요.
전제 조건
- 구성된 identity provider(IdP)
환경 변수
-
ISSUER: IdP의 issuer 인증 URL이에요. 예를 들어, Keycloak을 IdP로 사용한다면 issuer URL은 다음과 같아요:http://localhost:8080/realms/example-realm -
JWKS_ENDPOINT: 내부 discovery 메커니즘이 반환하는jwks_uri대신 사용할 JWKS 엔드포인트의 URL이에요. -
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" }}
auth_methods:
- bearer
jwks_endpoint: ${{ env "DECK_JWKS_ENDPOINT" }}
issuers_allowed:
- issuer-url-for-example-host1
- issuer-url-for-example-host2
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'",
"auth_methods": [
"bearer"
],
"jwks_endpoint": "'$JWKS_ENDPOINT'",
"issuers_allowed": [
"issuer-url-for-example-host1",
"issuer-url-for-example-host2"
],
"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'",
"auth_methods": [
"bearer"
],
"jwks_endpoint": "'$JWKS_ENDPOINT'",
"issuers_allowed": [
"issuer-url-for-example-host1",
"issuer-url-for-example-host2"
],
"cache_tokens_salt": "'$TOKEN_SALT'"
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꾸세요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요.
리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API reference를 참고하세요.
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'
auth_methods:
- bearer
jwks_endpoint: '$JWKS_ENDPOINT'
issuers_allowed:
- issuer-url-for-example-host1
- issuer-url-for-example-host2
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
auth_methods = ["bearer"]
jwks_endpoint = var.jwks_endpoint
issuers_allowed = ["issuer-url-for-example-host1", "issuer-url-for-example-host2"]
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 "jwks_endpoint" {
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" }}
auth_methods:
- bearer
jwks_endpoint: ${{ env "DECK_JWKS_ENDPOINT" }}
issuers_allowed:
- issuer-url-for-example-host1
- issuer-url-for-example-host2
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'",
"auth_methods": [
"bearer"
],
"jwks_endpoint": "'$JWKS_ENDPOINT'",
"issuers_allowed": [
"issuer-url-for-example-host1",
"issuer-url-for-example-host2"
],
"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'",
"auth_methods": [
"bearer"
],
"jwks_endpoint": "'$JWKS_ENDPOINT'",
"issuers_allowed": [
"issuer-url-for-example-host1",
"issuer-url-for-example-host2"
],
"cache_tokens_salt": "'$TOKEN_SALT'"
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꾸세요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
serviceId: 플러그인 구성이 대상으로 할 서비스의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'
auth_methods:
- bearer
jwks_endpoint: '$JWKS_ENDPOINT'
issuers_allowed:
- issuer-url-for-example-host1
- issuer-url-for-example-host2
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
auth_methods = ["bearer"]
jwks_endpoint = var.jwks_endpoint
issuers_allowed = ["issuer-url-for-example-host1", "issuer-url-for-example-host2"]
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 "jwks_endpoint" {
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" }}
auth_methods:
- bearer
jwks_endpoint: ${{ env "DECK_JWKS_ENDPOINT" }}
issuers_allowed:
- issuer-url-for-example-host1
- issuer-url-for-example-host2
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'",
"auth_methods": [
"bearer"
],
"jwks_endpoint": "'$JWKS_ENDPOINT'",
"issuers_allowed": [
"issuer-url-for-example-host1",
"issuer-url-for-example-host2"
],
"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'",
"auth_methods": [
"bearer"
],
"jwks_endpoint": "'$JWKS_ENDPOINT'",
"issuers_allowed": [
"issuer-url-for-example-host1",
"issuer-url-for-example-host2"
],
"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'
auth_methods:
- bearer
jwks_endpoint: '$JWKS_ENDPOINT'
issuers_allowed:
- issuer-url-for-example-host1
- issuer-url-for-example-host2
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
사전 준비: 개인 액세스 토큰(Personal Access Token) 구성하기
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
auth_methods = ["bearer"]
jwks_endpoint = var.jwks_endpoint
issuers_allowed = ["issuer-url-for-example-host1", "issuer-url-for-example-host2"]
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 "jwks_endpoint" {
type = string
}
variable "token_salt" {
type = string
}
관련 리소스
더 알아보기 (Learn more)
- Kong Gateway에서 OpenID Connect 플러그인의 전반적인 개념과 설정을 먼저 이루면 좋아요 — OpenID Connect in Kong Gateway
- 여러 JWKS 엔드포인트를 fallback으로 사용하는 extra_jwks_uris 예시는 이 문서에서 바로 연결되어 있어요 — Token validation for multiple IdPs example
- decK 설정 파일 작성법은 예시의 kong.yaml을 따라 할 때 참고하면 돼요 —
kong.yaml - Konnect API로 플러그인을 설정할 때 이 API 레퍼런스가 필요해요 — Konnect Control Planes Config API reference
- OpenID Connect 관련 실습 튜토리얼을 모아서 볼 수 있어요 — OpenID Connect tutorials