Datakit으로 런타임에 동적으로 결정되는 서드파티 서비스에 Kong 인증하기
Datakit으로 런타임에 동적으로 결정되는 서드파티 서비스에 Kong 인증하기 (Datakit: Authenticate Kong to a third-party service resolved at runtime)
이 문서는 Datakit 플러그인으로 Kong이 런타임에 동적으로 결정되는 서드파티 서비스에 인증하는 방법을 설명해요 요청을 프록시하기 전에 동적 내부 인증 엔드포인트를 통해 요청 헤더를 주입하는 구성인데요, STATIC_INPUTS부터 BUILD_HEADERS, BUILD_URL, AUTH_REQUEST, UPSTREAM_AUTH_HEADER까지 노드들이 인증 흐름을 단계별로 이어줘요 decK용 kong.yaml과 Admin API 두 가지 방식의 설정 예제도 함께 제공해요
출처: 문서
본문
런타임에 결정되는 서드파티 서비스에 대해 Kong 인증하기v3.13+
동적 내부 인증 엔드포인트를 사용해 요청을 프록시하기 전에 요청 헤더를 주입해요.
이 예시는 다음 노드들로 구성돼요:
STATIC_INPUTS노드는 다른 노드의 입력으로 사용될 몇 가지 정적 값을 설정해요.BUILD_HEADERS노드는 클라이언트 쿼리에서 API 키를 가져와 인증 서비스로 전송될 요청 헤더에 주입해요.BUILD_URL노드는 요청 헤더의 요청 경로 파라미터를 기반으로 인증 서비스 URL을 동적으로 구성해요.AUTH_REQUEST노드는 인증 서비스에 POST 요청을 보내요.UPSTREAM_AUTH_HEADER노드는 인증 서비스에서 받은 액세스 토큰으로 Authorization 헤더를 구성하고, 요청을 프록시하기 전에 그 헤더를 서비스 요청 헤더에 추가해요.
플러그인 설정하기
전역
decK
이 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
config:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
- name: BUILD_URL
type: jq
input: request.headers
jq: '"https://my-token-service/" + .path + "/auth-token"
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + " " + .access_token)
}
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
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": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
-
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:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
'X-Api-Key': (.query.api_key // 'none')
}
- name: BUILD_URL
type: jq
input: request.headers
jq: ''https://my-token-service/' + .path + '/auth-token'
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + ' ' + .access_token)
}
plugin: datakit
" | 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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "STATIC_INPUTS"
type = "static"
values = {
headers = {
Content-Type = "application/x-www-form-urlencoded"
}
body = "grant_type=client_credentials"
}
},
{
name = "BUILD_HEADERS"
type = "jq"
inputs = {
headers = "STATIC_INPUTS.headers"
query = "request.query"
}
jq = <<EOF
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
EOF
},
{
name = "BUILD_URL"
type = "jq"
input = "request.headers"
jq = <<EOF
"https://my-token-service/" + .path + "/auth-token"
EOF
},
{
name = "AUTH_REQUEST"
type = "call"
inputs = {
headers = "BUILD_HEADERS"
body = "STATIC_INPUTS.body"
url = "BUILD_URL"
}
url = "https://my-token-service/auth-token"
method = "POST"
},
{
name = "UPSTREAM_AUTH_HEADER"
type = "jq"
input = "AUTH_REQUEST.body"
output = "service_request.headers"
jq = <<EOF
{
Authorization: (.token_type + " " + .access_token)
}
EOF
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
서비스
decK
이 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
service: serviceName|Id
config:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
- name: BUILD_URL
type: jq
input: request.headers
jq: '"https://my-token-service/" + .path + "/auth-token"
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + " " + .access_token)
}
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
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": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더는 여러분의 값으로 교체해야 해요:
-
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:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
'X-Api-Key': (.query.api_key // 'none')
}
- name: BUILD_URL
type: jq
input: request.headers
jq: ''https://my-token-service/' + .path + '/auth-token'
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + ' ' + .access_token)
}
plugin: datakit
" | 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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "STATIC_INPUTS"
type = "static"
values = {
headers = {
Content-Type = "application/x-www-form-urlencoded"
}
body = "grant_type=client_credentials"
}
},
{
name = "BUILD_HEADERS"
type = "jq"
inputs = {
headers = "STATIC_INPUTS.headers"
query = "request.query"
}
jq = <<EOF
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
EOF
},
{
name = "BUILD_URL"
type = "jq"
input = "request.headers"
jq = <<EOF
"https://my-token-service/" + .path + "/auth-token"
EOF
},
{
name = "AUTH_REQUEST"
type = "call"
inputs = {
headers = "BUILD_HEADERS"
body = "STATIC_INPUTS.body"
url = "BUILD_URL"
}
url = "https://my-token-service/auth-token"
method = "POST"
},
{
name = "UPSTREAM_AUTH_HEADER"
type = "jq"
input = "AUTH_REQUEST.body"
output = "service_request.headers"
jq = <<EOF
{
Authorization: (.token_type + " " + .access_token)
}
EOF
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
Route
decK
이 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
route: routeName|Id
config:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
- name: BUILD_URL
type: jq
input: request.headers
jq: '"https://my-token-service/" + .path + "/auth-token"
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + " " + .access_token)
}
{: 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": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더는 여러분의 값으로 교체해야 해요:
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": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더는 여러분의 값으로 교체해야 해요:
-
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:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
'X-Api-Key': (.query.api_key // 'none')
}
- name: BUILD_URL
type: jq
input: request.headers
jq: ''https://my-token-service/' + .path + '/auth-token'
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + ' ' + .access_token)
}
plugin: datakit
" | 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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "STATIC_INPUTS"
type = "static"
values = {
headers = {
Content-Type = "application/x-www-form-urlencoded"
}
body = "grant_type=client_credentials"
}
},
{
name = "BUILD_HEADERS"
type = "jq"
inputs = {
headers = "STATIC_INPUTS.headers"
query = "request.query"
}
jq = <<EOF
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
EOF
},
{
name = "BUILD_URL"
type = "jq"
input = "request.headers"
jq = <<EOF
"https://my-token-service/" + .path + "/auth-token"
EOF
},
{
name = "AUTH_REQUEST"
type = "call"
inputs = {
headers = "BUILD_HEADERS"
body = "STATIC_INPUTS.body"
url = "BUILD_URL"
}
url = "https://my-token-service/auth-token"
method = "POST"
},
{
name = "UPSTREAM_AUTH_HEADER"
type = "jq"
input = "AUTH_REQUEST.body"
output = "service_request.headers"
jq = <<EOF
{
Authorization: (.token_type + " " + .access_token)
}
EOF
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
route = {
id = konnect_gateway_route.my_route.id
}
}
Consumer
decK
다음 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
consumer: consumerName|Id
config:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
- name: BUILD_URL
type: jq
input: request.headers
jq: '"https://my-token-service/" + .path + "/auth-token"
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + " " + .access_token)
}
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:
consumerName|Id: 플러그인 구성이 대상으로 지정할 컨슈머의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/consumers/{consumerName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:
consumerName|Id: 플러그인 구성이 대상으로 지정할 컨슈머의id또는name이에요.
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumers/{consumerId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정에 연결된 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
consumerId: 플러그인 구성이 대상으로 지정할 컨슈머의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:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
'X-Api-Key': (.query.api_key // 'none')
}
- name: BUILD_URL
type: jq
input: request.headers
jq: ''https://my-token-service/' + .path + '/auth-token'
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + ' ' + .access_token)
}
plugin: datakit
" | kubectl apply -f -
다음으로, KongConsumer 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용하세요:
kubectl annotate -n kong kongconsumer CONSUMER_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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "STATIC_INPUTS"
type = "static"
values = {
headers = {
Content-Type = "application/x-www-form-urlencoded"
}
body = "grant_type=client_credentials"
}
},
{
name = "BUILD_HEADERS"
type = "jq"
inputs = {
headers = "STATIC_INPUTS.headers"
query = "request.query"
}
jq = <<EOF
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
EOF
},
{
name = "BUILD_URL"
type = "jq"
input = "request.headers"
jq = <<EOF
"https://my-token-service/" + .path + "/auth-token"
EOF
},
{
name = "AUTH_REQUEST"
type = "call"
inputs = {
headers = "BUILD_HEADERS"
body = "STATIC_INPUTS.body"
url = "BUILD_URL"
}
url = "https://my-token-service/auth-token"
method = "POST"
},
{
name = "UPSTREAM_AUTH_HEADER"
type = "jq"
input = "AUTH_REQUEST.body"
output = "service_request.headers"
jq = <<EOF
{
Authorization: (.token_type + " " + .access_token)
}
EOF
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
consumer = {
id = konnect_gateway_consumer.my_consumer.id
}
}
Consumer Group
decK
다음 섹션을 kong.yaml 구성 파일에 추가하세요:
_format_version: "3.0"
plugins:
- name: datakit
consumer_group: consumerGroupName|Id
config:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
- name: BUILD_URL
type: jq
input: request.headers
jq: '"https://my-token-service/" + .path + "/auth-token"
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + " " + .access_token)
}
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:
consumerGroupName|Id: 플러그인 구성이 대상으로 지정할 컨슈머 그룹의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/consumer_groups/{consumerGroupName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 자리표를 여러분의 값으로 바꿔야 해요:
consumerGroupName|Id: 플러그인 구성이 대상으로 삼을 컨슈머 그룹의id또는name이에요.
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumer_groups/{consumerGroupId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "datakit",
"config": {
"nodes": [
{
"name": "STATIC_INPUTS",
"type": "static",
"values": {
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials"
}
},
{
"name": "BUILD_HEADERS",
"type": "jq",
"inputs": {
"headers": "STATIC_INPUTS.headers",
"query": "request.query"
},
"jq": ".headers * {\n \"X-Api-Key\": (.query.api_key // \"none\")\n}\n"
},
{
"name": "BUILD_URL",
"type": "jq",
"input": "request.headers",
"jq": "\"https://my-token-service/\" + .path + \"/auth-token\"\n"
},
{
"name": "AUTH_REQUEST",
"type": "call",
"inputs": {
"headers": "BUILD_HEADERS",
"body": "STATIC_INPUTS.body",
"url": "BUILD_URL"
},
"url": "https://my-token-service/auth-token",
"method": "POST"
},
{
"name": "UPSTREAM_AUTH_HEADER",
"type": "jq",
"input": "AUTH_REQUEST.body",
"output": "service_request.headers",
"jq": "{\n Authorization: (.token_type + \" \" + .access_token)\n}\n"
}
]
}
}
'
다음 자리표를 여러분의 값으로 바꿔야 해요:
-
region: Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요. -
KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요. -
controlPlaneId: 컨트롤 플레인의id예요. -
consumerGroupId: 플러그인 구성이 대상으로 삼을 컨슈머 그룹의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:
nodes:
- name: STATIC_INPUTS
type: static
values:
headers:
Content-Type: application/x-www-form-urlencoded
body: grant_type=client_credentials
- name: BUILD_HEADERS
type: jq
inputs:
headers: STATIC_INPUTS.headers
query: request.query
jq: |
.headers * {
'X-Api-Key': (.query.api_key // 'none')
}
- name: BUILD_URL
type: jq
input: request.headers
jq: ''https://my-token-service/' + .path + '/auth-token'
'
- name: AUTH_REQUEST
type: call
inputs:
headers: BUILD_HEADERS
body: STATIC_INPUTS.body
url: BUILD_URL
url: https://my-token-service/auth-token
method: POST
- name: UPSTREAM_AUTH_HEADER
type: jq
input: AUTH_REQUEST.body
output: service_request.headers
jq: |
{
Authorization: (.token_type + ' ' + .access_token)
}
plugin: datakit
" | kubectl apply -f -
다음으로, KongConsumerGroup 리소스에 어노테이션을 달아서 KongPlugin 리소스를 적용하세요:
kubectl annotate -n kong kongconsumergroup CONSUMERGROUP_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_datakit" "my_datakit" {
enabled = true
config = {
nodes = [
{
name = "STATIC_INPUTS"
type = "static"
values = {
headers = {
Content-Type = "application/x-www-form-urlencoded"
}
body = "grant_type=client_credentials"
}
},
{
name = "BUILD_HEADERS"
type = "jq"
inputs = {
headers = "STATIC_INPUTS.headers"
query = "request.query"
}
jq = <<EOF
.headers * {
"X-Api-Key": (.query.api_key // "none")
}
EOF
},
{
name = "BUILD_URL"
type = "jq"
input = "request.headers"
jq = <<EOF
"https://my-token-service/" + .path + "/auth-token"
EOF
},
{
name = "AUTH_REQUEST"
type = "call"
inputs = {
headers = "BUILD_HEADERS"
body = "STATIC_INPUTS.body"
url = "BUILD_URL"
}
url = "https://my-token-service/auth-token"
method = "POST"
},
{
name = "UPSTREAM_AUTH_HEADER"
type = "jq"
input = "AUTH_REQUEST.body"
output = "service_request.headers"
jq = <<EOF
{
Authorization: (.token_type + " " + .access_token)
}
EOF
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
consumer_group = {
id = konnect_gateway_consumer_group.my_consumer_group.id
}
}
관련 리소스
더 알아보기 (Learn more)
- Datakit 플러그인의 기본 개념과 노드 구성 방식을 개괄적으로 설명해요 — Datakit overview
- Datakit을 처음 설정하고 기본 사용법을 익히는 과정을 안내해요 — Get started with Datakit
- Datakit 노드 흐름을 디버거로 추적하고 문제를 진단하는 방법을 다뤄요 — Using Debugger for Datakit
- decK 설정 파일인 kong.yaml 작성을 시작하는 방법을 안내해요 —
kong.yaml - Konnect에서 플러그인 등 구성을 관리할 때 사용하는 Control Planes Config API 레퍼런스예요 — Konnect Control Planes Config API reference