

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Amazon RDS 中为 PostgreSQL 数据库实例启用加密连接
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds"></a>

*Rohit Kapoor，Amazon Web Services*

## Summary
<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 连接。默认情况下，适用于 PostgreSQL 的 Amazon RDS SSL/TLS 使用并期望所有客户端都使用加密进行连接。 SSL/TLS Amazon RDS for PostgreSQL 支持 TLS 版本 1.1 和 1.2。

此模式介绍了如何为 Amazon RDS for PostgreSQL 数据库实例启用加密连接。您可使用相同进程为 Amazon Aurora PostgreSQL-Compatible Edition 启用加密连接。

## 先决条件和限制
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-prereqs"></a>
+ 一个有效的 Amazon Web Services account
+ [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)

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

![\[在 Amazon RDS 中为 PostgreSQL 数据库实例启用加密连接\]](http://docs.aws.amazon.com/zh_cn/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](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) 增强您的通知效果 GuardDuty。
+ 定期监控政策遵守情况。

## 操作说明
<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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 将受信任的证书加载到您的计算机。 | 要将证书添加到计算机的受信任的根证书颁发机构存储中，请按照以下步骤操作。（这些指令以 Windows Server 为例。）[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html) | DevOps 工程师、迁移工程师、DBA | 

### 强制执行 SSL 连接
<a name="force-ssl-connections"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建参数组和设置 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_cn/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_cn/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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 安装 SSL 扩展。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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 | 

### 为您的 PostgreSQL 客户端配置 SSL
<a name="configure-your-postgresql-client-for-ssl"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 为 SSL 配置客户端。 | 通过使用 SSL，您可启动支持使用 TLS 协议的加密连接的 PostgreSQL 服务器。服务器在同一 TCP 端口上侦听标准连接和 SSL 连接，并与任何连接客户端协商是否使用 SSL。默认情况下，这是一个客户端选项。如果您使用 psql 客户端：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/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_cn/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)
+ [将 SSL 与 PostgreSQL 数据库实例结合使用](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 文档）