OAuth 2.0 인증: Client Credentials 플로우 플러그인 활성화
OAuth 2.0 인증: Client Credentials 플로우 플러그인 활성화 (Enable the plugin for the Client Credentials flow)
이 문서는 OAuth 2.0 인증 플러그인에서 Client Credentials 플로우를 활성화하는 방법을 안내해요. decK, Admin API, Kubernetes Ingress Controller, Terraform 등 다양한 도구를 사용해 글로벌 또는 서비스 단위로 플러그인을 구성하는 예시를 단계별로 보여줘요. provision_key 같은 필수 환경 변수와 설정 방법도 함께 확인할 수 있어요
출처: 문서
본문
Client Credentials 플로우에 플러그인 활성화하기v1.0+
Client Credentials OAuth 2.0 플로우를 활성화하도록 플러그인을 설정해요.
환경 변수
PROVISION_KEY: 사용할 프로비전 키예요.
플러그인 설정하기
전역
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: oauth2
config:
scopes:
- email
provision_key: ${{ env "DECK_PROVISION_KEY" }}
enable_client_credentials: true
{: 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": "oauth2",
"config": {
"scopes": [
"email"
],
"provision_key": "'$PROVISION_KEY'",
"enable_client_credentials": true
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
scopes:
- email
provision_key: '$PROVISION_KEY'
enable_client_credentials: true
plugin: oauth2
" | 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_oauth2" "my_oauth2" {
enabled = true
config = {
scopes = ["email"]
provision_key = var.provision_key
enable_client_credentials = true
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
이 예제에서는 다음 변수들을 매니페스트에 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 런타임에 값을 지정할 수 있어요.
variable "provision_key" {
type = string
}
서비스
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: oauth2
service: serviceName|Id
config:
scopes:
- email
provision_key: ${{ env "DECK_PROVISION_KEY" }}
enable_client_credentials: true
{: 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": "oauth2",
"config": {
"scopes": [
"email"
],
"provision_key": "'$PROVISION_KEY'",
"enable_client_credentials": true
}
}
'
다음 플레이스홀더는 반드시 실제 값으로 바꿔야 해요:
serviceName|Id: 플러그인 설정이 적용될 서비스의id또는name이에요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
scopes:
- email
provision_key: '$PROVISION_KEY'
enable_client_credentials: true
plugin: oauth2
" | 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_oauth2" "my_oauth2" {
enabled = true
config = {
scopes = ["email"]
provision_key = var.provision_key
enable_client_credentials = true
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
이 예제에서는 다음 변수들을 매니페스트에 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 런타임에 값을 지정할 수 있어요.
variable "provision_key" {
type = string
}
라우트
decK
다음 섹션을 kong.yaml 설정 파일에 추가해요:
_format_version: "3.0"
plugins:
- name: oauth2
route: routeName|Id
config:
scopes:
- email
provision_key: ${{ env "DECK_PROVISION_KEY" }}
enable_client_credentials: true
{: 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": "oauth2",
"config": {
"scopes": [
"email"
],
"provision_key": "'$PROVISION_KEY'",
"enable_client_credentials": true
}
}
'
다음 플레이스홀더는 반드시 실제 값으로 바꿔야 해요:
routeName|Id: 플러그인 설정이 적용될 라우트의id또는name이에요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
scopes:
- email
provision_key: '$PROVISION_KEY'
enable_client_credentials: true
plugin: oauth2
" | 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_oauth2" "my_oauth2" {
enabled = true
config = {
scopes = ["email"]
provision_key = var.provision_key
enable_client_credentials = true
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
route = {
id = konnect_gateway_route.my_route.id
}
}
이 예제에서는 다음 변수들을 매니페스트에 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 런타임에 값을 지정할 수 있어요.
variable "provision_key" {
type = string
}
관련 리소스
더 알아보기 (Learn more)
- decK 설정 파일인 kong.yaml 작성 방법을 기본부터 소개해요 —
kong.yaml - Kong Gateway에서 OAuth 2.0 인증을 전체적으로 설정하는 실습 과정을 다뤄요 — Enable OAuth 2.0 authentication with Kong Gateway
- WebSocket 요청에 OAuth 2.0 인증을 적용하는 방법을 보여줘요 — Enable OAuth 2.0 authentication for WebSocket requests with Kong Gateway
- OIDC와 Kong OAuth2 토큰 인증을 함께 구성하는 방법을 설명해요 — Configure OIDC with Kong Oauth2 token authentication
- Kong Gateway에서 사용할 수 있는 다양한 인증 방식을 개괄적으로 정리해요 — Kong Gateway authentication