

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

# Amazon Cognito 的資料保護
<a name="data-protection"></a>

AWS[共同責任模型](https://aws.amazon.com/compliance/shared-responsibility-model/)適用於 Amazon Cognito (Amazon Cognito) 中的資料保護。如此模型所述， AWS負責保護執行所有 AWS雲端的 全球基礎設施。您負責維護在此基礎設施上託管內容的控制權。此內容包含您使用之AWS服務的安全組態和管理任務。如需有關資料隱私權的詳細資訊，請參閱[資料隱私權常見問答集](https://aws.amazon.com/compliance/data-privacy-faq)。

基於資料保護目的，我們建議您保護AWS帳戶登入資料，並使用 AWS Identity and Access Management(IAM) 設定個別使用者帳戶。如此一來，每個使用者都只會獲得授予完成其任務所必須的許可。我們也建議您採用下列方式保護資料：
+ 每個帳戶均要使用多重要素驗證 (MFA)。
+ 使用 SSL/TLS 與 AWS資源通訊。
+ 使用 設定 API 和使用者活動記錄AWS CloudTrail。
+ 使用AWS加密解決方案，以及 服務中的所有AWS預設安全控制。
+ 使用進階的受管安全服務 (例如 Amazon Macie)，協助探索和保護儲存在 Simple Storage Service (Amazon Simple Storage Service (Amazon S3)) 的個人資料。

我們強烈建議您絕對不要將客戶帳戶號碼等敏感的識別資訊，放在自由格式的欄位中，例如**Name (名稱)** 欄位。這包括當您使用 Amazon Cognito 或使用主控台AWS CLI、API 或 AWSSDKs的其他AWS 服務時。您在 Amazon Cognito 或其他服務中輸入的任何資料都可能選入診斷日誌中。當您提供外部伺服器的 URL 時，請勿在驗證您對該伺服器請求的 URL 中包含憑證資訊。

## 資料加密
<a name="data-encryption"></a>

資料加密通常分為兩類：靜態加密和傳輸中加密。

### 靜態加密
<a name="data-encryption-at-rest"></a>

Amazon Cognito 使用者集區和身分集區中的資料會根據業界標準進行靜態加密。
+ Amazon Cognito 會使用[AWS擁有的金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-owned-cmk)加密身分集區中的客戶資料。您無法變更此行為。
+ *根據預設*，Amazon Cognito 也會使用AWS擁有的金鑰加密使用者集區中的客戶資料。您也可以將使用者集區設定為使用客戶[受管金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk)來加密客戶的資訊。

**AWS擁有的金鑰**  
Amazon Cognito 會使用 AWS擁有的 KMS 金鑰加密使用者集區或身分集區中的資料。此類型的金鑰不會顯示在 中AWS KMS。

**客戶自管金鑰**  
Amazon Cognito 會使用客戶受管金鑰加密使用者集區中的資料。您擁有客戶受管金鑰政策、輪換和排程刪除的管理。  
某些使用者集區可能無法使用客戶受管金鑰進行加密。新建立的使用者集區一律提供這種形式的加密。

**使用客戶受管金鑰進行使用者集區加密的須知事項**

1. 使用者集區中的所有客戶資料都會靜態加密，即使您未採取任何動作來設定加密設定。

1. Amazon Cognito 僅支援與使用者集區AWS 區域相同的對稱 KMS 金鑰，以進行靜態使用者集區加密。您無法使用[非對稱金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html)設定使用者集區靜態加密。您可以使用單一區域金鑰和與使用者集區位於相同區域的[多區域金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/multi-region-keys-overview.html)來設定靜態加密。

1. 您只能使用 KMS 金鑰 ARN 而非別名來設定使用者集區加密。

**PII 加密**  
Amazon Cognito 支援使用[可搜尋加密](https://docs.aws.amazon.com/database-encryption-sdk/latest/devguide/searchable-encryption.html)的使用者屬性搜尋中個人身分識別資訊 (PII) 的機密性、完整性和可用性。這些雜湊型訊息驗證碼 (HMAC) 函數針對使用者集區資料集進行效能最佳化，在純文字和使用者屬性的加密值之間進行映射。Amazon Cognito 會使用加密使用者集區的 KMS 金鑰來計算 HMAC 值。此保護適用於下列屬性：
+ `sub`
+ `email`
+ `phone_number`
+ `given_name`
+ `family_name`
+ `name`
+ `username`
+ `preferred_username`
+ `cognito:user_status`

下列程序會在您的使用者集區中設定靜態加密。如需委派存取 AWS 服務之 KMS 金鑰政策的詳細資訊，例如 Amazon Cognito，請參閱[金鑰政策中的 Amazon Cognito 許可](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-services.html)。

------
#### [ Set customer managed key policy ]

若要使用客戶受管金鑰，您的金鑰必須信任 Amazon Cognito 服務主體，才能對金鑰執行加密和解密操作。設定 KMS [金鑰的金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)，如下列範例所示。撰寫此政策的 IAM 主體必須具有 KMS 金鑰的寫入存取權，並具有 `kms:PutKeyPolicy` 許可。

```
{
    "Id": "cognito-cmk-policy",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Allow Amazon Cognito service access",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "cognito-idp.amazonaws.com",
                    "identitystore.amazonaws.com"
                ]
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKeyWithoutPlainText"
            ],
            "Resource": "*",
            "Condition": {
                "ArnEquals": {
                    "aws:SourceArn": [
                        "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                    ]
                },
                "StringEquals": {
                    "aws:SourceAccount": [
                        "{{111122223333}}"
                    ]
                },
                "StringLike": {
                    "kms:EncryptionContext:aws:cognito-idp:userpool-arn": "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                }
            }
        },
        {
            "Sid": "Allow Amazon Cognito service DescribeKey access",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "cognito-idp.amazonaws.com",
                    "identitystore.amazonaws.com"
                ]
            },
            "Action": [
                "kms:DescribeKey"
            ],
            "Resource": "*",
            "Condition": {
                "ArnEquals": {
                    "aws:SourceArn": [
                        "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                    ]
                },
                "StringEquals": {
                    "aws:SourceAccount": [
                        "{{111122223333}}"
                    ]
                }
            }
        },
        {
            "Sid": "Allow access through Amazon Cognito for all principals in account that are authorized to use Amazon Cognito",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "kms:DescribeKey"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "kms:ViaService": [
                        "cognito-idp.{{us-east-1}}.amazonaws.com"
                    ]
                }
            }
        },
        {
            "Sid": "Allow access through Amazon Cognito for all principals in account that are authorized to use Amazon Cognito",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKeyWithoutPlainText"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "kms:ViaService": [
                        "cognito-idp.{{us-east-1}}.amazonaws.com"
                    ]
                },
                "StringLike": {
                    "kms:EncryptionContext:aws:cognito-idp:userpool-arn": "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                }
            }
        },
        {
            "Sid": "Allow administrators to manage the key",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:{{aws}}:iam::{{111122223333}}:root"
            },
            "Action": "kms:*",
            "Resource": "*"
        }
    ]
}
```

------
#### [ Set customer managed key policy with permissions for encryption of exported logs ]

當您已設定[日誌匯出](exporting-quotas-and-usage.md)時，請將此政策套用至您的 KMS 金鑰。此政策允許 Amazon Cognito 在匯出日誌時加密日誌，而中繼服務會在將日誌寫入 CloudWatch Logs 日誌群組之前解密日誌。設定 KMS [金鑰的金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)，如下列範例所示。撰寫此政策的 IAM 主體必須具有 KMS 金鑰的寫入存取權，並具有 `kms:PutKeyPolicy` 許可。

```
{
    "Id": "cognito-cmk-policy",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Allow Amazon Cognito service access",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "cognito-idp.amazonaws.com",
                    "identitystore.amazonaws.com"
                ]
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKeyWithoutPlainText"
            ],
            "Resource": "*",
            "Condition": {
                "ArnEquals": {
                    "aws:SourceArn": [
                        "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                    ]
                },
                "StringEquals": {
                    "aws:SourceAccount": [
                        "{{111122223333}}"
                    ]
                },
                "StringLike": {
                    "kms:EncryptionContext:aws:cognito-idp:userpool-arn": "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                }
            }
        },
        {
            "Sid": "Allow Amazon Cognito service DescribeKey access",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "cognito-idp.amazonaws.com",
                    "identitystore.amazonaws.com"
                ]
            },
            "Action": [
                "kms:DescribeKey"
            ],
            "Resource": "*",
            "Condition": {
                "ArnEquals": {
                    "aws:SourceArn": [
                        "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                    ]
                },
                "StringEquals": {
                    "aws:SourceAccount": [
                        "{{111122223333}}"
                    ]
                }
            }
        },
        {
            "Sid": "Allow access through Amazon Cognito for all principals in account that are authorized to use Amazon Cognito",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "kms:DescribeKey"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "kms:ViaService": [
                        "cognito-idp.{{us-east-1}}.amazonaws.com"
                    ]
                }
            }
        },
        {
            "Sid": "Allow access through Amazon Cognito for all principals in account that are authorized to use Amazon Cognito",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKeyWithoutPlainText"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "kms:ViaService": [
                        "cognito-idp.{{us-east-1}}.amazonaws.com"
                    ]
                },
                "StringLike": {
                    "kms:EncryptionContext:aws:cognito-idp:userpool-arn": "arn:{{aws}}:cognito-idp:{{us-east-1}}:{{111122223333}}:userpool/{{us-east-1_EXAMPLE}}"
                }
            }
        },
        {
            "Sid": "Allow Amazon Cognito service log delivery access",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "cognito-idp.amazonaws.com"
                ]
            },
            "Action": [
                "kms:GenerateDataKey",
                "kms:Encrypt"
            ],
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "kms:EncryptionContext:SourceArn": "arn:{{aws}}:logs:{{us-east-1}}:{{111122223333}}:*"
                }
            }
        },
        {
            "Sid": "Allow IngestionHub service log delivery access",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "delivery.logs.amazonaws.com"
                ]
            },
            "Action": [
                "kms:GenerateDataKey",
                "kms:Decrypt"
            ],
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "kms:EncryptionContext:SourceArn": "arn:{{aws}}:logs:{{us-east-1}}:{{111122223333}}:*"
                }
            }
        },
        {
            "Sid": "Allow administrators to manage the key",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:{{aws}}:iam::{{111122223333}}:root"
            },
            "Action": "kms:*",
            "Resource": "*"
        }
    ]
}
```

------
#### [ Configure encryption at rest in the console ]

**在使用者集區中設定靜態加密**

1. 前往 [Amazon Cognito 主控台](https://console.aws.amazon.com/cognito/home)。您可能會收到提示，要求您輸入 AWS 憑證。

1. 選擇 **User Pools** (使用者集區)。

1. 從清單中選擇現有的使用者集區，或[建立使用者集區](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-as-user-directory.html)。

1. 選擇**設定**功能表，然後導覽至**使用者集區安全**索引標籤。尋找**靜態加密**，然後選取**編輯**。

1. 在**金鑰類型**下，選取**AWS擁有的金鑰**或**客戶受管金鑰**。

   1. 如果您選擇**AWS了擁有的金鑰**，則不需要額外的組態。

   1. 如果您選取**客戶受管金鑰**，請在**客戶受管金鑰 ARN 中輸入 KMS 金鑰的 ARN**。您也可以選擇**建立AWS KMS金鑰**，並在AWS KMS主控台中開啟新視窗以建立新的 KMS 金鑰。

1. 選擇**儲存變更**。

------
#### [ Configure encryption at rest with the API ]

在 [CreateUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#CognitoUserPools-CreateUserPool-request-KeyConfiguration) 或 [UpdateUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPool.html#CognitoUserPools-UpdateUserPool-request-KeyConfiguration) API 請求中設定金鑰組態。下列部分範例請求內文會將使用者集區設定為使用提供的客戶受管金鑰。如需完整的範例請求，請參閱[範例](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#API_CreateUserPool_Examples)。

```
"KeyConfiguration": { 
   "KeyType": "CUSTOMER_MANAGED_KEY",
   "KmsKeyArn": "arn:aws:kms:{{us-east-1}}:{{111122223333}}:key/{{a1b2c3d4-5678-90ab-cdef-EXAMPLE22222}}"
},
```

下列部分範例請求內文會將使用者集區設定為使用 AWS擁有的金鑰。

```
"KeyConfiguration": { 
   "KeyType": "AWS_OWNED_KEY"
},
```

如果您的 [DescribeUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_DescribeUserPool.html) 回應不包含 `KeyConfiguration` 參數，您的使用者集區會設定為使用 AWS擁有的金鑰加密靜態資料。

------

## 傳輸中加密
<a name="data-encryption-in-transit"></a>

Amazon Cognito 是受管服務，受到AWS全球網路安全的保護。如需AWS安全服務以及如何AWS保護基礎設施的資訊，請參閱[AWS雲端安全](https://aws.amazon.com/security/)。若要使用基礎設施安全的最佳實務設計您的AWS環境，請參閱*安全支柱 AWSWell-Architected Framework* 中的[基礎設施保護](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/infrastructure-protection.html)。

您可以使用AWS發佈的 API 呼叫，透過網路存取 Amazon Cognito。使用者端必須支援下列專案：
+ Transport Layer Security (TLS)。我們需要 TLS 1.2 並建議使用 TLS 1.3。
+ 具備完美轉送私密(PFS)的密碼套件，例如 DHE (Ephemeral Diffie-Hellman)或 ECDHE (Elliptic Curve Ephemeral Diffie-Hellman)。現代系統(如 Java 7 和更新版本)大多會支援這些模式。

Amazon Cognito 使用者集區和身分集區具有經過 IAM 驗證、未驗證和權杖授權的 API 操作。有些是管理操作的*控制平面*類型操作，例如設定使用者集區網域，有些則是用於身分驗證*的資料平面*類型操作。如需詳細資訊，請參閱[依授權模型分組的 API 操作清單](authentication-flows-public-server-side.md#user-pool-apis-auth-unauth)。Amazon Cognito API 操作的所有類別都會共用使用者集區、`cognito-identity`身分集區和服務端點的命名空間`cognito-idp`。 [AWS服務端點](https://docs.aws.amazon.com/general/latest/gr/rande.html)需要傳輸中加密，[最低 TLS 版本為 1.2。](https://aws.amazon.com/blogs/security/tls-1-2-required-for-aws-endpoints/)

Amazon Cognito 使用者集區託管[受管登入](cognito-user-pools-managed-login.md)，以及 Web 網域上從服務擁有的 Amazon CloudFront 分佈提供的傳統託管 UI。Amazon Cognito 會管理這些分佈上傳輸中加密的設定。如需受管登入加密設定的詳細資訊，請參閱 受管登入章節中的 [TLS 版本](cognito-user-pools-managed-login.md#managed-login-things-to-know-TLSversion)。