Kubernetes에서 AlloyDB Omni와 Active Directory 통합

문서 버전을 선택합니다.

이 문서에서는 기존 Active Directory 기반 사용자가 AlloyDB Omni 데이터베이스에 액세스할 수 있도록 Kubernetes 기반 AlloyDB Omni 데이터베이스 클러스터에서 Active Directory 통합을 사용 설정하는 방법을 설명합니다. Active Directory 통합은 Kerberos 메커니즘을 사용하여 인증된 사용자가 AlloyDB Omni에 액세스할 수 있도록 GSSAPI를 사용한 승인을 제공합니다.

AlloyDB Omni의 Active Directory 구성은 선택사항이며 기본적으로 사용 중지되어 있습니다. 인증에 Active Directory 서버를 사용하는 환경만 이 구성 메커니즘을 사용할 수 있습니다.

이 문서에서는 사용자가 Kubernetes 매니페스트 파일 적용 및 kubectl 명령줄 도구 사용에 익숙하다고 가정합니다. 자세한 내용은 명령줄 도구 (kubectl)를 참고하세요.

시작하기 전에

Active Directory 통합을 사용 설정하려면 다음이 필요합니다.

  • Kubernetes 환경에 배포된 AlloyDB Omni 클러스터
  • Active Directory 서버 키탭

Active Directory 인증 사용 설정

Active Directory 인증을 사용 설정하려면 다음 Helm 명령어를 실행합니다.

helm upgrade alloydbomni-operator PATH_TO_CHART -n alloydb-omni-system --set userDefinedAuthentication.enabled=true

이 명령어는 다음 출력을 반환합니다.

Release "alloydbomni-operator" has been upgraded. Happy Helming!
NAME: alloydbomni-operator
LAST DEPLOYED: CURRENT_TIMESTAMP
NAMESPACE: alloydb-omni-system
STATUS: deployed
REVISION: 2
TEST SUITE: None

Active Directory 인증 상태 확인

Active Directory 인증 상태를 확인하려면 다음 단계를 따르세요.

  1. Fleet 컨트롤러의 현재 배포 args을 가져오고 enable-user-defined-authenticationtrue로 설정되어 있는지 확인하려면 다음 명령어를 실행합니다.

    kubectl get deployment -n alloydb-omni-system fleet-controller-manager -o json | jq '.spec.template.spec.containers[0].args'
    
    [
      "--health-probe-bind-address=:8081",
      "--metrics-bind-address=127.0.0.1:8080",
      "--leader-elect",
      "--image-registry=gcr.io",
      ...
      "--enable-user-defined-authentication=true"
    ]
    
  2. 다음 명령어를 실행하여 로컬 컨트롤러의 현재 배포 인수를 가져오고 enable-user-defined-authenticationtrue로 설정되어 있는지 확인합니다.

    kubectl get deployment -n alloydb-omni-system local-controller-manager -o json | jq '.spec.template.spec.containers[0].args'
    
    [
      "--health-probe-bind-address=:8081",
      "--metrics-bind-address=127.0.0.1:8080",
      "--leader-elect",
      "--deployment-platform=generic-k8s",
      "--enable-backup-from-standby=true",
      "--enable-user-defined-authentication=true"
    ]
    

Active Directory 지원 구성

  1. pg_hba.conf 파일 항목을 사용하여 구성 맵을 만들고 적용합니다.

    kubectl apply -f - 
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: pg-hba-config
    data:
      pg_hba_entries: |
        # Active Directory-based users
        hostgssenc all all 0.0.0.0/0    gss
        hostgssenc all all ::1/128      gss
        # Database-based users
        hostssl    all all 0.0.0.0/0  scram-sha-256
        hostssl    all all ::/0       scram-sha-256
    EOF
    

    요구사항에 따라 이러한 항목을 수정합니다. 이러한 항목은 pg_hba.conf의 기본 항목을 덮어씁니다. 잘못된 구성을 추가하면 사용자가 로그인할 수 없습니다.

    위의 예에서는 GSS 기반 인증 항목을 추가한 후 비밀번호 기반 인증을 추가했습니다. 즉, 사용자가 GSS API를 사용하여 로그인합니다. 이 로그인 방식이 실패하면 비밀번호 기반 인증이 대체로 사용됩니다.

    자세한 내용은 pg_hba.conf 파일을 참고하세요.

  2. keytab으로 보안 비밀을 만들고 적용합니다.

     kubectl apply -f - 
     apiVersion: v1
     kind: Secret
     metadata:
       name: db-keytab-dbcluster-sample
     type: Opaque
     data:
       krb5.keytab: |
        BASE64_ENCODED_KEYTAB
     EOF
     

  3. 선택사항: pg_ident.conf 항목을 사용하여 구성 맵을 만들고 적용합니다.

      kubectl apply -f - EOF
      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: pg-ident-config
      data:
        pg_ident_entries: |
    MAP_NAME /^(.)@YOUR.REALM$/ \1 MAP_NAME /^(.)@your.realm$/ \1 EOF

    사용자 이름 매핑을 구현하려면 pg_hba.conf 파일의 옵션 필드에 map=MAP_NAME를 지정하세요.

    자세한 내용은 ID 맵을 참고하세요.

  4. Active Directory 통합을 사용 설정하려면 DBCluster 사양에 주석을 추가합니다.

    kubectl apply -f - DB_CLUSTER_NAME
    type: Opaque
    data:
      DB_CLUSTER_NAME: "ENCODED_PASSWORD"
    ---
    apiVersion: alloydbomni.dbadmin.goog/v1
    kind: DBCluster
    metadata:
      name: DB_CLUSTER_NAME
      annotations:
        dbs.dbadmin.goog.com/pg-hba-config-map: pg-hba-config
        dbs.dbadmin.goog.com/pg-ident-config-map: pg-ident-config
        dbs.dbadmin.goog.com/keytab-ref: db-keytab-dbcluster-sample
    spec:
      databaseVersion: "DB_VERSION"
      primarySpec:
        adminUser:
          passwordRef:
            name: db-pw-DB_CLUSTER_NAME
        resources:
          memory: MEMORY_SIZE
          cpu: CPU_COUNT
          disks:
          - name: DataDisk
            size: DISK_SIZE
    EOF
    

Active Directory 사용자로 데이터베이스 역할 만들기

  1. Active Directory 사용자와 일치하는 역할을 데이터베이스에 만듭니다. Active Directory 사용자의 역할을 만들려면 클러스터에 연결하고 다음 명령어를 실행합니다.

    username=# CREATE ROLE "USERNAME@REALM" WITH LOGIN;
    
  2. Active Directory 사용자를 사용하여 데이터베이스에 로그인합니다. 연결하려는 클라이언트에서 kinit를 사용 설정해야 합니다.

    kubectl exec -it postgres -n DB_CLUSTER_NAMESPACE -- bash
    root:/# kinit USERNAME
    Password for USERNAME@REALM:
    
    root:/# psql -h HOSTNAME -d DB_NAME -U USERNAME@REALM
    psql (16.6 (Ubuntu 16.6-0ubuntu0.24.04.1), server 16.3)
    GSSAPI-encrypted connection
    Type "help" for help.
    
  3. SQL 쿼리를 실행합니다.

    username=# select * from ;
    

Active Directory 인증 사용 중지

Active Directory 인증을 사용 중지하려면 다음 Helm 명령어를 실행합니다.

helm upgrade alloydbomni-operator PATH_TO_CHART -n alloydb-omni-system --set userDefinedAuthentication.enabled=false

Active Directory 인증 상태를 확인할 수 있습니다.

이 명령어는 다음 출력을 반환합니다.

Release "alloydbomni-operator" has been upgraded. Happy Helming!
NAME: alloydbomni-operator
LAST DEPLOYED: CURRENT_TIMESTAMP
NAMESPACE: alloydb-omni-system
STATUS: deployed
REVISION: 2
TEST SUITE: None