排解 AlloyDB Omni 中的 Active Directory 整合問題

選取說明文件版本:

本文說明在 AlloyDB Omni 中整合 Active Directory 時,可能會遇到的錯誤。並提供錯誤範例和建議修正方式。

與 AlloyDB Omni 整合 Active Directory 失敗

如果 Active Directory 無法運作,請按照下列步驟解決問題:

  1. 驗證 keytab 檔案。 請確認您可以使用取得的 keytab 連線至 Active Directory 伺服器:

    kinit -kt PATH_TO_KEYTAB_FILE postgres/DBCLUSTER_HOST@REALM
    
  2. 驗證主機。

    請確認產生 keytab 檔案時使用的主機,與 psql 指令中的主機相同,如下列範例所示:

    KTPass /princ postgres/DBCLUSTER_HOST@REALM /Pass PASSWORD /mapuser postgres /crypto ALL /ptype KRB5_NT_Principal /out OUTPUT_PATH
    
    psql -h DBCLUSTER_HOST -d DB_NAME -U USERNAME@REALM
    

    請確認兩個指令中的 DBCLUSTER_HOST 相同。

  3. 驗證 krb5.conf 檔案。

    在用戶端上驗證 krb5.conf 檔案的內容。確認 krb5.conf 檔案內容符合您的設定。

    cat /etc/krb5.conf
    

    預期輸出內容如下:

    [libdefaults]
      default_realm = REALM
    [realms]
      REALM = {
          kdc = KDC_HOST
          admin_server = ADMIN_SERVER
      }
    [domain_realm]
      HOST_DOMAIN_1 = REALM
      HOST_DOMAIN_2 = REALM
    
  4. 確認 HBA 項目和狀態。

    1. 執行下列指令,然後將記錄傳送給 AlloyDB Omni 產品團隊

      psql -h DBCLUSTER_HOST -U postgres -d postgres
      

      psql 會提示您輸入 postgres 使用者的密碼:

      Password for user postgres:
      

      psql 會傳回下列輸出內容:

      psql (17.5 (Ubuntu 17.5-0ubuntu0.25.04.1), server 16.3)
      SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
      Type "help" for help.
      
    2. psql 提示中執行下列指令:

      postgres=# table pg_hba_file_rules ;
      

      系統會傳回類似下列範例的輸出內容。

      rule_number |            file_name             | line_number |  type   | database |     user_name      |  address  |                 netmask                 | auth_method |         options          |                        error
      -------------+--------------------------------------+-------------+---------+----------+--------------------+-----------+-----------------------------------------+-------------+--------------------------+-----------------------------------------------------
            1 | /var/lib/postgresql/data/pg_hba.conf |           1 | host    | {all}    | {alloydbadmin}     | 127.0.0.1 | 255.255.255.255                         | trust       |                          |
              | /var/lib/postgresql/data/pg_hba.conf |           2 | hostssl | {all}    | {alloydbadmin}     | ::1       | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust       |                          | hostssl record cannot match because SSL is disabled
              | /var/lib/postgresql/data/pg_hba.conf |           3 | hostssl | {all}    | {alloydbpgbouncer} | 0.0.0.0   | 0.0.0.0                                 | cert        | {clientcert=verify-full} | hostssl record cannot match because SSL is disabled
              | /var/lib/postgresql/data/pg_hba.conf |           4 | hostssl | {all}    | {alloydbpgbouncer} | ::1       | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | cert        | {clientcert=verify-full} | hostssl record cannot match because SSL is disabled
              | /var/lib/postgresql/data/pg_hba.conf |           5 | hostssl | {all}    | {alloydbadmin}     | all       |                                         | reject      |                          | hostssl record cannot match because SSL is disabled
              | /var/lib/postgresql/data/pg_hba.conf |           6 |         |          |                    |           |                                         |             |                          | invalid CIDR mask in address "0.0.0.0/1000"
            2 | /var/lib/postgresql/data/pg_hba.conf |           7 | local   | {all}    | {all}              |           |                                         | trust       |                          |
      
  5. 查看 error 欄中的錯誤訊息,找出設定問題。

  6. 顯示偵錯層級 krb5 記錄。

    export KRB5_TRACE=/dev/stderr
    kinit AD_USER@REALM
    psql -h DBCLUSTER_HOST -d DB_NAME -U USERNAME@REALM
    

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: role "user2" does not exist

說明

如果嘗試連線的系統使用者未建立 PostgreSQL 使用者,或未對應角色,就會發生這個錯誤。

建議修正方式

在 PostgreSQL 中建立具有必要使用者名稱的角色,或在 pg_ident.conf 檔案中新增這個使用者的項目。

psql (16.3)
Type "help" for help.

postgres=# CREATE ROLE user2 WITH LOGIN;
CREATE ROLE

伺服器重新啟動失敗,並顯示「could not load /var/lib/postgresql/data/pg_hba.conf」錯誤

說明

pg_hba.conf 含有無效項目,因此無法重新啟動伺服器。

建議修正方式

檢查 pg_hba.conf 檔案是否有無效項目。

FATAL: LDAP group synchronization failed

說明

使用者嘗試登入時,LDAP 同步處理失敗。

建議修正方式

  1. postgres 使用者身分登入,然後執行下列指令:

    CREATE EXTENSION google_pg_auth;
    
  2. 查看 postgresql.log 檔案,瞭解 LDAP 登入失敗的原因。

    cat /obs/diagnostic/postgresql.log | grep google_pg_auth
    

後續步驟