AlloyDB Omni での Active Directory 構成はオプションです。デフォルトでは無効になっています。この構成メカニズムを使用できるのは、認証に Active Directory サーバーを使用する環境のみです。
始める前に
Active Directory を統合する前に、次の要件を満たしていることを確認してください。
- Active Directory が設定されていることを確認します。
- Active Directory サーバーの
REALM
を取得します。 - Active Directory サーバーのキー配布センター(KDC)のホスト名を取得します。ホスト名は Docker イメージに保存されます。
- Active Directory サーバーの管理サーバーのホスト名を取得します。このホスト名は Docker イメージに保存されます。
.keytab
ファイルを生成できるように、Active Directory サーバーにアクセスできることを確認します。- テストとログインに使用する Active Directory ユーザーを選択します。
- 既存の Active Directory サーバーから
.keytab
ファイルを取得します。
既存の Active Directory サーバーから .keytab ファイルを取得する
Active Directory サーバーから keytab を取得する手順は次のとおりです。
- Active Directory サーバーの PowerShell ターミナルに管理者としてログインします。
- 次のコマンドを実行するか、Active Directory ユーザー インターフェースを使用して、
postgres
というユーザーを作成します。 - この Active Directory サーバーにマッピングされるサービス プリンシパル Keytab を生成します。
- keytab ファイルを Linux マシンにコピーします。
New-ADUser -Name "postgres" ` -SamAccountName "postgres" ` -UserPrincipalName "postgres@REALM" ` -Description "Service Account for AlloyDB Omni PostgreSQL Kerberos Authentication" ` -AccountPassword (Read-Host -AsSecureString "Set a strong password for the postgres service account") ` -Enabled $true ` -PasswordNeverExpires $true
ktpass /princ postgres/ALLOYDB_HOST_NAME@REALM /Pass ChangeMe123 /mapuser postgres /crypto ALL /ptype KRB5_NT_PRINCIPAL /mapOp set /out C:\Users\Public\postgres.keytab
ここで、<HOST>
は AlloyDB Omni をデプロイする予定のサーバーの完全修飾ドメイン名です(例: alloydb-server.ad.example.com
)。ドメインレルム マッピングの krb5.conf
ファイルで同じホストを構成する必要があります。
Active Directory 認証を有効にする
AlloyDB Omni で Active Directory 認証を有効にするには、次の操作を行います。ここでは、プログラムがセキュリティ サービスにアクセスできるようにするアプリケーション プログラミング インターフェースである Generic Security Service Application Program Interface(GSSAPI)の構成も行います。
/var/lib/postgresql/data/pg_hba.conf
ファイルのhost all all all scram-sha-256
エントリの前に、
次のエントリを追加します。次の Docker コマンドを実行して、コンテナ内に
gss
を追加します。docker exec CONTAINER_NAME sed -i 's;^host all all all scram-sha-256$;hostgssenc all all 0.0.0.0/0 gss map=gssmap\n&;' /var/lib/postgresql/data/pg_hba.conf
次の Docker コマンドを実行して、
pg_hba.conf
ファイルがコンテナ内にあることを確認します。docker exec CONTAINER_NAME cat /var/lib/postgresql/data/pg_hba.conf
ファイルに次のエントリがあることを確認します。
hostgssenc all all 0.0.0.0/0 gss map=gssmap
詳細については、pg_hba.conf ファイルをご覧ください。
keytab ファイルを AlloyDB Omni イメージ内のデータ ディレクトリにコピーします。
docker cp PATH TO KEYTAB FILE CONTAINER_NAME:/var/lib/postgresql/data/alloydb.keytab docker exec CONTAINER_NAME chmod 600 /var/lib/postgresql/data/alloydb.keytab docker exec CONTAINER_NAME chown postgres:postgres /var/lib/postgresql/data/alloydb.keytab
keytab ファイルは、Kerberos によって PostgreSQL サーバー用に生成されます。認証の詳細については、GSSAPI 認証をご覧ください。
keytab ファイルのエントリを
/var/lib/postgresql/data/DATA_DIR/postgresql.conf
ファイルに追加します。次の Docker コマンドを実行して、コンテナ内にエントリを追加します。
docker exec CONTAINER_NAME sed -i '$akrb_server_keyfile='"'"'/var/lib/postgresql/data/alloydb.keytab'"'" /var/lib/postgresql/data/postgresql.conf
次の Docker コマンドを実行して、コンテナ内の
postgresql.conf
ファイルを確認します。docker exec CONTAINER_NAME tail /var/lib/postgresql/data/postgresql.conf
ファイルに次のエントリがあることを確認します。
krb_server_keyfile=/var/lib/postgresql/data/alloydb.keytab
詳細については、krb_server_keyfile をご覧ください。
省略可:
/var/lib/postgresql/data/DATA_DIR/pg_ident.conf
ファイルにエントリを追加します。GSSAPI などの外部認証システムを使用する場合、接続を開始したオペレーティング システム ユーザーの名前が、使用するデータベース ユーザー(ロール)と同じではない場合があります。
この場合、
/var/lib/postgresql/data/DATA_DIR/pg_ident.conf
ファイルにシステム ユーザーと PostgreSQL ユーザーのマッピングを指定します。docker exec -it CONTAINER_NAME bash $ echo -e " gssmap /^(.*)@EXAMPLE\.COM$ \1 gssmap /^(.*)@example\.com$ \1 " | column -t | tee -a /var/lib/postgresql/data/pg_ident.conf
ユーザー名のマッピングを実装するには、
pg_hba.conf
ファイルの options フィールドにmap=gssmap
を指定します。ID ベースの認証の詳細については、ID マップをご覧ください。
次のコマンドを使用して PostgreSQL 構成を再読み込みします。
docker exec -it CONTAINER_NAME psql -h localhost -U postgres psql (16.3) Type "help" for help. postgres=# select pg_reload_conf();
Active Directory 認証をテストする
Active Directory 認証が機能していることを確認する手順は次のとおりです。
kinit
を使用して Active Directory にログインします。通常
kinit
を実行するマシンから、次のpsql
コマンドを実行します。root@4f6414ad02ef:/# kinit AD_USER_NAME Password for user1@YOUR.REALM: root@4f6414ad02ef:/# psql --h ALLOYDB_SERVER_HOST_NAME -U AD_USER_NAME psql (16.6 (Ubuntu 16.6-0ubuntu0.24.04.1), server 16.3) GSSAPI-encrypted connection Type "help" for help. user1=#
Active Directory 認証を無効にする
AlloyDB Omni で Active Directory 認証を無効にするには、次の手順で GSSAPI を無効にします。
gss
認証方法を参照するpg_hba.conf
ファイル内のエントリを削除します。docker exec CONTAINER_NAME sed -i '/hostgssenc all all 0.0.0.0\/0 gss map=gssmap/d' /var/lib/postgresql/data/pg_hba.conf
次のコマンドを使用して PostgreSQL 構成を再読み込みします。
docker exec -it CONTAINER_NAME psql -h localhost -U postgres psql (16.3) Type "help" for help. postgres=# select pg_reload_conf();
次のステップ
- Kubernetes で Active Directory ユーザーのサポートを統合する。
- AlloyDB Omni で Active Directory のトラブルシューティングを行う。
- Active Directory グループのサポートを AlloyDB Omni と統合する。
- Kubernetes で Active Directory グループのサポートを統合する。
- AlloyDB Omni での Active Directory 統合のトラブルシューティング。