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

Azure Managed Identity를 사용하여 Kong Gateway Azure PostgreSQL 서버에 연결하기

원문 보기 위키 갱신

Azure Managed Identity를 사용하여 Kong Gateway Azure PostgreSQL 서버에 연결하기 (Azure Managed Identity)

이 문서는 Azure Managed Identity 인증 방식으로 Kong Gateway를 Azure PostgreSQL 서버에 연결하는 방법을 안내해요 Microsoft Entra 인증을 활용하면 설정 파일에 데이터베이스 비밀번호를 저장하지 않아도 되니까 보안을 한층 강화할 수 있어요 관리 ID와 PostgreSQL 사용자 준비부터 환경 변수와 설정 파일을 통한 구성, pg_azure_auth 같은 파라미터와 자주 묻는 질문까지 차근차근 살펴볼게요

출처: 문서

본문

Microsoft Entra 인증(구 Azure AD)은 데이터베이스 비밀번호를 설정 파일에 저장하지 않고도 Kong Gateway를 Azure PostgreSQL 데이터베이스에 안전하게 연결할 수 있는 방법을 제공해요. 이 기능은 Service Principal과 Managed Identity 두 가지 인증 방식을 모두 지원해요. 이 문서에서는 Azure Managed Identity 인증을 사용해 Azure PostgreSQL Server에 연결하는 방법을 예제로 소개해요.

필수 조건

Kong Gateway에서 Azure 인증을 구성하기 전에 다음 항목이 필요해요:

  • Azure Database for PostgreSQL flexible server 인스턴스의 인증 방법으로 PostgreSQL and Microsoft Entra authentication을 선택해 Azure PostgreSQL Flexible Server를 사용 설정하세요.
  • managed identity와, 인증에 이 managed identity를 사용하는 Azure 리소스가 필요해요. 예를 들어 사용자 할당 managed identity를 만들고 Azure VM에 할당할 수 있어요. managed identity의 클라이언트 ID를 복사해 저장해 두세요. 클라이언트 ID는 Azure Portal의 managed identity 상세 페이지에서 확인할 수 있어요.
  • Managed Identity를 위한 Azure Database for PostgreSQL flexible server 사용자를 만드세요. managed identity용 PostgreSQL 사용자를 만들려면 Microsoft Entra 관리자로 Azure PostgreSQL 서버에 연결해야 해요. Azure PostgreSQL 서버에 성공적으로 로그인한 후 다음 SQL 명령을 실행하세요:
    postgres=> select * from pgaadauth_create_principal('my-managed-identity', false, false);
    
              pgaadauth_create_principal
    ------------------------------------------------
    Created role for "my-managed-identity"
    (1 row)
    

Azure PostgreSQL 사용자를 위해 올바른 Kong Gateway 데이터베이스도 준비해야 해요. 예를 들어 다음 명령은 kong 데이터베이스를 만들고 public 스키마에 대한 권한을 managed identity에 부여해요:

postgres=> create database kong owner 'my-managed-identity' encoding 'utf-8';
CREATE DATABASE
postgres=> \c kong
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
You are now connected to database "kong" as user "XXXXX".
kong=> grant all on schema public to "my-managed-identity";
GRANT

Kong Gateway에서 Azure 인증 구성하기

이제 데이터베이스 설정값을 지정해서 Kong Gateway에서 Azure 인증을 구성할 수 있어요.

환경 변수

환경 변수를 사용해 읽기-쓰기 데이터베이스를 구성하려면 다음 예제를 사용하세요:

# Basic database configuration
export KONG_DATABASE=postgres
export KONG_PG_HOST=your-server.postgres.database.azure.com
export KONG_PG_PORT=5432
export KONG_PG_DATABASE=kong
export KONG_PG_USER=my-managed-identity # needs to be the name of the managed identity

export KONG_PG_AZURE_AUTH=on
export KONG_PG_AZURE_CLIENT_ID=00000000-0000-0000-0000-000000000001 # the Client ID of the user assigned managed identity

환경 변수를 사용해 읽기 전용 데이터베이스를 구성하려면 다음 예제를 사용하세요:

# Read-only database configuration
export KONG_PG_RO_HOST=your-ro-server.postgres.database.azure.com
export KONG_PG_RO_PORT=5432
export KONG_PG_RO_DATABASE=kong
export KONG_PG_RO_USER=my-managed-identity # needs to be the name of the managed identity

export KONG_PG_RO_AZURE_AUTH=on
export KONG_PG_RO_AZURE_CLIENT_ID=00000000-0000-0000-0000-000000000001 # the Client ID of the user assigned managed identity

설정 파일

kong.conf 파일을 사용해 읽기-쓰기 데이터베이스를 구성하려면 다음 예제를 사용하세요:

# Basic database configuration
database = postgres
pg_host = your-server.postgres.database.azure.com
pg_port = 5432
pg_database = kong
pg_user = my-managed-identity # needs to be the name of the managed identity

pg_azure_auth = on
pg_azure_client_id = 00000000-0000-0000-0000-000000000001 # the Client ID of the user assigned managed identity

kong.conf 파일을 사용해 읽기 전용 데이터베이스를 구성하려면 다음 예제를 사용하세요:

# Read-only database configuration
pg_ro_host = your-ro-server.postgres.database.azure.com
pg_ro_port = 5432
pg_ro_database = kong
pg_ro_user = my-managed-identity # needs to be the name of the managed identity

pg_ro_azure_auth = on
pg_ro_azure_client_id = 00000000-0000-0000-0000-000000000001 # the Client ID of the user assigned managed identity

Azure PostgreSQL Server 구성 파라미터

다음 표는 Azure PostgreSQL Server에 연결하기 위해 Azure Service Principal 인증을 구성할 때 설정할 수 있는 다양한 구성 파라미터를 설명해요:

파라미터: pg_azure_auth

parameter: pg_azure_auth default_value: off description: | PostgreSQL 연결에 Azure 인증을 사용할지 여부를 결정해요. on으로 설정하면 pg_user에 정의된 사용자 이름이 데이터베이스 계정으로 사용되고, 데이터베이스 연결에는 TLS 사용이 강제돼요. 이 스위치가 on이면 pg_password는 사용되지 않아요.

파라미터: pg_azure_client_id

parameter: pg_azure_client_id default_value: none description: | 인증에 사용할 Azure 클라이언트 ID예요. Managed Identity인 경우: 사용자 할당 managed identity의 클라이언트 ID예요. Service Principal인 경우: Service Principal의 애플리케이션(클라이언트) ID예요.

파라미터: pg_azure_client_secret

parameter: pg_azure_client_secret default_value: none description: | 인증에 사용할 Azure 클라이언트 시크릿이에요. Service Principal 인증에는 필수예요. Managed Identity에는 필요하지 않아요.

파라미터: pg_azure_tenant_id

parameter: pg_azure_tenant_id default_value: none description: | Service Principal 인증에 사용할 Azure 테넌트 ID예요. Service Principal 인증을 사용할 때만 필요해요(Managed Identity에는 불필요해요). 지정하지 않으면 Managed Identity 인증이 시도돼요.

파라미터: pg_ro_azure_auth

parameter: pg_ro_azure_auth default_value: <pg_azure_auth> description: | pg_azure_auth와 같지만, 읽기 전용 연결에 사용되는 파라미터예요.

파라미터: pg_ro_azure_client_id

parameter: pg_ro_azure_client_id default_value: <pg_azure_client_id> description: | pg_azure_client_id와 같지만, 읽기 전용 연결에 사용되는 파라미터예요.

파라미터: pg_ro_azure_client_secret

parameter: pg_ro_azure_client_secret default_value: <pg_azure_client_secret> description: | pg_azure_client_secret와 같지만, 읽기 전용 연결에 사용되는 파라미터예요.

파라미터: pg_ro_azure_tenant_id

parameter: pg_ro_azure_tenant_id default_value: <pg_azure_tenant_id> description: | pg_azure_tenant_id와 같지만, 읽기 전용 연결에 사용되는 파라미터예요.

자주 묻는 질문(FAQ)

  • failed to initialize Azure client: no authentication mechanism worked for azure 오류는 어떻게 해결하나요? 디버그 로그를 표시하려면 --vv 파라미터를 붙여서 Kong Gateway 명령을 실행해 보세요. Azure 인증이 실패한 이유를 확인할 수 있어요. 예를 들어 다음 로그는 Managed Identity로 인증할 때 발생한 오류를 보여줘요:

    2025/08/20 06:55:13 [debug] 68220#0: *2 [lua] init.lua:32: auth(): could not authenticate to azure with ClientCredentials class, error: Couldn't find AZURE_CLIENT_SECRET env variable
    2025/08/20 06:55:13 [debug] 68220#0: *2 [lua] init.lua:32: auth(): could not authenticate to azure with WorkloadIdentityCredentials class, error: Couldn't find AZURE_FEDERATED_TOKEN_FILE env variable
    2025/08/20 06:55:13 [debug] 68220#0: *2 [lua] ManagedIdentityCredentials.lua:217: configureIMDSCredentialRequest(): use managed identity in IMDS
    2025/08/20 06:55:13 [debug] 68220#0: *2 [lua] ManagedIdentityCredentials.lua:150: try to use managed identity client_id XXXXXXXX
    2025/08/20 06:55:13 [debug] 68220#0: *2 [lua] http_connect.lua:253: connect(): poolname: http:169.254.169.254:80:nil::nil:::
    2025/08/20 06:55:13 [debug] 68220#0: *2 [lua] init.lua:32: auth(): could not authenticate to azure with ManagedIdentityCredentials class, error: managed identity credentials request failed, status: 400, body: {"error":"invalid_request","error_description":"Identity not found"}
    
  • pg_password를 Azure 인증과 함께 사용할 수 있나요? 아니요, pg_azure_auth가 활성화되어 있으면 pg_password는 무시돼요.

관련 리소스

더 알아보기 (Learn more)