

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

# 管理秘密和資源政策
<a name="managing-secrets-resource-policies"></a>

當您[設定第三方語音提供者](configure-third-party-speech-providers.md)時，您需要在 Secrets Manager 中建立包含語音提供者 API 金鑰的秘密。建立秘密需要兩個步驟：
+ 建立包含 API 金鑰的秘密。如需說明，請參閱[建立 AWS Secrets Manager 秘密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/create_secret.html)。
+ 設定必要的許可：
  + 將資源型政策連接至秘密。
  + 將資源型政策連接至與秘密相關聯的 KMS 金鑰 （而非 API 金鑰）。KMS 金鑰會保護秘密中的 API 金鑰。

  這些政策允許 Amazon Connect 存取秘密中的 API 金鑰。請注意，您無法使用預設 `aws/secretsmanager` KMS 金鑰；您必須建立新的金鑰或使用現有的客戶受管金鑰。如需 KMS 金鑰如何保護秘密的詳細資訊，請參閱 [Secrets Manager 中的秘密加密和解密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/security-encryption.html)。

請確定秘密的資源型政策包含 `aws:SourceAccount`和`aws:SourceArn`混淆代理人條件 （請參閱[混淆代理人問題](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html))，且 KMS 金鑰的資源型政策包含 `kms:EncryptionContext:SecretARN`條件。這將確保 Amazon Connect 只能在單一特定執行個體的內容中存取您的 API 金鑰秘密，並且只能在該執行個體和特定秘密的內容中存取您的 KMS 金鑰。

## Secrets Manager 秘密的資源型政策範例
<a name="example-resource-policy-secrets-manager"></a>

以下是您可以連接到秘密的資源型政策範例。

```
{
  "Version":"2012-10-17",		 	 	                    
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "connect.amazonaws.com"
        ]
      },
      "Action": "secretsmanager:GetSecretValue",
      "Resource": "*",
      "Condition": {
        "ArnLike": {
          "aws:sourceArn": "///the ARN of your Amazon Connect instance///"
        },
        "StringEquals": {
          "aws:sourceAccount": "///Your account ID///"
        }
      }
    }
  ]
}
```

## 適用於 AWS KMS key的資源型政策範例
<a name="example-resource-policy-kms-keys"></a>

以下是您可以連接到 KMS 金鑰的資源型政策範例。

```
{
  "Version":"2012-10-17",		 	 	                    
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "connect.amazonaws.com"
        ]
      },
      "Action": "kms:Decrypt",
      "Resource": "*",
      "Condition": {
        "ArnLike": {
          "aws:sourceArn": "///the ARN of your Amazon Connect instance///"
        },
        "StringEquals": {
          "aws:sourceAccount": "///Your account ID///",
          "kms:EncryptionContext:SecretARN": "///the ARN of your secrets manager secret///"
        }
      }
    }
  ]
}
```

## 將資源型政策連接至 Secrets Manager 秘密
<a name="attaching-resource-policy-secrets-manager"></a>

若要將資源型政策連接至您的秘密，請前往 中的 Secrets Manager 主控台 AWS 管理主控台，導覽至您的秘密，選擇**編輯許可**或**資源許可**，然後直接在頁面上新增或修改資源政策，使其看起來與[範例](#example-resource-policy-secrets-manager)類似。您也可以透過 AWS CLI`put-resource-policy`命令連接資源政策，或使用 [PutResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_PutResourcePolicy.html) API 操作以程式設計方式連接資源政策。

## 將資源型政策連接至您的 KMS 金鑰
<a name="attaching-resource-policy-kms-key"></a>

若要將資源型政策連接至您的 KMS 金鑰，請前往 內的 AWS Key Management Service 主控台 AWS 管理主控台，導覽至您的 KMS 金鑰並編輯您的金鑰政策，看起來像[範例](#example-resource-policy-kms-keys)。您也可以透過 AWS CLI`put-key-policy`命令更新金鑰，或使用 [PutKeyPolicy](https://docs.aws.amazon.com/kms/latest/APIReference/API_PutKeyPolicy.html) API 操作以程式設計方式更新金鑰。

## 輪換 API 金鑰
<a name="rotating-api-keys"></a>

我們建議至少每 90 天輪換 API 金鑰，以將入侵風險降至最低，並針對緊急狀況維持良好的金鑰輪換程序。

若要輪換 API 金鑰，您必須輪換其中包含的秘密。如需如何[輪換秘密的詳細資訊，請參閱《Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets.html) *使用者指南》中的輪換 Secrets Manager* 秘密。當您輪換 API 金鑰時，建議您先等待上一個金鑰的使用量降至零，再撤銷舊的 API 金鑰，以確保持續的請求不會受到影響。