온프레미스 인증 구성
온프레미스 인증 구성 (Configuring on-prem authentication)
decK는 기본적으로 Kong Gateway와 같은 머신에서 실행되며 Admin API에 인증이 필요 없다고 가정해요. 이 문서에서는 이 기본 동작을 바꾸기 위해 사용하는 CLI 플래그를 소개해요. Admin API 주소 지정과 TLS 인증서 검증부터 RBAC 토큰, 상호 TLS(mTLS), OpenID Connect 인증 설정 방법까지 차례로 설명해요.
출처: 문서
본문
이 페이지에서는 이 동작을 커스터마이즈하는 데 필요한 CLI 플래그를 설명해요. 환경 변수나 설정 파일을 사용해 기본 동작을 바꾸고 싶다면 설정 옵션 페이지를 참고하세요.
다음 예제에서는 deck gateway ping을 사용하지만, 이 플래그들은 다른 모든 deck gateway 명령어에도 적용돼요.
--kong-addr 플래그는 decK가 Admin API를 사용하기 위해 호출하는 URL을 설정해요. 기본값은 http://localhost:8001이에요.
deck gateway ping --kong-addr https://my-kong-gateway.example.com:8001
자체 서명(self-signed) TLS 인증서를 사용해 Kong Gateway를 실행한다면, TLS 검증이 수행될 수 있도록 --ca-cert(원본 내용) 또는 --ca-cert-file 플래그를 지정해야 해요:
deck gateway ping --kong-addr https://my-kong-gateway.example.com:8001 --ca-cert-file /path/to/ca.crt
TLS 인증서를 검증하고 싶지 않다면(권장하지 않아요) --tls-skip-verify 플래그를 사용할 수 있어요.
토큰 인증
Admin API가 RBAC으로 보호되고 있다면, 요청에 Kong-Admin-Token 헤더를 보내야 해요. --headers 플래그를 사용하면 돼요:
deck gateway ping --headers "Kong-Admin-Token:$MY_TOKEN_HERE"
인증서 인증
Admin API가 상호 TLS(mutual TLS)로 보호되고 있다면, TLS 클라이언트 인증서와 키를 보내야 해요:
deck gateway ping --tls-client-cert-file /path/to/tls.crt --tls-client-cert-key /path/to/tls.key
또한 이 파일들의 원본 내용을 --tls-client-cert $CERT와 --tls-client-key $KEY로 지정할 수도 있어요.
OpenID Connect 인증
Admin API가 OpenID Connect로 보호되고 있다면, Kong Manager의 /auth 엔드포인트를 호출하고 쿠키를 저장해서 --kong-cookie-jar-path와 함께 사용해야 해요.
세션 쿠키를 생성하려면 다음 스크립트를 사용할 수 있어요. 상단의 KONG_ADMIN_URL, KONG_ADMIN_USER, KONG_IDP_USER, KONG_IDP_PASS 값을 반드시 변경하세요.
#!/usr/bin/env bash
# halt on errors
set -e
# The admin URL for Kong
KONG_ADMIN_URL=https://my-kong.example.com
# The admin user for Kong
# This user should be the one associated with
# the IDP user
KONG_ADMIN_USER=jdoe
# The IDP user of the person initiating
# the pipeline job
KONG_IDP_USER=jdoe@your-idp.com
# The corresponding password for the IDP user
KONG_IDP_PASS=********
# The Kong workspace we want to use
KONG_WORKSPACE=default
# Create restrictive temp directory for session cookie
TMPDIR=$(mktemp -d -t ci-XXXXXXXXXX)
chmod 700 "${TMPDIR}"
# A temporary file used for storing the Kong
# manager session cookie
COOKIE_JAR=$(mktemp "${TMPDIR}/cookie.jar.XXXX")
# Chmod the cookie jar file path to stop access from other users
# on the same system
chmod 600 "${COOKIE_JAR}"
# Create a unique user agent name for this request
# This exact name is used when creating the session cookie
# if you try to reuse the cookie without this name or a different user-agent
# name then the signature validation will fail. And the cookie will not be
# usable.
# The UNIQUE_USER_AGENT variable is generated by uuidgen and only ever stored
# in memory.
UNIQUE_USER_AGENT=$(uuidgen)
# Function to call delete on the auth endpoint
# this will destroy the cookie in the Kong database
function auth_logout() {
curl -s -X DELETE --cookie "${COOKIE_JAR}" --cookie-jar "${COOKIE_JAR}" \
-A "${UNIQUE_USER_AGENT}" \
-H "Kong-Admin-User: ${KONG_ADMIN_USER}" \
"${KONG_ADMIN_URL}/auth?session_logout=true"
}
# Function to remove the cookie file from the filesystem
function remove_cookie() {
if [ -d "${TMPDIR}" ]; then
/usr/bin/rm -rf "${TMPDIR}"
fi
}
# On any interrupt, error or normal exit remove the cookie jar folder
# and call auth_logout
trap \
"{ auth_logout; remove_cookie ; exit 0; }" \
SIGINT SIGTERM ERR EXIT
# By hitting the /auth endpoint of Kong admin API
# we can simulate a Kong Manager login and store
# the session cookie that is returned.
# To do this we pass the Kong admin user name, the
# IDP user name and the IDP password.
curl -s -k --get --cookie "${COOKIE_JAR}" --cookie-jar "${COOKIE_JAR}" \
-A "${UNIQUE_USER_AGENT}" \
-H "Kong-Admin-User: ${KONG_ADMIN_USER}" \
-u ${KONG_IDP_USER}:${KONG_IDP_PASS} \
${KONG_ADMIN_URL}/auth
# decK now has a session cookie it can use when talking to the admin api.
# The decK command passes the kong-admin-user and user-agent headers
# without both of these headers set to the correct value the deck commands
# session cookie will fail validation
deck gateway ping \
--workspace "${KONG_WORKSPACE}" \
--kong-addr "${KONG_ADMIN_URL}" \
--kong-cookie-jar-path "${COOKIE_JAR}" \
--headers "kong-admin-user:${KONG_ADMIN_USER}" \
--headers "user-agent:${UNIQUE_USER_AGENT}" \
--yes
관련 리소스
더 알아보기 (Learn more)
- 환경 변수나 설정 파일로 decK 기본 동작을 바꾸는 방법을 확인할 수 있어요 — configuration options
- Admin API 연결과 인증 설정을 점검할 때 쓰는 기본 명령이에요 —
deck gateway ping - decK의 게이트웨이 관련 명령 전체를 살펴볼 수 있어요 —
deck gateway