

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

# 輪換您的 SSL/TLS 憑證
<a name="UsingWithRDS.SSL-certificate-rotation"></a>

Amazon RDS 憑證授權機構憑證 rds-ca-2019 已於 2024 年 8 月到期。如果您使用或計劃使用 Secure Sockets Layer (SSL) 或 Transport Layer Security (TLS) 搭配憑證驗證連線至 RDS 資料庫執行個體或，請考慮使用新的 CA 憑證 rds-ca-rsa2048-g1、rds-ca-rsa4096-g1 或 rds-ca-ecc384-g1。如果您目前未將 SSL/TLS 與憑證驗證搭配使用，則可能仍有過期的 CA 憑證，而且如果您計劃將 SSL/TLS 與憑證驗證搭配使用以連線至 RDS 資料庫，則必須將其更新為新的 CA 憑證。

Amazon RDS 提供新的 CA 憑證做為 AWS 安全最佳實務。如需新憑證和支援 AWS 區域的相關資訊，請參閱 [使用 SSL/TLS 加密與資料庫叢集的連線](UsingWithRDS.SSL.md) 。

若要更新資料庫的 CA 憑證，請使用下列方法：
+  [透過修改資料庫執行個體來更新憑證授權機構憑證](#UsingWithRDS.SSL-certificate-rotation-updating) 
+  [透過套用維護來更新憑證授權機構憑證](#UsingWithRDS.SSL-certificate-rotation-maintenance-update) 

在更新您的資料庫執行個體以使用新的 CA 憑證之前，請確定您已更新連線至 RDS 資料庫的用戶端或應用程式。

## 輪換憑證的考量
<a name="UsingWithRDS.SSL-certificate-rotation-considerations"></a>

在輪換憑證之前，請考量下列情況：
+ Amazon RDS Proxy 和 Aurora Serverless v1 使用來自 AWS Certificate Manager (ACM) 的憑證。如果您使用 RDS Proxy，當您輪換 SSL/TLS 憑證時，不需要更新使用 RDS Proxy 連線的應用程式。如需詳細資訊，請參閱 [搭配 RDS Proxy 使用 TLS/SSL](rds-proxy.howitworks.md#rds-proxy-security.tls)。
+ 如果您使用 Aurora Serverless v1，則不需要下載 Amazon RDS 憑證。如需詳細資訊，請參閱 [搭配 Aurora Serverless v1 使用 TLS/SSL](aurora-serverless.md#aurora-serverless.tls)。
+ 如果您使用的 Go 1.15 版應用程式是搭配在 2020 年 7 月 28 日前建立或更新為 rds-ca-2019 憑證的資料庫執行個體，則您必須再次更新憑證。根據您的引擎，將憑證更新為 rds-ca-rsa2048-g1、rds-ca-rsa4096-g1 或 rds-ca-ecc384-g1。

  使用新的 CA 憑證識別符，將 `modify-db-instance` 命令。您可以使用 `describe-db-engine-versions` 命令，尋找適用於特定資料庫引擎和資料庫引擎版本的 CA。

  如果您是在 2020 年 7 月 28 日之後建立資料庫或更新其憑證，則不需要執行任何動作。如需詳細資訊，請參閱 [Go GitHub 問題編號 39568](https://github.com/golang/go/issues/39568)。

## 透過修改資料庫執行個體來更新憑證授權機構憑證
<a name="UsingWithRDS.SSL-certificate-rotation-updating"></a>

以下範例會將您的 CA 憑證從 *rds-ca-2019* 更新為 *rds-ca-rsa2048-g1*。您可以選擇不同的憑證。如需詳細資訊，請參閱 [憑證授權單位](UsingWithRDS.SSL.md#UsingWithRDS.SSL.RegionCertificateAuthorities)。

更新您的應用程式信任存放區，以減少與更新 CA 憑證相關聯的任何停機時間。如需與 CA 憑證輪換相關聯重新啟動的詳細資訊，請參閱 [自動伺服器憑證輪換](#UsingWithRDS.SSL-certificate-rotation-server-cert-rotation)。

**透過修改資料庫執行個體來更新 CA 憑證**

1. 請遵循 [使用 SSL/TLS 加密與資料庫叢集的連線](UsingWithRDS.SSL.md) 所述，下載新的 SSL/TLS 憑證。

1. 更新您的應用程式，以使用新的 SSL/TLS 憑證。

   更新應用程式 SSL/TLS 憑證的方法取決於您特定的應用程式。與應用程式開發人員合作更新應用程式的 SSL/TLS 憑證。

   如需針對每個資料庫引擎檢查 SSL/TLS 連線和更新應用程式的資訊，請參閱下列主題：
   +  [將應用程式更新為使用新的 TLS 憑證來連線至 Aurora MySQL 資料庫叢集](ssl-certificate-rotation-aurora-mysql.md) 
   +  [將應用程式更新為使用新的 SSL/TLS 憑證來連線至 Aurora PostgreSQL 資料庫叢集](ssl-certificate-rotation-aurora-postgresql.md) 

   關於為 Linux 作業系統更新信任存放區的範例指令碼，請參閱 [將憑證匯入信任存放區的範例指令碼](#UsingWithRDS.SSL-certificate-rotation-sample-script)。
**注意**  
憑證套件同時包含舊 CA 和新 CA 的憑證，讓您可以安全地更新應用程式，並在轉換期間維護連線。如果您使用 AWS Database Migration Service 將資料庫遷移至資料庫叢集，我們建議您使用憑證套件來確保遷移期間的連線。

1. 修改資料庫執行個體或，以將 CA 從 **rds-ca-2019** 變更為 **rds-ca-rsa2048-g1**。若要檢查資料庫是否需要重新啟動才能更新 CA 憑證，請使用 [describe-db-engine-versions](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-engine-versions.html) 命令並查看 `SupportsCertificateRotationWithoutRestart` 旗標。
**注意**  
修改後將 Babelfish 叢集重新開機以更新 CA 憑證。
**重要**  
如果您在憑證到期後發生連線問題，請在主控台中指定 **Apply immediately (立即套用)**，或使用 `--apply-immediately` 來指定 AWS CLI選項。依預設，此操作排定在下一個維護時段執行。  
若要為您的叢集 CA 設定與預測 RDS CA 不同的覆寫，請使用 [modify-certificates](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-certificates.html) CLI 命令。

您可以使用 AWS 管理主控台 或 AWS CLI ，將資料庫執行個體的 CA 憑證從 **rds-ca-2019** 變更為 **rds-ca-rsa2048-g1**。

------
#### [ Console ]

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 在導覽窗格中選擇**資料庫**，然後選擇您要修改的資料庫執行個體。

1. 選擇 **Modify** (修改)。  
![\[修改資料庫執行個體或\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/ssl-rotate-cert-modify-aurora.png)

1. 在**連線**區段中，選擇 **rds-ca-rsa2048-g1**。  
![\[選擇 CA 憑證\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/ssl-rotate-cert-ca-rsa2048-g1.png)

1. 選擇 **Continue (繼續)**，並檢查修改的摘要。

1. 若要立即套用變更，請選擇 **Apply immediately** (立即套用)。

1. 在確認頁面上，檢閱您的變更。如果都正確，請選擇**修改資料庫執行個體**，以儲存您的變更。
**重要**  
排定此操作時，請確定您事先已更新用戶端信任存放區。

   或者，選擇 **Back (上一步)** 以編輯變更，或是選擇 **Cancel (取消)** 以取消變更。

------
#### [ AWS CLI ]

若要使用 AWS CLI 將資料庫執行個體的 CA 從 **rds-ca-2019** 變更為 **rds-ca-rsa2048-g1**，請呼叫 [modify-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html) 或 [modify-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-cluster.html) 命令。指定資料庫執行個體識別符和 `--ca-certificate-identifier` 選項。

使用 `--apply-immediately` 參數以立即套用更新。依預設，此操作排定在下一個維護時段執行。

**重要**  
排定此操作時，請確定您事先已更新用戶端信任存放區。

**Example**  
以下範例會將 CA 憑證設定為 `rds-ca-rsa2048-g1`，藉此修改 `mydbinstance`。  
針對 Linux、macOS 或 Unix：  

```
aws rds modify-db-instance \
    --db-instance-identifier mydbinstance \
    --ca-certificate-identifier rds-ca-rsa2048-g1
```
在 Windows 中：  

```
aws rds modify-db-instance ^
    --db-instance-identifier mydbinstance ^
    --ca-certificate-identifier rds-ca-rsa2048-g1
```
如果您的執行個體需要重新開機，可以使用 [modify-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html) CLI 命令並指定 `--no-certificate-rotation-restart` 選項。

------

## 透過套用維護來更新憑證授權機構憑證
<a name="UsingWithRDS.SSL-certificate-rotation-maintenance-update"></a>

透過套用維護，執行下列步驟來套用 CA 憑證。

------
#### [ Console ]

**透過套用維護來更新 CA 憑證**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 在導覽窗格中，選擇**憑證更新**。  
![\[憑證輪換導覽窗格選項\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/ssl-rotate-cert-certupdate.png)

   **需要更新憑證的資料庫**頁面隨即顯示。  
![\[更新資料庫的 CA 憑證\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/ssl-rotate-cert-update-multiple.png)
**注意**  
此頁面僅顯示目前 的資料庫執行個體 AWS 區域。如果您在多個資料庫中有資料庫 AWS 區域，請檢查每個資料庫的此頁面 AWS 區域 ，以查看具有舊 SSL/TLS 憑證的所有資料庫執行個體。

1. 選擇您要更新的資料庫執行個體。

   您可以選擇**排程**，以排定下一個維護時段的憑證輪換。您可以選擇**立即套用**以立即套用輪換。
**重要**  
如果在憑證到期後發生連線問題，請使用**立即套用**選項。

1. 

   1. 如果您選擇**排程**，系統會提示您確認 CA 憑證輪換。此提示也會指出排定的更新時段。  
![\[確認憑證輪換\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/ssl-rotate-cert-confirm-schedule.png)

   1. 如果您選擇**立即套用**，系統會提示您確認 CA 憑證輪換。  
![\[確認憑證輪換\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/ssl-rotate-cert-confirm-now.png)
**重要**  
在資料庫上排定 CA 憑證輪換之前，請先更新使用 SSL/TLS 的任何用戶端應用程式和要連結伺服器憑證。這些更新專屬於您的資料庫引擎。更新這些用戶端應用程式之後，您可以確認 CA 憑證輪換。

   若要繼續，請選擇核取方塊，然後選擇 **Confirm (確認)**。

1. 針對您要更新的每個資料庫執行個體重複步驟 3 和 4。

------

## 自動伺服器憑證輪換
<a name="UsingWithRDS.SSL-certificate-rotation-server-cert-rotation"></a>

如果您的根 CA 支援自動伺服器憑證輪換，RDS 會自動處理資料庫伺服器憑證的輪換。RDS 會使用相同的根 CA 進行此自動輪換，因此您不需要下載新的 CA 套件。請參閱 [憑證授權單位](UsingWithRDS.SSL.md#UsingWithRDS.SSL.RegionCertificateAuthorities)。

資料庫伺服器憑證的輪換和有效期取決於資料庫引擎：
+ 如果您的資料庫引擎支援在不重新啟動的情況下輪換，則 RDS 會自動輪換資料庫伺服器憑證，而不需要您採取任何動作。RDS 會嘗試在資料庫伺服器憑證有效期過半時，在您偏好的維護時段內輪換您的資料庫伺服器憑證。新的資料庫伺服器憑證有效期為 12 個月。
+ 如果您的資料庫引擎不支援在未重新啟動的情況下輪換，Amazon RDS 會透過 Describe-pending-maintenance-actions API、憑證的一半生命週期，或在過期前至少 3 個月顯示`server-certificate-rotation`待定維護動作。您可以使用 apply-pending-maintenance-action API 來套用輪換。新的資料庫伺服器憑證有效期為 36 個月。

使用 [describe-db-engine-versions](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-engine-versions.html) 命令並檢查 `SupportsCertificateRotationWithoutRestart` 旗標，以確定資料庫引擎版本是否支援在不重新啟動的情況下輪換憑證。如需詳細資訊，請參閱 [設定資料庫的 CA](UsingWithRDS.SSL.md#UsingWithRDS.SSL.RegionCertificateAuthorities.Selection)。

## 將憑證匯入信任存放區的範例指令碼
<a name="UsingWithRDS.SSL-certificate-rotation-sample-script"></a>

以下是範例 Shell 指令碼，會將憑證套件匯入信任存放區。

每個範例 Shell 指令碼都使用 keytool，其是 Java 開發套件 (JDK) 的一部分。如需安裝 JDK 的詳細資訊，請參閱《[JDK 安裝指南](https://docs.oracle.com/en/java/javase/17/install/overview-jdk-installation.html)》。

------
#### [ Linux ]

以下範例 Shell 指令碼將憑證套件匯入 Linux 作業系統上的信任存放區。

```
mydir=tmp/certs
if [ ! -e "${mydir}" ]
then
mkdir -p "${mydir}"
fi truststore=${mydir}/rds-truststore.jks storepassword=changeit

curl -sS "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem"> ${mydir}/global-bundle.pem
awk 'split_after == 1 {n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1}{print > "rds-ca-" n+1 ".pem"}' < ${mydir}/global-bundle.pem

for CERT in rds-ca-*; do alias=$(openssl x509 -noout -text -in $CERT | perl -ne 'next unless /Subject:/; s/.*(CN=|CN = )//; print')
  echo "Importing $alias"
  keytool -import -file ${CERT} -alias "${alias}" -storepass ${storepassword} -keystore ${truststore} -noprompt
  rm $CERT
done

rm ${mydir}/global-bundle.pem

echo "Trust store content is: "

keytool -list -v -keystore "$truststore" -storepass ${storepassword} | grep Alias | cut -d " " -f3- | while read alias 
do expiry=`keytool -list -v -keystore "$truststore" -storepass ${storepassword} -alias "${alias}" | grep Valid | perl -ne 'if(/until: (.*?)\n/) { print "$1\n"; }'`
   echo " Certificate ${alias} expires in '$expiry'" 
done
```

------
#### [ macOS ]

以下是範例 Shell 指令碼，會將憑證套件匯入 macOS 上的信任存放區。

```
mydir=tmp/certs
if [ ! -e "${mydir}" ]
then
mkdir -p "${mydir}"
fi truststore=${mydir}/rds-truststore.jks storepassword=changeit

curl -sS "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem"> ${mydir}/global-bundle.pem
split -p "-----BEGIN CERTIFICATE-----" ${mydir}/global-bundle.pem rds-ca-

for CERT in rds-ca-*; do alias=$(openssl x509 -noout -text -in $CERT | perl -ne 'next unless /Subject:/; s/.*(CN=|CN = )//; print')
  echo "Importing $alias"
  keytool -import -file ${CERT} -alias "${alias}" -storepass ${storepassword} -keystore ${truststore} -noprompt
  rm $CERT
done

rm ${mydir}/global-bundle.pem

echo "Trust store content is: "

keytool -list -v -keystore "$truststore" -storepass ${storepassword} | grep Alias | cut -d " " -f3- | while read alias 
do expiry=`keytool -list -v -keystore "$truststore" -storepass ${storepassword} -alias "${alias}" | grep Valid | perl -ne 'if(/until: (.*?)\n/) { print "$1\n"; }'`
   echo " Certificate ${alias} expires in '$expiry'" 
done
```

------

若要進一步了解將 SSL 與 Amazon RDS 搭配使用的最佳實務，請參閱[與 Amazon RDS for Oracle 成功進行 SSL 連線的最佳實務](https://aws.amazon.com/blogs/database/best-practices-for-successful-ssl-connections-to-amazon-rds-for-oracle/)。