在 AlloyDB Omni 中排查 Active Directory 集成问题

选择文档版本:

本文档介绍了在 AlloyDB Omni 中集成 Active Directory 时可能会遇到的错误。还提供了错误示例和建议的修复方法。

Active Directory 与 AlloyDB Omni 集成失败

如果 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(psql:错误:无法通过套接字“/tmp/.s.PGSQL.5432”连接到服务器:严重错误:角色“user2”不存在)

说明

如果尝试连接的系统用户未创建 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”(无法加载 /var/lib/postgresql/data/pg_hba.conf)

说明

服务器重启失败,因为 pg_hba.conf 包含无效条目。

建议的修复方法

检查 pg_hba.conf 文件中是否存在无效条目。

严重问题:LDAP 群组同步失败

说明

当用户尝试登录时,LDAP 同步失败。

建议的修复方法

  1. postgres 用户身份登录,然后运行以下命令:

    CREATE EXTENSION google_pg_auth;
    
  2. 检查 postgresql.log 文件,了解 LDAP 登录失败的原因。

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

后续步骤