

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

# 检测具有即将过期的 CA 证书的 Amazon RDS 和 Aurora 数据库实例
<a name="detect-rds-instances-expiring-certificates"></a>

*Stephen DiCato 和 Eugene Shifer，Amazon Web Ser*

## Summary
<a name="detect-rds-instances-expiring-certificates-summary"></a>

作为安全最佳实践，建议您对应用程序服务器和关系数据库之间的传输中数据进行加密。您可以使用 SSL 或 TLS 加密与数据库（DB）实例或集群的连接。这些协议有助于确保应用程序和数据库之间的机密性、完整性和真实性。数据库使用服务器证书，而该证书由[证书颁发机构（CA）](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#UsingWithRDS.SSL.RegionCertificateAuthorities)颁发，可用于执行服务器身份验证。SSL 或 TLS 通过验证证书的数字签名并确保其未过期来验证证书的真实性。

在中 AWS 管理控制台，[亚马逊关系数据库服务 (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 和[亚马逊 Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 提供有关需要更新证书的数据库实例的通知。但是，要查看这些通知，您必须登录每个通知 AWS 账户 并导航到每个通知中的服务控制台 AWS 区域。如果您需要评估许多作为组织管理的证书的有效性 AWS 账户 ，则此任务会变得更加复杂[AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)。

通过配置此模式中提供的基础设施即代码 (IaC)，您可以检测您 AWS 账户 或 AWS 组织中所有 Amazon RDS 和 Aurora 数据库实例的 CA 证书即将过期。该[AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)模板提供了 AWS Config 规则、 AWS Lambda 函数和必要的权限。您可以将其作为[堆栈](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacks.html)部署到单个账户中，也可以将其作为堆[栈集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html)部署到整个 AWS 组织中。

## 先决条件和限制
<a name="detect-rds-instances-expiring-certificates-prereqs"></a>

**先决条件**
+ 活跃的 AWS 账户
+ 如果您要部署到单个 AWS 账户：
  + 确保您拥有创建 CloudFormation 堆栈的[权限](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html)。
  +  AWS Config 在目标账户中@@ [启用](https://docs.aws.amazon.com/config/latest/developerguide/getting-started.html)。
  + （可选） AWS Security Hub CSPM 在目标账户中[启用](https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-settingup.html#securityhub-manual-setup-overview)。
+ 如果您要部署到 AWS 组织中：
  + 确保您拥有创建 CloudFormation 堆栈集的[权限](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html)。
  + [通过集成启用](https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-settingup.html#securityhub-orgs-setup-overview) Security Hub CSPM。 AWS Organizations 
  +  AWS Config 在部署此解决方案的账户中@@ [启用](https://docs.aws.amazon.com/config/latest/developerguide/getting-started.html)。
  + 指定一个作 AWS 账户 为 Security Hub CSP AWS Config M 的委托管理员。

**限制**
+ 如果您要部署到未启用 Security Hub CSPM 的个人账户，则可以使用 AWS Config 来评估结果。
+ 如果您要部署到的组织没有为 Security Hub CSPM 委派管理员，则必须登录个人成员账户才能查看调查结果。 AWS Config 
+ 如果您使用 AWS Control Tower 管理和治理组织中的账户，请使用[定制 AWS Control Tower (cfc](https://docs.aws.amazon.com/controltower/latest/userguide/cfct-overview.html) T) 按此模式部署 IaC。使用 CloudFormation 控制台会导致配置偏离 AWS Control Tower 防护栏，并要求您重新注册组织单位 (OUs) 或托管账户。
+ 有些 AWS 服务 并非全部可用 AWS 区域。有关区域可用性，请参阅[服务端点和配额](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)页面，然后选择相应服务的链接。

## 架构
<a name="detect-rds-instances-expiring-certificates-architecture"></a>

**部署到个人中 AWS 账户**

以下架构图显示了 AWS 资源在单个架构中的部署 AWS 账户。它是通过直接通过 CloudFormation 控制台使用 CloudFormation 模板来实现的。如果启用了 Security Hub CSPM，则可以在 AWS Config 或 Security Hub CSPM 中查看结果。如果未启用 Security Hub CSPM，则只能在控制台中 AWS Config 查看结果。

![\[在单个账户中部署所提供的 CloudFormation 模板。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/d34fe1f1-6764-4485-b7a7-04e5861f1e9b/images/0b07133a-d4f8-4d87-8d00-2b5e2c453ece.png)


图中显示以下步骤：

1. 你创建了一个 CloudFormation 堆栈。这将部署一个 Lambda 函数和 AWS Config 一条规则。规则和函数都设置了在中发布资源评估 AWS Config 和日志所需的 AWS Identity and Access Management (IAM) 权限。

1. 该 AWS Config 规则在[侦探评估模式下](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config-rules.html#aws-config-rules-evaluation-modes)运行，每 24 小时运行一次。

1. Security Hub CSPM 会收到所有调查结果 AWS Config 。

1. 您可以在 Security Hub CSPM 中或中查看调查结果 AWS Config，具体取决于账户的配置。

**部署到 AWS 组织中**

下图显示了通过 AWS Organizations 和管理的多个账户对证书到期情况的评估 AWS Control Tower。您可以通过 cfCT 部署 CloudFormation 模板。评估结果集中在委派管理员账户的 Security Hub CSPM 中。图中描述 AWS CodePipeline 的工作流程显示了 cfCT 部署期间发生的背景步骤。

![\[将提供的 CloudFormation 模板部署到 AWS 组织中的多个账户。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/d34fe1f1-6764-4485-b7a7-04e5861f1e9b/images/8d870cbb-54cf-43ec-96f2-00730e0134af.png)


图中显示以下步骤：

1. 根据 cfCT 的配置，您可以在管理账户中将 iaC 推送到 AWS CodeCommit 存储库，或者将 iaC 的压缩 (ZIP) 文件上传到亚马逊简单存储服务 (Amazon S3) 存储桶。

1. cfcT 管道解压缩文件，运行 [cfn-nag](https://github.com/stelligent/cfn_nag) (GitHub) 检查，然后将其部署为堆栈集。 CloudFormation 

1. 根据 cfcT 清单文件中指定的配置，将堆栈 CloudFormation StackSets 部署到单个账户或指定账户。 OUs这将在目标账户中部署一个 Lambda 函数和 AWS Config 一条规则。规则和函数均使用在中发布资源评估 AWS Config 和日志所需的 IAM 权限进行设置。

1. 该 AWS Config 规则在[侦探评估模式下](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config-rules.html#aws-config-rules-evaluation-modes)运行，每 24 小时运行一次。

1. AWS Config 将所有发现结果转发给 Security Hub CSPM。

1. Security Hub CSPM 调查结果汇总到委派的管理员账户中。

1. 你可以使用委派管理员账户在 Security Hub CSPM 中查看调查结果。

## 工具
<a name="detect-rds-instances-expiring-certificates-tools"></a>

**AWS 服务**
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)帮助您设置 AWS 资源，快速一致地配置资源，并在资源的整个生命周期中跨地区对其 AWS 账户 进行管理。
+ [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html)提供了您的资源 AWS 账户 及其配置方式的详细视图。它可以帮助您确定资源之间的相互关系，以及它们的配置如何随时间变化。 AWS Config [规则](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config.html)定义了您理想的资源配置设置，并 AWS Config 可以评估您的 AWS 资源是否符合规则中的条件。
+ [AWS Control Tower](https://docs.aws.amazon.com/controltower/latest/userguide/what-is-control-tower.html)按照规范性最佳实践，帮助您设置和管理 AWS 多账户环境。[AWS Control Tower (cfcT) 的自定义](https://docs.aws.amazon.com/controltower/latest/userguide/cfct-overview.html)可帮助您自定义 AWS Control Tower 着陆区并与 AWS 最佳实践保持一致。使用 CloudFormation 模板和服务控制策略（SCPs）实现自定义。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一项计算服务，可帮助您运行代码，无需预调配或管理服务器。它只在需要时运行您的代码，并自动进行扩展，因此您只需为使用的计算时间付费。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)是一项账户管理服务，可帮助您将多个账户整合 AWS 账户 到一个由您创建和集中管理的组织中。
+ [AWS Security Hub CSPM](https://docs.aws.amazon.com/securityhub/latest/userguide/what-is-securityhub.html)提供了您的安全状态的全面视图 AWS。它还可以帮助您根据安全行业标准和最佳实践检查您的 AWS 环境。

**其他工具**
+ [Python](https://www.python.org/) 是通用的计算机编程语言。

**代码存储库**

此模式的代码可在 GitHub [检测 CA 证书即将过期的 Amazon RDS 实例](https://github.com/aws-samples/config-rds-ca-expiry)存储库中找到。

## 最佳实践
<a name="detect-rds-instances-expiring-certificates-best-practices"></a>

建议遵守以下资源中的最佳实践：
+ [组织单位的最佳实践 AWS Organizations](https://aws.amazon.com/blogs/mt/best-practices-for-organizational-units-with-aws-organizations/)（AWS 云运营和迁移博客）
+ [使用 AWS Control Tower on AWS（AWS 解决方案库）建立初始基础的指南](https://aws.amazon.com/solutions/guidance/establishing-an-initial-foundation-using-control-tower-on-aws/)
+ [创建和修改 AWS Control Tower 资源的指南](https://docs.aws.amazon.com/controltower/latest/userguide/getting-started-guidance.html)（AWS Control Tower 文档）
+ [cfCT 部署注意事项](https://docs.aws.amazon.com/controltower/latest/userguide/cfct-considerations.html)（AWS Control Tower 文档）

## 操作说明
<a name="detect-rds-instances-expiring-certificates-epics"></a>

### 查看解决方案和代码
<a name="review-the-solution-and-code"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 确定您的部署策略。 | 查看解决方案和代码，以确定如何将其部署到您的 AWS 环境中。确定您是要部署到单个账户还是 AWS 组织中。 | 应用程序所有者、常规 AWS | 
| 克隆存储库。 | 输入以下命令，以克隆[检测具有即将过期的 CA 证书的 Amazon RDS 实例](https://github.com/aws-samples/config-rds-ca-expiry)存储库。<pre>git clone https://github.com/aws-samples/config-rds-ca-expiry.git</pre> | 应用程序开发人员、应用程序所有者 | 
| 验证 Python 版本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html) | 应用程序开发人员、应用程序所有者 | 

### 部署解决方案
<a name="deploy-the-solution"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 部署 CloudFormation 模板。 | 将 CloudFormation 模板部署到您的 AWS 环境中。请执行以下操作之一：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html) | 应用程序开发人员、AWS 管理员、常规 AWS | 
| 验证部署。 | 在[CloudFormation 控制台](https://console.aws.amazon.com/cloudformation/)中，验证堆栈或堆栈集是否已成功部署。 | AWS 管理员、应用程序所有者 | 

### 查看调查发现
<a name="review-the-findings"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 查看 AWS Config 规则调查结果。 | 在 Security Hub CSPM 中，执行以下操作以查看单个发现结果的列表：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html)在 Security Hub CSPM 中，执行以下操作以查看按以下分组的全部发现结果列表： AWS 账户[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html)在中 AWS Config，要查看调查结果列表，请按照 AWS Config 文档中[查看合规信息和评估结果](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_view-compliance.html#evaluate-config_view-compliance-console)中的说明进行操作。 | AWS 管理员、AWS 系统管理员、云管理员 | 

## 问题排查
<a name="detect-rds-instances-expiring-certificates-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| CloudFormation 创建或删除堆栈集失败 | 部署后 AWS Control Tower ，它会强制执行必要的护栏，并控制 AWS Config 聚合器和规则。这包括防止通过 CloudFormation进行任何直接更改。要正确部署或删除此 CloudFormation 模板（包括所有相关资源），必须使用 cfcT。 | 
| cfcT 无法删除模板 CloudFormation  | 如果即使在清单文件中进行了必要的更改并删除了 CloudFormation 模板文件之后，模板仍然存在，请确认清单文件中是否包含`enable_stack_set_deletion`参数并且该值已设置为`false`。有关更多信息，请参阅 CfCT 文档中的[删除堆栈集](https://docs.aws.amazon.com/controltower/latest/userguide/cfct-delete-stack.html)。 | 

## 相关资源
<a name="detect-rds-instances-expiring-certificates-resources"></a>
+ [使用加密 SSL/TLS 与数据库实例或集群的连接](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html)（Amazon RDS 文档）
+ [AWS Config 自定义规则](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules.html)（AWS Config 文档）