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

Okta를 사용한 OpenID Connect

원문 보기 위키 갱신

Okta를 사용한 OpenID Connect (OpenID Connect with Okta)

이 문서는 Okta를 IdP로 사용해서 브라우저 클라이언트를 인증하는 OIDC 플러그인 설정 방법을 안내해요. Okta 개발자 계정과 HTTPS로 보안된 Gateway Service, Route를 준비한 뒤, issuer와 클라이언트 ID/시크릿, 리디렉션 URI 같은 환경 변수를 활용해 decK YAML 등 여러 형식으로 플러그인을 구성할 수 있어요. Consumer를 따로 만들지 않아도 유효한 Okta 계정을 가진 사용자는 누구나 업스트림 서비스에 접근할 수 있고, Consumer 매핑이나 클레임 기반 pseudo-Consumer 설정으로 접근 범위를 더 좁힐 수도 있어요

출처: 문서

본문

Okta와 함께 OpenID Connect 사용하기v1.0+

Okta를 사용해 브라우저 클라이언트를 인증해요.

다음 설정 예제는 Consumer가 만들어져 있지 않은 사용자도 인증하고 업스트림 서비스에 접근할 수 있게 해줘요. 즉, 디렉터리에 유효한 계정을 가진 모든 사용자가 접근할 수 있어요. 접근을 더 제한하고 싶다면 선택할 수 있는 옵션이 몇 가지 있어요:

  • Consumer 매핑: Consumer 정보를 사용하는 다른 Kong Gateway 플러그인과 상호작용해야 하는 경우, IdP에서 받은 계정 데이터를 Kong Gateway Consumer에 매핑할 수 있어요. 자세한 내용은 Consumer 권한 부여를 사용한 OIDC를 참고하세요.
  • Pseudo-Consumer 매핑: 일반적으로 Consumer를 필요로 하는 플러그인의 경우, OIDC 플러그인이 실제 Consumer에 매핑하지 않고도 클레임 값을 기반으로 Consumer ID를 제공할 수 있어요. 플러그인 설정에서 credential_claim을 클레임으로 설정하면, 해당 클레임의 값을 추출해서 Kong Gateway가 보통 Consumer ID를 사용하는 자리에 그 값을 사용해요. 마찬가지로 authenticated_groups_claim을 설정하면 해당 클레임의 값을 추출해서 ACL 플러그인의 그룹으로 사용해요.

이 예제를 사용한 전체 튜토리얼은 인가 코드 플로우와 Okta로 OpenID Connect 구성하기를 참고하세요.

사전 준비

  • Okta 개발자 계정.

  • HTTPS로 보호되는 Gateway Service와 Route.

  • Kong Gateway Route를 가리키는, Okta에 등록된 애플리케이션.

  • Kong Gateway 노드에 대한 네트워크 접근 제어가 있다면, Okta, 업스트림 서비스, 클라이언트와 주고받는 트래픽을 허용해야 해요.

환경 변수

  • ISSUER: IdP의 issuer 인증 URL이에요. Okta의 경우 일반적으로 다음과 같은 형태예요: https://{oktaDomain}/oauth2/{authServer}/.well-known/openid-configuration.

  • CLIENT_ID: 플러그인이 IdP의 인증된 엔드포인트를 호출할 때 사용하는 클라이언트 ID예요.

  • CLIENT_SECRET: IdP에 연결하는 데 필요한 클라이언트 시크릿이에요.

  • REDIRECT_URI: client_id로 정의된 클라이언트의 redirect_uri예요.

  • TOKEN_SALT: 매번 동기화할 때마다 세션 자격 증명이 다시 생성되지 않도록 하기 위해 decK(v1.59 이상)가 요구하는 랜덤 문자열이에요. 이 파라미터는 다른 형식에서는 선택 사항이에요. 예를 들어 openssl rand -base64 16으로 하나 생성할 수 있어요.

플러그인 설정

Global

decK

이 섹션을 kong.yaml 설정 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: openid-connect
    config:
      issuer: ${{ env "DECK_ISSUER" }}
      client_id:
      - ${{ env "DECK_CLIENT_ID" }}
      client_secret:
      - ${{ env "DECK_CLIENT_SECRET" }}
      redirect_uri:
      - ${{ env "DECK_REDIRECT_URI" }}
      scopes_claim:
      - scp
      scopes:
      - openid
      - email
      - profile
      auth_methods:
      - authorization_code
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

{: data-file="kong.yaml" data-tool="deck" }

Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "redirect_uri": [
          "'$REDIRECT_URI'"
        ],
        "scopes_claim": [
          "scp"
        ],
        "scopes": [
          "openid",
          "email",
          "profile"
        ],
        "auth_methods": [
          "authorization_code"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '
Konnect API

다음 요청을 보내세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "redirect_uri": [
          "'$REDIRECT_URI'"
        ],
        "scopes_claim": [
          "scp"
        ],
        "scopes": [
          "openid",
          "email",
          "profile"
        ],
        "auth_methods": [
          "authorization_code"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

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

  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(Personal Access Token, PAT)이에요.

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

지역별 URL과 개인 액세스 토큰에 대해 자세히 알아보려면 Konnect Control Planes Config API reference를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
  labels:
    global: 'true'
config:
  issuer: '$ISSUER'
  client_id:
  - '$CLIENT_ID'
  client_secret:
  - '$CLIENT_SECRET'
  redirect_uri:
  - '$REDIRECT_URI'
  scopes_claim:
  - scp
  scopes:
  - openid
  - email
  - profile
  auth_methods:
  - authorization_code
  cache_tokens_salt: '$TOKEN_SALT'
plugin: openid-connect
" | kubectl apply -f -
Terraform
사전 준비: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway Plugin을 생성하려면 Terraform 설정에 다음을 추가하세요:

resource "konnect_gateway_plugin_openid_connect" "my_openid_connect" {
  enabled = true

  config = {
    issuer = var.issuer
    client_id = [var.client_id]
    client_secret = [var.client_secret]
    redirect_uri = [var.redirect_uri]
    scopes_claim = ["scp"]
    scopes = ["openid", "email", "profile"]
    auth_methods = ["authorization_code"]
    cache_tokens_salt = var.token_salt
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

이 예제에서는 다음 변수를 매니페스트에 추가해야 해요. TF_VAR_name=value로 설정하면 런타임에 값을 지정할 수 있어요.

variable "issuer" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "redirect_uri" {
  type = string
}
variable "token_salt" {
  type = string
}

Service

decK

이 섹션을 kong.yaml 설정 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: openid-connect
    service: serviceName|Id
    config:
      issuer: ${{ env "DECK_ISSUER" }}
      client_id:
      - ${{ env "DECK_CLIENT_ID" }}
      client_secret:
      - ${{ env "DECK_CLIENT_SECRET" }}
      redirect_uri:
      - ${{ env "DECK_REDIRECT_URI" }}
      scopes_claim:
      - scp
      scopes:
      - openid
      - email
      - profile
      auth_methods:
      - authorization_code
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

{: data-file="kong.yaml" data-tool="deck" }

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

  • serviceName|Id: 플러그인 설정이 대상으로 할 서비스의 id 또는 name이에요.
Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "redirect_uri": [
          "'$REDIRECT_URI'"
        ],
        "scopes_claim": [
          "scp"
        ],
        "scopes": [
          "openid",
          "email",
          "profile"
        ],
        "auth_methods": [
          "authorization_code"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

  • serviceName|Id: 플러그인 설정이 대상으로 할 서비스의 id 또는 name이에요.
Konnect API

다음 요청을 보내세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "redirect_uri": [
          "'$REDIRECT_URI'"
        ],
        "scopes_claim": [
          "scp"
        ],
        "scopes": [
          "openid",
          "email",
          "profile"
        ],
        "auth_methods": [
          "authorization_code"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

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

  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(Personal Access Token, PAT)이에요.

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

  • serviceId: 플러그인 설정이 대상으로 할 서비스의 id예요.

지역별 URL과 개인 액세스 토큰에 대해 자세히 알아보려면 Konnect Control Planes Config API reference를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  issuer: '$ISSUER'
  client_id:
  - '$CLIENT_ID'
  client_secret:
  - '$CLIENT_SECRET'
  redirect_uri:
  - '$REDIRECT_URI'
  scopes_claim:
  - scp
  scopes:
  - openid
  - email
  - profile
  auth_methods:
  - authorization_code
  cache_tokens_salt: '$TOKEN_SALT'
plugin: openid-connect
" | kubectl apply -f -

다음으로, service 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용하세요:

kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=
Terraform
사전 준비: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway Plugin을 생성하려면 Terraform 설정에 다음을 추가하세요:

resource "konnect_gateway_plugin_openid_connect" "my_openid_connect" {
  enabled = true

  config = {
    issuer = var.issuer
    client_id = [var.client_id]
    client_secret = [var.client_secret]
    redirect_uri = [var.redirect_uri]
    scopes_claim = ["scp"]
    scopes = ["openid", "email", "profile"]
    auth_methods = ["authorization_code"]
    cache_tokens_salt = var.token_salt
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  service = {
    id = konnect_gateway_service.my_service.id
  }
}

이 예제에서는 다음 변수를 매니페스트에 추가해야 해요. TF_VAR_name=value로 설정하면 런타임에 값을 지정할 수 있어요.

variable "issuer" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "redirect_uri" {
  type = string
}
variable "token_salt" {
  type = string
}

Route

decK

이 섹션을 kong.yaml 설정 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: openid-connect
    route: routeName|Id
    config:
      issuer: ${{ env "DECK_ISSUER" }}
      client_id:
      - ${{ env "DECK_CLIENT_ID" }}
      client_secret:
      - ${{ env "DECK_CLIENT_SECRET" }}
      redirect_uri:
      - ${{ env "DECK_REDIRECT_URI" }}
      scopes_claim:
      - scp
      scopes:
      - openid
      - email
      - profile
      auth_methods:
      - authorization_code
      cache_tokens_salt: ${{ env "DECK_TOKEN_SALT" }}

{: data-file="kong.yaml" data-tool="deck" }

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

  • routeName|Id: 플러그인 설정이 대상으로 할 라우트의 id 또는 name이에요.
Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "redirect_uri": [
          "'$REDIRECT_URI'"
        ],
        "scopes_claim": [
          "scp"
        ],
        "scopes": [
          "openid",
          "email",
          "profile"
        ],
        "auth_methods": [
          "authorization_code"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

  • routeName|Id: 플러그인 구성이 대상으로 삼을 라우트의 id 또는 name이에요.
Konnect API

다음 요청을 보내세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "openid-connect",
      "config": {
        "issuer": "'$ISSUER'",
        "client_id": [
          "'$CLIENT_ID'"
        ],
        "client_secret": [
          "'$CLIENT_SECRET'"
        ],
        "redirect_uri": [
          "'$REDIRECT_URI'"
        ],
        "scopes_claim": [
          "scp"
        ],
        "scopes": [
          "openid",
          "email",
          "profile"
        ],
        "auth_methods": [
          "authorization_code"
        ],
        "cache_tokens_salt": "'$TOKEN_SALT'"
      }
    }
    '

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

  • region: Kong Konnect가 호스팅되고 동작하는 지리적 지역이에요.

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

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

  • routeId: 플러그인 구성이 대상으로 삼을 라우트의 id예요.

지역별 URL과 개인 액세스 토큰에 대해 자세히 알아보려면 Konnect Control Planes Config API reference 문서를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  issuer: '$ISSUER'
  client_id:
  - '$CLIENT_ID'
  client_secret:
  - '$CLIENT_SECRET'
  redirect_uri:
  - '$REDIRECT_URI'
  scopes_claim:
  - scp
  scopes:
  - openid
  - email
  - profile
  auth_methods:
  - authorization_code
  cache_tokens_salt: '$TOKEN_SALT'
plugin: openid-connect
" | kubectl apply -f -

다음으로, httproute 또는 ingress 리소스에 어노테이션을 추가해서 KongPlugin 리소스를 적용해요:

Gateway API
kubectl annotate -n kong httproute  konghq.com/plugins=
Ingress
kubectl annotate -n kong ingress  konghq.com/plugins=
Terraform
사전 조건: 개인 액세스 토큰 구성하기
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음을 추가해요:

resource "konnect_gateway_plugin_openid_connect" "my_openid_connect" {
  enabled = true

  config = {
    issuer = var.issuer
    client_id = [var.client_id]
    client_secret = [var.client_secret]
    redirect_uri = [var.redirect_uri]
    scopes_claim = ["scp"]
    scopes = ["openid", "email", "profile"]
    auth_methods = ["authorization_code"]
    cache_tokens_salt = var.token_salt
  }

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

이 예제에서는 다음 변수를 매니페스트에 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 런타임에 값을 지정할 수 있어요.

variable "issuer" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "redirect_uri" {
  type = string
}
variable "token_salt" {
  type = string
}

관련 리소스

더 알아보기 (Learn more)