본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Datakit으로 서로 다른 소스의 여러 JWT를 사용해 컨슈머 인증하기

원문 보기 위키 갱신

Datakit으로 서로 다른 소스의 여러 JWT를 사용해 컨슈머 인증하기 (Datakit: Authenticate Consumer using multiple JWTs from different sources)

이 문서는 Datakit 플러그인을 사용해 서로 다른 JWKS에 기반한 두 개의 JWT 소스에서 컨슈머를 인증하는 방법을 다뤄요. 기본 Authorization 헤더를 먼저 확인하고 없으면 Authorization2 헤더로 폴백하는 분기 흐름을 노드로 구성하는 방법을 설명해요. 검증된 JWT의 sub 클레임으로 Kong Gateway 컨슈머를 찾아 인증하는 전체 과정을 decK 설정 예제와 함께 따라 해 볼 수 있어요

출처: 문서

본문

서로 다른 소스의 여러 JWT를 사용해 Consumer 인증하기v3.14+

가능한 두 소스 중 하나에서 JWT를 검증해 Consumer를 인증해요. 각 소스는 서로 다른 JWKS로 뒷받침돼요.

플러그인은 먼저 기본 Authorization 헤더를 확인해요. 헤더를 찾지 못하면 보조 Authorization2 헤더로 폴백해요. 검증된 JWT의 sub 클레임을 사용해 일치하는 Kong Gateway Consumer를 조회하고 인증해요.

이 예시에는 다음 노드들이 포함돼요:

  1. 노드 HAS_AUTH1은 기본 Authorization 헤더가 있는지 확인해요.
  2. 노드 BRANCH_AUTH1은 Authorization 헤더를 확인해요. 헤더가 있으면 JWT를 추출해 JWKS1으로 검증하고 Consumer를 설정해요. 그렇지 않으면 보조 헤더를 확인해요.
  3. 노드 EXTRACT_AUTH1, VERIFY_AUTH1, BUILD_CONSUMER1, SET_CONSUMER1은 기본 JWT 경로를 처리해요.
  4. 노드 HAS_AUTH2는 보조 Authorization2 헤더가 있는지 확인해요.
  5. 노드 BRANCH_AUTH2는 보조 JWT 경로의 실행을 라우팅해요.
  6. 노드 EXTRACT_AUTH2, VERIFY_AUTH2, BUILD_CONSUMER2, SET_CONSUMER2는 보조 JWT 경로를 처리해요.

참고: Datakit의 우선순위는 810이에요. 즉, 우선순위 900 이상인 rate limiting 플러그인 다음에 실행돼요. Consumer 기반 rate limit을 사용하는 경우, rate limiting이 실행되기 전에 Consumer가 설정되도록 Datakit이 먼저 실행돼야 해요. 이는 동적 플러그인 순서 지정으로 조정할 수 있어요.

전제 조건

플러그인 설정하기

전역

decK

다음 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: datakit
    config:
      resources:
        vault:
          jwks1: "{vault://env/JWKS1_JSON}"
          jwks2: "{vault://env/JWKS2_JSON}"
      nodes:
      - name: HAS_AUTH1
        type: jq
        input: request.headers
        jq: "(.Authorization // .authorization) != null\n"
      - name: BRANCH_AUTH1
        type: branch
        input: HAS_AUTH1
        then:
        - EXTRACT_AUTH1
        - VERIFY_AUTH1
        - BUILD_CONSUMER1
        - SET_CONSUMER1
        else:
        - HAS_AUTH2
        - BRANCH_AUTH2
      - name: EXTRACT_AUTH1
        type: jq
        input: request.headers
        jq: ".Authorization // .authorization\n"
      - name: VERIFY_AUTH1
        type: jwt_verify
        issuers:
        - expected-issuer-1
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH1
          key: vault.jwks1
      - name: BUILD_CONSUMER1
        type: jq
        input: VERIFY_AUTH1.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER1
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER1
      - name: HAS_AUTH2
        type: jq
        input: request.headers
        jq: "(.Authorization2 // .authorization2) != null\n"
      - name: BRANCH_AUTH2
        type: branch
        input: HAS_AUTH2
        then:
        - EXTRACT_AUTH2
        - VERIFY_AUTH2
        - BUILD_CONSUMER2
        - SET_CONSUMER2
      - name: EXTRACT_AUTH2
        type: jq
        input: request.headers
        jq: ".Authorization2 // .authorization2\n"
      - name: VERIFY_AUTH2
        type: jwt_verify
        issuers:
        - expected-issuer-2
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH2
          key: vault.jwks2
      - name: BUILD_CONSUMER2
        type: jq
        input: VERIFY_AUTH2.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER2
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER2

{: 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '
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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더를 반드시 여러분의 값으로 바꾸세요:

  • 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:
  resources:
    vault:
      jwks1: '{vault://env/JWKS1_JSON}'
      jwks2: '{vault://env/JWKS2_JSON}'
  nodes:
  - name: HAS_AUTH1
    type: jq
    input: request.headers
    jq: '(.Authorization // .authorization) != null\n'
  - name: BRANCH_AUTH1
    type: branch
    input: HAS_AUTH1
    then:
    - EXTRACT_AUTH1
    - VERIFY_AUTH1
    - BUILD_CONSUMER1
    - SET_CONSUMER1
    else:
    - HAS_AUTH2
    - BRANCH_AUTH2
  - name: EXTRACT_AUTH1
    type: jq
    input: request.headers
    jq: '.Authorization // .authorization\n'
  - name: VERIFY_AUTH1
    type: jwt_verify
    issuers:
    - expected-issuer-1
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH1
      key: vault.jwks1
  - name: BUILD_CONSUMER1
    type: jq
    input: VERIFY_AUTH1.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER1
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER1
  - name: HAS_AUTH2
    type: jq
    input: request.headers
    jq: '(.Authorization2 // .authorization2) != null\n'
  - name: BRANCH_AUTH2
    type: branch
    input: HAS_AUTH2
    then:
    - EXTRACT_AUTH2
    - VERIFY_AUTH2
    - BUILD_CONSUMER2
    - SET_CONSUMER2
  - name: EXTRACT_AUTH2
    type: jq
    input: request.headers
    jq: '.Authorization2 // .authorization2\n'
  - name: VERIFY_AUTH2
    type: jwt_verify
    issuers:
    - expected-issuer-2
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH2
      key: vault.jwks2
  - name: BUILD_CONSUMER2
    type: jq
    input: VERIFY_AUTH2.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER2
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER2
plugin: datakit
" | kubectl apply -f -
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 Plugin을 생성하려면 Terraform 구성에 다음 내용을 추가해요:

resource "konnect_gateway_plugin_datakit" "my_datakit" {
  enabled = true

  config = {

    resources = {

      vault = {
        jwks1 = "{vault://env/JWKS1_JSON}"
        jwks2 = "{vault://env/JWKS2_JSON}"
      }
    }
    nodes = [
      {
        name = "HAS_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization // .authorization) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH1"
        type = "branch"
        input = "HAS_AUTH1"
        then = ["EXTRACT_AUTH1", "VERIFY_AUTH1", "BUILD_CONSUMER1", "SET_CONSUMER1"]
        else = ["HAS_AUTH2", "BRANCH_AUTH2"]
      }, 

      {
        name = "EXTRACT_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization // .authorization
EOF
      }, 

      {
        name = "VERIFY_AUTH1"
        type = "jwt_verify"
        issuers = ["expected-issuer-1"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH1"
          key = "vault.jwks1"
        }
      }, 

      {
        name = "BUILD_CONSUMER1"
        type = "jq"
        input = "VERIFY_AUTH1.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER1"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER1"
      }, 

      {
        name = "HAS_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization2 // .authorization2) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH2"
        type = "branch"
        input = "HAS_AUTH2"
        then = ["EXTRACT_AUTH2", "VERIFY_AUTH2", "BUILD_CONSUMER2", "SET_CONSUMER2"]
      }, 

      {
        name = "EXTRACT_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization2 // .authorization2
EOF
      }, 

      {
        name = "VERIFY_AUTH2"
        type = "jwt_verify"
        issuers = ["expected-issuer-2"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH2"
          key = "vault.jwks2"
        }
      }, 

      {
        name = "BUILD_CONSUMER2"
        type = "jq"
        input = "VERIFY_AUTH2.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER2"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER2"
      }    ]
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

Service

decK

다음 섹션을 kong.yaml 구성 파일에 추가해요:

_format_version: "3.0"
plugins:
  - name: datakit
    service: serviceName|Id
    config:
      resources:
        vault:
          jwks1: "{vault://env/JWKS1_JSON}"
          jwks2: "{vault://env/JWKS2_JSON}"
      nodes:
      - name: HAS_AUTH1
        type: jq
        input: request.headers
        jq: "(.Authorization // .authorization) != null\n"
      - name: BRANCH_AUTH1
        type: branch
        input: HAS_AUTH1
        then:
        - EXTRACT_AUTH1
        - VERIFY_AUTH1
        - BUILD_CONSUMER1
        - SET_CONSUMER1
        else:
        - HAS_AUTH2
        - BRANCH_AUTH2
      - name: EXTRACT_AUTH1
        type: jq
        input: request.headers
        jq: ".Authorization // .authorization\n"
      - name: VERIFY_AUTH1
        type: jwt_verify
        issuers:
        - expected-issuer-1
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH1
          key: vault.jwks1
      - name: BUILD_CONSUMER1
        type: jq
        input: VERIFY_AUTH1.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER1
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER1
      - name: HAS_AUTH2
        type: jq
        input: request.headers
        jq: "(.Authorization2 // .authorization2) != null\n"
      - name: BRANCH_AUTH2
        type: branch
        input: HAS_AUTH2
        then:
        - EXTRACT_AUTH2
        - VERIFY_AUTH2
        - BUILD_CONSUMER2
        - SET_CONSUMER2
      - name: EXTRACT_AUTH2
        type: jq
        input: request.headers
        jq: ".Authorization2 // .authorization2\n"
      - name: VERIFY_AUTH2
        type: jwt_verify
        issuers:
        - expected-issuer-2
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH2
          key: vault.jwks2
      - name: BUILD_CONSUMER2
        type: jq
        input: VERIFY_AUTH2.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER2
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER2

{: 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

반드시 다음 플레이스홀더를 여러분의 값으로 바꾸세요:

  • 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:

  • 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:
  resources:
    vault:
      jwks1: '{vault://env/JWKS1_JSON}'
      jwks2: '{vault://env/JWKS2_JSON}'
  nodes:
  - name: HAS_AUTH1
    type: jq
    input: request.headers
    jq: '(.Authorization // .authorization) != null\n'
  - name: BRANCH_AUTH1
    type: branch
    input: HAS_AUTH1
    then:
    - EXTRACT_AUTH1
    - VERIFY_AUTH1
    - BUILD_CONSUMER1
    - SET_CONSUMER1
    else:
    - HAS_AUTH2
    - BRANCH_AUTH2
  - name: EXTRACT_AUTH1
    type: jq
    input: request.headers
    jq: '.Authorization // .authorization\n'
  - name: VERIFY_AUTH1
    type: jwt_verify
    issuers:
    - expected-issuer-1
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH1
      key: vault.jwks1
  - name: BUILD_CONSUMER1
    type: jq
    input: VERIFY_AUTH1.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER1
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER1
  - name: HAS_AUTH2
    type: jq
    input: request.headers
    jq: '(.Authorization2 // .authorization2) != null\n'
  - name: BRANCH_AUTH2
    type: branch
    input: HAS_AUTH2
    then:
    - EXTRACT_AUTH2
    - VERIFY_AUTH2
    - BUILD_CONSUMER2
    - SET_CONSUMER2
  - name: EXTRACT_AUTH2
    type: jq
    input: request.headers
    jq: '.Authorization2 // .authorization2\n'
  - name: VERIFY_AUTH2
    type: jwt_verify
    issuers:
    - expected-issuer-2
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH2
      key: vault.jwks2
  - name: BUILD_CONSUMER2
    type: jq
    input: VERIFY_AUTH2.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER2
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER2
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 = {

    resources = {

      vault = {
        jwks1 = "{vault://env/JWKS1_JSON}"
        jwks2 = "{vault://env/JWKS2_JSON}"
      }
    }
    nodes = [
      {
        name = "HAS_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization // .authorization) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH1"
        type = "branch"
        input = "HAS_AUTH1"
        then = ["EXTRACT_AUTH1", "VERIFY_AUTH1", "BUILD_CONSUMER1", "SET_CONSUMER1"]
        else = ["HAS_AUTH2", "BRANCH_AUTH2"]
      }, 

      {
        name = "EXTRACT_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization // .authorization
EOF
      }, 

      {
        name = "VERIFY_AUTH1"
        type = "jwt_verify"
        issuers = ["expected-issuer-1"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH1"
          key = "vault.jwks1"
        }
      }, 

      {
        name = "BUILD_CONSUMER1"
        type = "jq"
        input = "VERIFY_AUTH1.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER1"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER1"
      }, 

      {
        name = "HAS_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization2 // .authorization2) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH2"
        type = "branch"
        input = "HAS_AUTH2"
        then = ["EXTRACT_AUTH2", "VERIFY_AUTH2", "BUILD_CONSUMER2", "SET_CONSUMER2"]
      }, 

      {
        name = "EXTRACT_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization2 // .authorization2
EOF
      }, 

      {
        name = "VERIFY_AUTH2"
        type = "jwt_verify"
        issuers = ["expected-issuer-2"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH2"
          key = "vault.jwks2"
        }
      }, 

      {
        name = "BUILD_CONSUMER2"
        type = "jq"
        input = "VERIFY_AUTH2.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER2"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER2"
      }    ]
  }

  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:
      resources:
        vault:
          jwks1: "{vault://env/JWKS1_JSON}"
          jwks2: "{vault://env/JWKS2_JSON}"
      nodes:
      - name: HAS_AUTH1
        type: jq
        input: request.headers
        jq: "(.Authorization // .authorization) != null\n"
      - name: BRANCH_AUTH1
        type: branch
        input: HAS_AUTH1
        then:
        - EXTRACT_AUTH1
        - VERIFY_AUTH1
        - BUILD_CONSUMER1
        - SET_CONSUMER1
        else:
        - HAS_AUTH2
        - BRANCH_AUTH2
      - name: EXTRACT_AUTH1
        type: jq
        input: request.headers
        jq: ".Authorization // .authorization\n"
      - name: VERIFY_AUTH1
        type: jwt_verify
        issuers:
        - expected-issuer-1
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH1
          key: vault.jwks1
      - name: BUILD_CONSUMER1
        type: jq
        input: VERIFY_AUTH1.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER1
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER1
      - name: HAS_AUTH2
        type: jq
        input: request.headers
        jq: "(.Authorization2 // .authorization2) != null\n"
      - name: BRANCH_AUTH2
        type: branch
        input: HAS_AUTH2
        then:
        - EXTRACT_AUTH2
        - VERIFY_AUTH2
        - BUILD_CONSUMER2
        - SET_CONSUMER2
      - name: EXTRACT_AUTH2
        type: jq
        input: request.headers
        jq: ".Authorization2 // .authorization2\n"
      - name: VERIFY_AUTH2
        type: jwt_verify
        issuers:
        - expected-issuer-2
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH2
          key: vault.jwks2
      - name: BUILD_CONSUMER2
        type: jq
        input: VERIFY_AUTH2.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER2
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER2

{: 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

  • 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

  • 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:
  resources:
    vault:
      jwks1: '{vault://env/JWKS1_JSON}'
      jwks2: '{vault://env/JWKS2_JSON}'
  nodes:
  - name: HAS_AUTH1
    type: jq
    input: request.headers
    jq: '(.Authorization // .authorization) != null\n'
  - name: BRANCH_AUTH1
    type: branch
    input: HAS_AUTH1
    then:
    - EXTRACT_AUTH1
    - VERIFY_AUTH1
    - BUILD_CONSUMER1
    - SET_CONSUMER1
    else:
    - HAS_AUTH2
    - BRANCH_AUTH2
  - name: EXTRACT_AUTH1
    type: jq
    input: request.headers
    jq: '.Authorization // .authorization\n'
  - name: VERIFY_AUTH1
    type: jwt_verify
    issuers:
    - expected-issuer-1
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH1
      key: vault.jwks1
  - name: BUILD_CONSUMER1
    type: jq
    input: VERIFY_AUTH1.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER1
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER1
  - name: HAS_AUTH2
    type: jq
    input: request.headers
    jq: '(.Authorization2 // .authorization2) != null\n'
  - name: BRANCH_AUTH2
    type: branch
    input: HAS_AUTH2
    then:
    - EXTRACT_AUTH2
    - VERIFY_AUTH2
    - BUILD_CONSUMER2
    - SET_CONSUMER2
  - name: EXTRACT_AUTH2
    type: jq
    input: request.headers
    jq: '.Authorization2 // .authorization2\n'
  - name: VERIFY_AUTH2
    type: jwt_verify
    issuers:
    - expected-issuer-2
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH2
      key: vault.jwks2
  - name: BUILD_CONSUMER2
    type: jq
    input: VERIFY_AUTH2.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER2
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER2
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 Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_datakit" "my_datakit" {
  enabled = true

  config = {

    resources = {

      vault = {
        jwks1 = "{vault://env/JWKS1_JSON}"
        jwks2 = "{vault://env/JWKS2_JSON}"
      }
    }
    nodes = [
      {
        name = "HAS_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization // .authorization) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH1"
        type = "branch"
        input = "HAS_AUTH1"
        then = ["EXTRACT_AUTH1", "VERIFY_AUTH1", "BUILD_CONSUMER1", "SET_CONSUMER1"]
        else = ["HAS_AUTH2", "BRANCH_AUTH2"]
      }, 

      {
        name = "EXTRACT_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization // .authorization
EOF
      }, 

      {
        name = "VERIFY_AUTH1"
        type = "jwt_verify"
        issuers = ["expected-issuer-1"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH1"
          key = "vault.jwks1"
        }
      }, 

      {
        name = "BUILD_CONSUMER1"
        type = "jq"
        input = "VERIFY_AUTH1.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER1"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER1"
      }, 

      {
        name = "HAS_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization2 // .authorization2) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH2"
        type = "branch"
        input = "HAS_AUTH2"
        then = ["EXTRACT_AUTH2", "VERIFY_AUTH2", "BUILD_CONSUMER2", "SET_CONSUMER2"]
      }, 

      {
        name = "EXTRACT_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization2 // .authorization2
EOF
      }, 

      {
        name = "VERIFY_AUTH2"
        type = "jwt_verify"
        issuers = ["expected-issuer-2"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH2"
          key = "vault.jwks2"
        }
      }, 

      {
        name = "BUILD_CONSUMER2"
        type = "jq"
        input = "VERIFY_AUTH2.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER2"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER2"
      }    ]
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  route = {
    id = konnect_gateway_route.my_route.id
  }
}

컨슈머

decK

kong.yaml 구성 파일에 다음 섹션을 추가해요:

_format_version: "3.0"
plugins:
  - name: datakit
    consumer: consumerName|Id
    config:
      resources:
        vault:
          jwks1: "{vault://env/JWKS1_JSON}"
          jwks2: "{vault://env/JWKS2_JSON}"
      nodes:
      - name: HAS_AUTH1
        type: jq
        input: request.headers
        jq: "(.Authorization // .authorization) != null\n"
      - name: BRANCH_AUTH1
        type: branch
        input: HAS_AUTH1
        then:
        - EXTRACT_AUTH1
        - VERIFY_AUTH1
        - BUILD_CONSUMER1
        - SET_CONSUMER1
        else:
        - HAS_AUTH2
        - BRANCH_AUTH2
      - name: EXTRACT_AUTH1
        type: jq
        input: request.headers
        jq: ".Authorization // .authorization\n"
      - name: VERIFY_AUTH1
        type: jwt_verify
        issuers:
        - expected-issuer-1
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH1
          key: vault.jwks1
      - name: BUILD_CONSUMER1
        type: jq
        input: VERIFY_AUTH1.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER1
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER1
      - name: HAS_AUTH2
        type: jq
        input: request.headers
        jq: "(.Authorization2 // .authorization2) != null\n"
      - name: BRANCH_AUTH2
        type: branch
        input: HAS_AUTH2
        then:
        - EXTRACT_AUTH2
        - VERIFY_AUTH2
        - BUILD_CONSUMER2
        - SET_CONSUMER2
      - name: EXTRACT_AUTH2
        type: jq
        input: request.headers
        jq: ".Authorization2 // .authorization2\n"
      - name: VERIFY_AUTH2
        type: jwt_verify
        issuers:
        - expected-issuer-2
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH2
          key: vault.jwks2
      - name: BUILD_CONSUMER2
        type: jq
        input: VERIFY_AUTH2.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER2
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER2

{: 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더는 여러분의 값으로 꼭 바꿔야 해요:

  • 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더는 여러분의 값으로 꼭 바꿔야 해요:

  • 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:
  resources:
    vault:
      jwks1: '{vault://env/JWKS1_JSON}'
      jwks2: '{vault://env/JWKS2_JSON}'
  nodes:
  - name: HAS_AUTH1
    type: jq
    input: request.headers
    jq: '(.Authorization // .authorization) != null\n'
  - name: BRANCH_AUTH1
    type: branch
    input: HAS_AUTH1
    then:
    - EXTRACT_AUTH1
    - VERIFY_AUTH1
    - BUILD_CONSUMER1
    - SET_CONSUMER1
    else:
    - HAS_AUTH2
    - BRANCH_AUTH2
  - name: EXTRACT_AUTH1
    type: jq
    input: request.headers
    jq: '.Authorization // .authorization\n'
  - name: VERIFY_AUTH1
    type: jwt_verify
    issuers:
    - expected-issuer-1
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH1
      key: vault.jwks1
  - name: BUILD_CONSUMER1
    type: jq
    input: VERIFY_AUTH1.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER1
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER1
  - name: HAS_AUTH2
    type: jq
    input: request.headers
    jq: '(.Authorization2 // .authorization2) != null\n'
  - name: BRANCH_AUTH2
    type: branch
    input: HAS_AUTH2
    then:
    - EXTRACT_AUTH2
    - VERIFY_AUTH2
    - BUILD_CONSUMER2
    - SET_CONSUMER2
  - name: EXTRACT_AUTH2
    type: jq
    input: request.headers
    jq: '.Authorization2 // .authorization2\n'
  - name: VERIFY_AUTH2
    type: jwt_verify
    issuers:
    - expected-issuer-2
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH2
      key: vault.jwks2
  - name: BUILD_CONSUMER2
    type: jq
    input: VERIFY_AUTH2.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER2
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER2
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 Plugin을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_datakit" "my_datakit" {
  enabled = true

  config = {

    resources = {

      vault = {
        jwks1 = "{vault://env/JWKS1_JSON}"
        jwks2 = "{vault://env/JWKS2_JSON}"
      }
    }
    nodes = [
      {
        name = "HAS_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization // .authorization) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH1"
        type = "branch"
        input = "HAS_AUTH1"
        then = ["EXTRACT_AUTH1", "VERIFY_AUTH1", "BUILD_CONSUMER1", "SET_CONSUMER1"]
        else = ["HAS_AUTH2", "BRANCH_AUTH2"]
      }, 

      {
        name = "EXTRACT_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization // .authorization
EOF
      }, 

      {
        name = "VERIFY_AUTH1"
        type = "jwt_verify"
        issuers = ["expected-issuer-1"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH1"
          key = "vault.jwks1"
        }
      }, 

      {
        name = "BUILD_CONSUMER1"
        type = "jq"
        input = "VERIFY_AUTH1.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER1"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER1"
      }, 

      {
        name = "HAS_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization2 // .authorization2) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH2"
        type = "branch"
        input = "HAS_AUTH2"
        then = ["EXTRACT_AUTH2", "VERIFY_AUTH2", "BUILD_CONSUMER2", "SET_CONSUMER2"]
      }, 

      {
        name = "EXTRACT_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization2 // .authorization2
EOF
      }, 

      {
        name = "VERIFY_AUTH2"
        type = "jwt_verify"
        issuers = ["expected-issuer-2"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH2"
          key = "vault.jwks2"
        }
      }, 

      {
        name = "BUILD_CONSUMER2"
        type = "jq"
        input = "VERIFY_AUTH2.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER2"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER2"
      }    ]
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  consumer = {
    id = konnect_gateway_consumer.my_consumer.id
  }
}

컨슈머 그룹

decK

다음 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: datakit
    consumer_group: consumerGroupName|Id
    config:
      resources:
        vault:
          jwks1: "{vault://env/JWKS1_JSON}"
          jwks2: "{vault://env/JWKS2_JSON}"
      nodes:
      - name: HAS_AUTH1
        type: jq
        input: request.headers
        jq: "(.Authorization // .authorization) != null\n"
      - name: BRANCH_AUTH1
        type: branch
        input: HAS_AUTH1
        then:
        - EXTRACT_AUTH1
        - VERIFY_AUTH1
        - BUILD_CONSUMER1
        - SET_CONSUMER1
        else:
        - HAS_AUTH2
        - BRANCH_AUTH2
      - name: EXTRACT_AUTH1
        type: jq
        input: request.headers
        jq: ".Authorization // .authorization\n"
      - name: VERIFY_AUTH1
        type: jwt_verify
        issuers:
        - expected-issuer-1
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH1
          key: vault.jwks1
      - name: BUILD_CONSUMER1
        type: jq
        input: VERIFY_AUTH1.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER1
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER1
      - name: HAS_AUTH2
        type: jq
        input: request.headers
        jq: "(.Authorization2 // .authorization2) != null\n"
      - name: BRANCH_AUTH2
        type: branch
        input: HAS_AUTH2
        then:
        - EXTRACT_AUTH2
        - VERIFY_AUTH2
        - BUILD_CONSUMER2
        - SET_CONSUMER2
      - name: EXTRACT_AUTH2
        type: jq
        input: request.headers
        jq: ".Authorization2 // .authorization2\n"
      - name: VERIFY_AUTH2
        type: jwt_verify
        issuers:
        - expected-issuer-2
        required_claims:
        - sub
        - iss
        - exp
        inputs:
          token: EXTRACT_AUTH2
          key: vault.jwks2
      - name: BUILD_CONSUMER2
        type: jq
        input: VERIFY_AUTH2.claims
        jq: '{ "username": .sub }
             '
      - name: SET_CONSUMER2
        type: property
        property: kong.client.consumer
        input: BUILD_CONSUMER2

{: 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더는 반드시 여러분의 값으로 바꾸세요:

  • 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": {
        "resources": {
          "vault": {
            "jwks1": "{vault://env/JWKS1_JSON}",
            "jwks2": "{vault://env/JWKS2_JSON}"
          }
        },
        "nodes": [
          {
            "name": "HAS_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization // .authorization) != null\n"
          },
          {
            "name": "BRANCH_AUTH1",
            "type": "branch",
            "input": "HAS_AUTH1",
            "then": [
              "EXTRACT_AUTH1",
              "VERIFY_AUTH1",
              "BUILD_CONSUMER1",
              "SET_CONSUMER1"
            ],
            "else": [
              "HAS_AUTH2",
              "BRANCH_AUTH2"
            ]
          },
          {
            "name": "EXTRACT_AUTH1",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization // .authorization\n"
          },
          {
            "name": "VERIFY_AUTH1",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-1"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH1",
              "key": "vault.jwks1"
            }
          },
          {
            "name": "BUILD_CONSUMER1",
            "type": "jq",
            "input": "VERIFY_AUTH1.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER1",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER1"
          },
          {
            "name": "HAS_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": "(.Authorization2 // .authorization2) != null\n"
          },
          {
            "name": "BRANCH_AUTH2",
            "type": "branch",
            "input": "HAS_AUTH2",
            "then": [
              "EXTRACT_AUTH2",
              "VERIFY_AUTH2",
              "BUILD_CONSUMER2",
              "SET_CONSUMER2"
            ]
          },
          {
            "name": "EXTRACT_AUTH2",
            "type": "jq",
            "input": "request.headers",
            "jq": ".Authorization2 // .authorization2\n"
          },
          {
            "name": "VERIFY_AUTH2",
            "type": "jwt_verify",
            "issuers": [
              "expected-issuer-2"
            ],
            "required_claims": [
              "sub",
              "iss",
              "exp"
            ],
            "inputs": {
              "token": "EXTRACT_AUTH2",
              "key": "vault.jwks2"
            }
          },
          {
            "name": "BUILD_CONSUMER2",
            "type": "jq",
            "input": "VERIFY_AUTH2.claims",
            "jq": "{ \"username\": .sub }\n"
          },
          {
            "name": "SET_CONSUMER2",
            "type": "property",
            "property": "kong.client.consumer",
            "input": "BUILD_CONSUMER2"
          }
        ]
      }
    }
    '

다음 플레이스홀더는 반드시 여러분의 값으로 바꿔야 해요:

  • region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • consumerGroupId: 플러그인 구성이 대상으로 삼는 컨슈머 그룹의 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:
  resources:
    vault:
      jwks1: '{vault://env/JWKS1_JSON}'
      jwks2: '{vault://env/JWKS2_JSON}'
  nodes:
  - name: HAS_AUTH1
    type: jq
    input: request.headers
    jq: '(.Authorization // .authorization) != null\n'
  - name: BRANCH_AUTH1
    type: branch
    input: HAS_AUTH1
    then:
    - EXTRACT_AUTH1
    - VERIFY_AUTH1
    - BUILD_CONSUMER1
    - SET_CONSUMER1
    else:
    - HAS_AUTH2
    - BRANCH_AUTH2
  - name: EXTRACT_AUTH1
    type: jq
    input: request.headers
    jq: '.Authorization // .authorization\n'
  - name: VERIFY_AUTH1
    type: jwt_verify
    issuers:
    - expected-issuer-1
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH1
      key: vault.jwks1
  - name: BUILD_CONSUMER1
    type: jq
    input: VERIFY_AUTH1.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER1
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER1
  - name: HAS_AUTH2
    type: jq
    input: request.headers
    jq: '(.Authorization2 // .authorization2) != null\n'
  - name: BRANCH_AUTH2
    type: branch
    input: HAS_AUTH2
    then:
    - EXTRACT_AUTH2
    - VERIFY_AUTH2
    - BUILD_CONSUMER2
    - SET_CONSUMER2
  - name: EXTRACT_AUTH2
    type: jq
    input: request.headers
    jq: '.Authorization2 // .authorization2\n'
  - name: VERIFY_AUTH2
    type: jwt_verify
    issuers:
    - expected-issuer-2
    required_claims:
    - sub
    - iss
    - exp
    inputs:
      token: EXTRACT_AUTH2
      key: vault.jwks2
  - name: BUILD_CONSUMER2
    type: jq
    input: VERIFY_AUTH2.claims
    jq: '{ 'username': .sub }

      '
  - name: SET_CONSUMER2
    type: property
    property: kong.client.consumer
    input: BUILD_CONSUMER2
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 플러그인을 생성하려면 Terraform 구성에 다음을 추가해요:

resource "konnect_gateway_plugin_datakit" "my_datakit" {
  enabled = true

  config = {

    resources = {

      vault = {
        jwks1 = "{vault://env/JWKS1_JSON}"
        jwks2 = "{vault://env/JWKS2_JSON}"
      }
    }
    nodes = [
      {
        name = "HAS_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization // .authorization) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH1"
        type = "branch"
        input = "HAS_AUTH1"
        then = ["EXTRACT_AUTH1", "VERIFY_AUTH1", "BUILD_CONSUMER1", "SET_CONSUMER1"]
        else = ["HAS_AUTH2", "BRANCH_AUTH2"]
      }, 

      {
        name = "EXTRACT_AUTH1"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization // .authorization
EOF
      }, 

      {
        name = "VERIFY_AUTH1"
        type = "jwt_verify"
        issuers = ["expected-issuer-1"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH1"
          key = "vault.jwks1"
        }
      }, 

      {
        name = "BUILD_CONSUMER1"
        type = "jq"
        input = "VERIFY_AUTH1.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER1"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER1"
      }, 

      {
        name = "HAS_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
(.Authorization2 // .authorization2) != null
EOF
      }, 

      {
        name = "BRANCH_AUTH2"
        type = "branch"
        input = "HAS_AUTH2"
        then = ["EXTRACT_AUTH2", "VERIFY_AUTH2", "BUILD_CONSUMER2", "SET_CONSUMER2"]
      }, 

      {
        name = "EXTRACT_AUTH2"
        type = "jq"
        input = "request.headers"
        jq = <<EOF
.Authorization2 // .authorization2
EOF
      }, 

      {
        name = "VERIFY_AUTH2"
        type = "jwt_verify"
        issuers = ["expected-issuer-2"]
        required_claims = ["sub", "iss", "exp"]

        inputs = {
          token = "EXTRACT_AUTH2"
          key = "vault.jwks2"
        }
      }, 

      {
        name = "BUILD_CONSUMER2"
        type = "jq"
        input = "VERIFY_AUTH2.claims"
        jq = <<EOF
{ "username": .sub }
EOF
      }, 

      {
        name = "SET_CONSUMER2"
        type = "property"
        property = "kong.client.consumer"
        input = "BUILD_CONSUMER2"
      }    ]
  }

  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
  • JWT의 sub 클레임으로 조회할 컨슈머 엔티티의 개념과 설정 방법을 설명해요 — Consumer
  • 이 예제에서 JWKS 값을 안전하게 저장하기 위해 사용하는 볼트 시크릿 설정 방법을 다뤄요 — Vault secrets
  • Datakit의 우선순위를 조정할 때 활용할 수 있는 동적 플러그인 순서 지정 방법을 설명해요 — dynamic plugin ordering
  • Datakit 노드 흐름을 디버깅할 때 사용하는 도구 사용법을 소개해요 — Using Debugger for Datakit