Active Directory と Kubernetes 上の AlloyDB Omni を統合する

ドキュメントのバージョンを選択してください。

このドキュメントでは、Kubernetes ベースの AlloyDB Omni データベース クラスタで Active Directory 統合を有効にして、既存の Active Directory ベースのユーザーが AlloyDB Omni データベースにアクセスできるようにする方法について説明します。Active Directory の統合により、Kerberos メカニズムを使用して認証されたユーザーが AlloyDB Omni にアクセスするための認可が GSSAPI を介して提供されます。

AlloyDB Omni での Active Directory 構成はオプションです。デフォルトでは無効になっています。この構成メカニズムを使用できるのは、認証に Active Directory サーバーを使用する環境のみです。

このドキュメントは、Kubernetes マニフェスト ファイルの適用と kubectl コマンドライン ツールの使用に精通していることを前提としています。詳細については、コマンドライン ツール(kubectl)をご覧ください。

始める前に

Active Directory との統合を有効にするには、次の要件を満たしている必要があります。

  • Kubernetes 環境にデプロイされた AlloyDB Omni クラスタ
  • Active Directory サーバー Keytab

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. 次のコマンドを実行してフリート コントローラの現在の Deployment 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. 次のコマンドを実行してローカル コントローラの現在の Deployment 引数を取得し、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 ファイルの options フィールドに 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