使用 Kerberos 身分驗證連線至 PostgreSQL - Amazon Aurora

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Kerberos 身分驗證連線至 PostgreSQL

您可以使用 pgAdmin 界面或 psql 等命令列界面搭配 Kerberos 身分驗證連接至 PostgreSQL。如需連線的詳細資訊,請參閱 連接至 Amazon Aurora PostgreSQL 資料庫叢集如需取得端點、連接埠號碼和其他連線所需詳細資訊的資訊,請參閱 檢視 Aurora 叢集的端點

若要使用 Kerberos 身分驗證搭配 pgAdmin 連接至 PostgreSQL,請遵循下列步驟:

  1. 在您的用戶端電腦上啟動 pgAdmin 應用程式。

  2. Dashboard (儀表板) 標籤上,選擇 Add New Server (新增伺服器)

  3. Create - Server (建立 - 伺服器) 對話方塊中,於 General (一般) 標籤上輸入名稱,以識別 pgAdmin 中的伺服器。

  4. Connection (連線) 標籤上,輸入來自 Aurora PostgreSQL 資料庫的下列資訊:

    • 對於 Host (託管),輸入 Aurora PostgreSQL 資料庫叢集的寫入器執行個體的端點。端點看起來類似下列:

      AUR-cluster-instance.111122223333.aws-region.rds.amazonaws.com

      若要從 Windows 用戶端連線至內部部署 Microsoft Active Directory,使用 AWS Managed Active Directory 中的網域名稱,而不是託管端點中的 rds.amazonaws.com。例如,假設 AWS 受管 Active Directory 的網域名稱為 corp.example.com。然後對於 Host (託管),端點的指定方式如下:

      AUR-cluster-instance.111122223333.aws-region.corp.example.com
    • 針對 Port (連接埠),輸入指派的連接埠。

    • 針對 Maintenance database (維護資料庫),輸入用戶端將連接的初始資料庫名稱。

    • 針對 Username (使用者名稱),輸入您在 步驟 7:針對您的 Kerberos 主體建立 PostgreSQL 使用者 中為 Kerberos 身分驗證輸入的使用者名稱。

  5. 選擇 Save (儲存)。

若要使用 Kerberos 身分驗證搭配 psql 連接至 PostgreSQL,請遵循下列步驟:

  1. 在命令提示中,執行下列命令。

    kinit username

    請將 username 換成使用者名稱。在提示字元中,輸入 Microsoft Active Directory 中為使用者存放的密碼。

  2. 如果 PostgreSQL 資料庫叢集是使用可公開存取的 VPC,請將資料庫叢集端點的 IP 地址放入 EC2 用戶端上的 /etc/hosts 檔案。例如,使用下列命令取得 IP 地址,然後將該地址放入 /etc/hosts 檔案。

    % dig +short PostgreSQL-endpoint.AWS-Region.rds.amazonaws.com ;; Truncated, retrying in TCP mode. ec2-34-210-197-118.AWS-Region.compute.amazonaws.com. 34.210.197.118 % echo " 34.210.197.118 PostgreSQL-endpoint.AWS-Region.rds.amazonaws.com" >> /etc/hosts

    如果使用來自 Windows 用戶端的內部部署 Microsoft Active Directory,則需要使用特殊化的端點進行連線。請使用 rds.amazonaws.com 受管 Active Directory 的網域名稱,而不是在主機端點中使用 Amazon 網域 AWS。

    例如,假設您的 AWS 受管 Active Directory 的網域名稱為 corp.example.com。則為端點使用 PostgreSQL-endpoint.AWS-Region.corp.example.com 格式並將其放入 /etc/hosts 檔案中。

    % echo " 34.210.197.118 PostgreSQL-endpoint.AWS-Region.corp.example.com" >> /etc/hosts
  3. 使用下列 psql 命令來登入與 Active Directory 整合的 PostgreSQL 資料庫叢集使用叢集或執行個體端點。

    psql -U username@CORP.EXAMPLE.COM -p 5432 -h PostgreSQL-endpoint.AWS-Region.rds.amazonaws.com postgres

    若要使用內部部署 Active Directory 從 Windows 用戶端登入 PostgreSQL 資料庫叢集,請使用下列 psql 命令搭配上一個步驟的網域名稱 (corp.example.com):

    psql -U username@CORP.EXAMPLE.COM -p 5432 -h PostgreSQL-endpoint.AWS-Region.corp.example.com postgres