

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

# 在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds"></a>

*Rohit Kapoor，Amazon Web Services*

## 總結
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-summary"></a>

Amazon Relational Database Service (Amazon RDS) 支援 PostgreSQL 資料庫執行個體的 SSL 加密。使用 SSL，您可以加密應用程式與 Amazon RDS for PostgreSQL 資料庫執行個體之間的 PostgreSQL 連線。根據預設，Amazon RDS for PostgreSQL 會使用 SSL/TLS，並預期所有用戶端都會使用 SSL/TLS 加密進行連線。Amazon RDS for PostgreSQL 支援 TLS 1.1 和 1.2 版。

此模式說明如何啟用 Amazon RDS for PostgreSQL 資料庫執行個體的加密連線。您可以使用相同的程序來啟用 Amazon Aurora PostgreSQL 相容版本的加密連線。

## 先決條件和限制
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-prereqs"></a>
+ 作用中的 AWS 帳戶
+ [Amazon RDS for PostgreSQL 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_RDS_Configuring.html)
+ [SSL 套件](https://www.postgresql.org/docs/current/ssl-tcp.html)

## Architecture
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-architecture"></a>

![\[在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4f87c6a3-b4ff-4248-96d3-a4a498659735/images/ccc5c880-1191-4c12-a255-6908b96b96a5.png)


## 工具
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-tools"></a>
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理和開發平台。您可以在 Linux、Unix、macOS 和 Windows 上使用 pgAdmin 來管理 PostgreSQL 10 和更新版本中的資料庫物件。
+ [PostgreSQL 編輯器](https://wiki.postgresql.org/wiki/PostgreSQL_Clients)提供更易於使用的界面，協助您建立、開發和執行查詢，以及根據您的需求編輯程式碼。

## 最佳實務
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-best-practices"></a>
+ 監控不安全的資料庫連線。
+ 稽核資料庫存取權。
+ 確定備份和快照已在靜態加密。
+ 監控資料庫存取。
+ 避免不受限制的存取群組。
+ 使用 [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) 增強您的通知。
+ 定期監控政策遵循。

## 史詩
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-epics"></a>

### 下載信任的憑證並將其匯入您的信任存放區
<a name="download-a-trusted-certificate-and-import-it-into-your-trust-store"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將信任的憑證載入您的電腦。 | 若要將憑證新增至您電腦的信任根憑證授權機構存放區，請遵循下列步驟。（這些指示使用 Window Server 做為範例。)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html) | DevOps 工程師、遷移工程師、DBA | 

### 強制 SSL 連線
<a name="force-ssl-connections"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立參數群組並設定 rds.force\$1ssl 參數。 | 如果 PostgreSQL 資料庫執行個體具有自訂參數群組，請編輯參數群組並變更為 `rds.force_ssl` 1。如果資料庫執行個體使用未`rds.force_ssl`啟用的預設參數群組，請建立新的參數群組。您可以使用 Amazon RDS API 或手動修改新的參數群組，如下列說明所示。若要建立新的參數群組：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)若要將參數群組與 PostgreSQL 資料庫執行個體建立關聯：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithDBInstanceParamGroups.html)。 | DevOps 工程師、遷移工程師、DBA | 
| 強制 SSL 連線。 | 連線至 Amazon RDS for PostgreSQL 資料庫執行個體。不使用 SSL 的連線嘗試會遭到拒絕，並顯示錯誤訊息。如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html#PostgreSQL.Concepts.General.SSL.Requiring)。 | DevOps 工程師、遷移工程師、DBA | 

### 安裝 SSL 延伸模組
<a name="install-ssl-extension"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 SSL 延伸模組。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html)。 | DevOps 工程師、遷移工程師、DBA | 

### 為 SSL 設定 PostgreSQL 用戶端
<a name="configure-your-postgresql-client-for-ssl"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 SSL 的用戶端。 | 透過使用 SSL，您可以啟動 PostgreSQL 伺服器，並支援使用 TLS 通訊協定的加密連線。伺服器會接聽相同 TCP 連接埠上的標準和 SSL 連線，並與任何連線用戶端協商是否使用 SSL。根據預設，這是用戶端選項。如果您使用的是 psql 用戶端：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)對於其他 PostgreSQL 用戶端：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)檢閱這些用戶端的下列頁面：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html) | DevOps 工程師、遷移工程師、DBA | 

## 疑難排解
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 無法下載 SSL 憑證。 | 請檢查您的網站連線，然後重試下載憑證到您的本機電腦。 | 

## 相關資源
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-resources"></a>
+ [Amazon RDS for PostgreSQL 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)
+ [搭配 PostgreSQL 資料庫執行個體使用 SSL ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html)(Amazon RDS 文件）
+ [使用 SSL 保護 TCP/IP 連線](https://www.postgresql.org/docs/9.1/ssl-tcp.html) (PostgreSQL 文件）
+ [使用 SSL](https://jdbc.postgresql.org/documentation/ssl/) (JDBC 文件）