

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

# 偵測具有即將到期 CA 憑證的 Amazon RDS 和 Aurora 資料庫執行個體
<a name="detect-rds-instances-expiring-certificates"></a>

*Stephen DiCato 和 Eugene Shifer，Amazon Web Services*

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

作為安全最佳實務，建議您加密應用程式伺服器和關聯式資料庫之間傳輸中的資料。您可以使用 SSL 或 TLS 來加密與資料庫 （資料庫） 執行個體或叢集的連線。這些通訊協定有助於在應用程式和資料庫之間提供機密性、完整性和真實性。資料庫使用由憑證[授權單位 (CA) 發行的伺服器憑證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#UsingWithRDS.SSL.RegionCertificateAuthorities)，並用於執行伺服器身分驗證。SSL 或 TLS 透過驗證憑證的數位簽章並確保憑證未過期，來驗證憑證的真偽。

在 中 AWS 管理主控台，[Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 和 [Amazon 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)，也可以將它部署到整個 AWS 組織中做為[堆疊集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html)。

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

**先決條件**
+ 作用中 AWS 帳戶
+ 如果您要部署到單一 AWS 帳戶：
  + 請確定您具有建立 CloudFormation 堆疊的[許可](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html)。
  + 在目標帳戶中[啟用](https://docs.aws.amazon.com/config/latest/developerguide/getting-started.html) AWS Config 。
  + （選用） 在目標帳戶中[啟用](https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-settingup.html#securityhub-manual-setup-overview) AWS Security Hub CSPM 。
+ 如果您要部署到 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) AWS Organizations 整合啟用 Security Hub CSPM。
  + 在您部署此解決方案的帳戶中[啟用](https://docs.aws.amazon.com/config/latest/developerguide/getting-started.html) AWS Config 。
  + 將 指定 AWS 帳戶 為 AWS Config 和 Security Hub CSPM 的委派管理員。

**限制**
+ 如果您要部署到未啟用 Security Hub CSPM 的個別帳戶，您可以使用 AWS Config 來評估問題清單。
+ 如果您要部署到沒有 AWS Config 和 Security Hub CSPM 委派管理員的組織，您必須登入個別成員帳戶才能檢視問題清單。
+ 如果您使用 AWS Control Tower 來管理組織中的帳戶，請使用 Customizations for(CfCT) 在此模式中部署 IaC。 [AWS Control Tower CfCT](https://docs.aws.amazon.com/controltower/latest/userguide/cfct-overview.html) 使用 CloudFormation AWS Control Tower 主控台將從護欄建立組態偏離，並要求您重新註冊組織單位 (OUs) 或受管帳戶。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<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_tw/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. 您可以根據帳戶的組態 AWS Config，在 Security Hub CSPM 或 中檢視問題清單。

**部署到 AWS 組織**

下圖顯示透過 AWS Organizations 和 管理的多個帳戶的憑證過期評估 AWS Control Tower。您可以透過 CfCT 部署 CloudFormation 範本。評估結果集中在委派管理員帳戶中的 Security Hub CSPM 中。圖表中描述的 AWS CodePipeline 工作流程顯示 CfCT 部署期間發生的背景步驟。

![將提供的 CloudFormation 範本部署到 AWS Organization 中的多個帳戶。](http://docs.aws.amazon.com/zh_tw/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 Simple Storage Service (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 帳戶 及其設定方式。它可協助您識別資源彼此之間的關係，以及其組態如何隨著時間而改變。An AWS Config [rule](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/) 是一種一般用途的電腦程式設計語言。

**程式碼儲存庫**

此模式的程式碼可在具有即將到期 CA 憑證儲存庫的 GitHub Detect Amazon RDS 執行個體中使用。 [https://github.com/aws-samples/config-rds-ca-expiry](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 上使用 建立初始基礎的指導 AWS](https://aws.amazon.com/solutions/guidance/establishing-an-initial-foundation-using-control-tower-on-aws/) (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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定您的部署策略。 | 檢閱解決方案和程式碼，以判斷如何將其部署到您的 AWS 環境。決定您要部署到單一帳戶或 AWS 組織。 | 應用程式擁有者，一般 AWS | 
| 複製儲存庫。 | 輸入下列命令以複製[具有即將過期 CA 憑證儲存庫的 Detect 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_tw/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html) | 應用程式開發人員、應用程式擁有者 | 

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


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 CloudFormation 範本。 | 將 CloudFormation 範本部署到您的 AWS 環境。執行以下任意一項：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢視 AWS Config 規則調查結果。 | 在 Security Hub CSPM 中，執行下列動作以檢視個別問題清單：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html)<br />在 Security Hub CSPM 中，執行下列動作以檢視依 分組的問題清單總數 AWS 帳戶：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/detect-rds-instances-expiring-certificates.html)<br />在 中 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 文件）