

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

# Amazon Cognito 如何與 IAM 搭配運作
<a name="security_iam_service-with-iam"></a>

在您使用 IAM 管理 Amazon Cognito 的存取權之前，請先了解有哪些 IAM 功能可搭配 Amazon Cognito 使用。






**您可以搭配 Amazon Cognito 使用的 IAM 功能**  

| IAM 功能 | Amazon Cognito 支援 | 
| --- | --- | 
|  [身分型政策](#security_iam_service-with-iam-id-based-policies)  |   是  | 
|  [資源型政策](#security_iam_service-with-iam-resource-based-policies)  |   否   | 
|  [政策動作](#security_iam_service-with-iam-id-based-policies-actions)  |   是  | 
|  [政策資源](#security_iam_service-with-iam-id-based-policies-resources)  |   是  | 
|  [政策條件索引鍵](#security_iam_service-with-iam-id-based-policies-conditionkeys)  |   是  | 
|  [ACL](#security_iam_service-with-iam-acls)  |   否   | 
|  [ABAC(政策中的標籤)](#security_iam_service-with-iam-tags)  |   部分  | 
|  [臨時憑證](#security_iam_service-with-iam-roles-tempcreds)  |   是  | 
|  [主體許可](#security_iam_service-with-iam-principal-permissions)  |   否   | 
|  [服務角色](#security_iam_service-with-iam-roles-service)  |   是  | 
|  [服務連結角色](#security_iam_service-with-iam-roles-service-linked)  |   是  | 

若要全面了解 Amazon Cognito 和其他 AWS 服務如何與大多數 IAM 功能搭配使用，請參閱《IAM *使用者指南*》中的[AWS 與 IAM 搭配使用的 服務](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html)。

## Amazon Cognito 身分型政策
<a name="security_iam_service-with-iam-id-based-policies"></a>

**支援身分型政策：**是

身分型政策是可以附加到身分 (例如 IAM 使用者、使用者群組或角色) 的 JSON 許可政策文件。這些政策可控制身分在何種條件下能對哪些資源執行哪些動作。如需了解如何建立身分型政策，請參閱《*IAM 使用者指南*》中的[透過客戶管理政策定義自訂 IAM 許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)。

使用 IAM 身分型政策，您可以指定允許或拒絕的動作和資源，以及在何種條件下允許或拒絕動作。如要了解您在 JSON 政策中使用的所有元素，請參閱《*IAM 使用者指南*》中的 [IAM JSON 政策元素參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html)。

### Amazon Cognito 的身分型政策範例
<a name="security_iam_service-with-iam-id-based-policies-examples"></a>



若要檢視 Amazon Cognito 身分型政策的範例，請參閱 [Amazon Cognito 的身分型政策範例](security_iam_id-based-policy-examples.md)。

## Amazon Cognito 內的資源型政策
<a name="security_iam_service-with-iam-resource-based-policies"></a>

**支援資源型政策：**否 

資源型政策是附加到資源的 JSON 政策文件。資源型政策的最常見範例是 IAM *角色信任政策*和 Amazon S3 *儲存貯體政策*。在支援資源型政策的服務中，服務管理員可以使用它們來控制對特定資源的存取權限。對於附加政策的資源，政策會定義指定的主體可以對該資源執行的動作以及在何種條件下執行的動作。您必須在資源型政策中[指定主體](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html)。委託人可以包含帳戶、使用者、角色、聯合身分使用者或 AWS 服務。

如需啟用跨帳戶存取權，您可以在其他帳戶內指定所有帳戶或 IAM 實體作為資源型政策的主體。如需詳細資訊，請參閱《*IAM 使用者指南*》中的 [IAM 中的快帳戶資源存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies-cross-account-resource-access.html)。

## Amazon Cognito 的政策動作
<a name="security_iam_service-with-iam-id-based-policies-actions"></a>

**支援政策動作：**是

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

JSON 政策的 `Action` 元素描述您可以用來允許或拒絕政策中存取的動作。政策會使用動作來授予執行相關聯動作的許可。



若要查看 Amazon Cognito 動作的清單，請參閱《*服務授權參考*》中的 [Amazon Cognito 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html#amazoncognitoidentity-actions-as-permissions)。

Amazon Cognito 中的政策動作會在動作前使用以下字首：

```
cognito-identity
```

若要在單一陳述式中指定多個動作，請用逗號分隔。

```
"Action": [
      "cognito-identity:action1",
      "cognito-identity:action2"
         ]
```

### 簽章與未簽章的 API
<a name="security_amazon-cognito-signed-versus-unsigned-apis"></a>

當您使用 AWS 登入資料簽署 Amazon Cognito API 請求時，您可以在 AWS Identity and Access Management (IAM) 政策中限制這些請求。您必須使用 AWS 憑證簽署的 API 請求，包括使用 `AdminInitiateAuth` 進行的伺服器端登入，以及建立、檢視或修改您的 Amazon Cognito 資源的動作，例如 `UpdateUserPool`。如需已簽署 API 請求的詳細資訊，請參閱[簽署 AWS API 請求](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html)。

由於 Amazon Cognito 是您要向大眾提供之應用程式的消費者身分產品，因此您可以存取下列未簽署的 API。您的應用程式會為您的使用者和潛在使用者發出這些 API 請求。某些 API 不需要事先授權，例如啟動新的驗證工作階段的 `InitiateAuth`。有些 API 會使用存取字符或工作階段金鑰進行授權，例如，`VerifySoftwareToken` 為具有現有已驗證工作階段的使用者完成 MFA 設定。未簽署、授權的 Amazon Cognito 使用者集區 API 支援請求語法中的 `Session` 或 `AccessToken` 參數，如 [Amazon Cognito API 參考](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/Welcome.html)中所示。未簽署的 Amazon Cognito 身分 API 支援顯示於 [Amazon Cognito 聯合身分 API 參考](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/Welcome.html)的 `IdentityId` 參數。

如需 Amazon Cognito 使用者集區 API 操作的授權模型和角色的詳細資訊，請參閱 [依授權模型分組的 API 操作清單](authentication-flows-public-server-side.md#user-pool-apis-auth-unauth)。

**Amazon Cognito 身分池 API 操作**
+ `GetId`
+ `GetOpenIdToken`
+ `GetCredentialsForIdentity`
+ `UnlinkIdentity`

**Amazon Cognito 使用者集區 API 操作**
+ `AssociateSoftwareToken`
+ `ChangePassword`
+ `ConfirmDevice`
+ `ConfirmForgotPassword`
+ `ConfirmSignUp`
+ `DeleteUser`
+ `DeleteUserAttributes`
+ `ForgetDevice`
+ `ForgotPassword`
+ `GetDevice`
+ `GetUser`
+ `GetUserAttributeVerificationCode`
+ `GlobalSignOut`
+ `InitiateAuth`
+ `ListDevices`
+ `ResendConfirmationCode`
+ `RespondToAuthChallenge`
+ `RevokeToken`
+ `SetUserMFAPreference`
+ `SetUserSettings`
+ `SignUp`
+ `UpdateAuthEventFeedback`
+ `UpdateDeviceStatus`
+ `UpdateUserAttributes`
+ `VerifySoftwareToken`
+ `VerifyUserAttribute`





若要檢視 Amazon Cognito 身分型政策的範例，請參閱 [Amazon Cognito 的身分型政策範例](security_iam_id-based-policy-examples.md)。

## Amazon Cognito 的政策資源
<a name="security_iam_service-with-iam-id-based-policies-resources"></a>

**支援政策資源：**是

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

`Resource` JSON 政策元素可指定要套用動作的物件。最佳實務是使用其 [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html) 來指定資源。若動作不支援資源層級許可，使用萬用字元 (\$1) 表示該陳述式適用於所有資源。

```
"Resource": "*"
```

### Amazon 資源名稱 (ARN)
<a name="security_amazon-cognito-amazon-resource-names"></a>

**適用於 Amazon Cognito 聯合身分的 ARN**

在 Amazon Cognito 使用者集區 (聯合身分) 中，您可以利用 Amazon Resource Name (ARN) 格式，限制 IAM 使用者對特定身分集區的存取，如下列範例所示。如需 ARN 的詳細資訊，請參閱 [IAM 識別符](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html)。

```
arn:aws:cognito-identity:REGION:ACCOUNT_ID:identitypool/IDENTITY_POOL_ID
```

**Amazon Cognito Sync 的 ARN**

在 Amazon Cognito Sync 中，客戶也可以依身分集區 ID、身分 ID 和資料集名稱來限制存取。

若為在身分集區上操作的 API，身分集區 ARN 格式與 Amazon Cognito 聯合身分相同，但服務名稱為 `cognito-sync`，而不是 `cognito-identity`：

```
arn:aws:cognito-sync:REGION:ACCOUNT_ID:identitypool/IDENTITY_POOL_ID
```

若為在單一身分上操作的 API，例如 `RegisterDevice`，您可以利用下列 ARN 格式來參照個別身分：

```
arn:aws:cognito-sync:REGION:ACCOUNT_ID:identitypool/IDENTITY_POOL_ID/identity/IDENTITY_ID
```

若為在資料集上操作的 API，例如 `UpdateRecords`和 `ListRecords`，您可以利用下列 ARN 格式來參照個別資料集：

```
arn:aws:cognito-sync:REGION:ACCOUNT_ID:identitypool/IDENTITY_POOL_ID/identity/IDENTITY_ID/dataset/DATASET_NAME
```

**適用於 Amazon Cognito 使用者集區的 ARN**

針對 Amazon Cognito 您的使用者集區，您可以利用下列 ARN 格式來限制使用者對特定身分集區的存取：

```
arn:aws:cognito-idp:REGION:ACCOUNT_ID:userpool/USER_POOL_ID
```

若要查看 Amazon Cognito 資源類型及其 ARN 的清單，請參閱《*服務授權參考*》中的 [Amazon Cognito 定義的資源](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html#amazoncognitoidentity-resources-for-iam-policies)。若要了解您可以使用哪些動作指定每個資源的 ARN，請參閱 [Amazon Cognito 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html#amazoncognitoidentity-actions-as-permissions)。





若要檢視 Amazon Cognito 身分型政策的範例，請參閱 [Amazon Cognito 的身分型政策範例](security_iam_id-based-policy-examples.md)。

## Amazon Cognito 政策條件金鑰
<a name="security_iam_service-with-iam-id-based-policies-conditionkeys"></a>

**支援服務特定政策條件金鑰：**是

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

`Condition` 元素會根據定義的條件，指定陳述式的執行時機。您可以建立使用[條件運算子](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html)的條件運算式 (例如等於或小於)，來比對政策中的條件和請求中的值。若要查看所有 AWS 全域條件索引鍵，請參閱《*IAM 使用者指南*》中的[AWS 全域條件內容索引鍵](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)。

若要查看 Amazon Cognito 條件金鑰的清單，請參閱《*服務授權參考*》中的 [Amazon Cognito 的條件金鑰](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html#amazoncognitoidentity-policy-keys)。若要了解您可以搭配哪些動作和資源使用條件金鑰，請參閱 [Amazon Cognito 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html#amazoncognitoidentity-actions-as-permissions)。

若要檢視 Amazon Cognito 身分型政策的範例，請參閱 [Amazon Cognito 的身分型政策範例](security_iam_id-based-policy-examples.md)。

## Amazon Cognito 中的存取控制清單 (ACL)
<a name="security_iam_service-with-iam-acls"></a>

**支援 ACL：**否 

存取控制清單 (ACL) 可控制哪些主體 (帳戶成員、使用者或角色) 擁有存取某資源的許可。ACL 類似於資源型政策，但它們不使用 JSON 政策文件格式。

## 使用 Amazon Cognito 的屬性型存取控制 (ABAC)
<a name="security_iam_service-with-iam-tags"></a>

**支援 ABAC (政策中的標籤)：**部分

屬性型存取控制 (ABAC) 是一種授權策略，根據稱為標籤的屬性定義許可權。您可以將標籤連接至 IAM 實體 AWS 和資源，然後設計 ABAC 政策，以便在委託人的標籤符合資源上的標籤時允許操作。

如需根據標籤控制存取，請使用 `aws:ResourceTag/key-name`、`aws:RequestTag/key-name` 或 `aws:TagKeys` 條件索引鍵，在政策的[條件元素](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)中，提供標籤資訊。

如果服務支援每個資源類型的全部三個條件金鑰，則對該服務而言，值為 **Yes**。如果服務僅支援某些資源類型的全部三個條件金鑰，則值為 **Partial**。

如需 ABAC 的詳細資訊，請參閱《*IAM 使用者指南*》中的[使用 ABAC 授權定義許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)。如要查看含有設定 ABAC 步驟的教學課程，請參閱《*IAM 使用者指南*》中的[使用屬性型存取控制 (ABAC)](https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html)。

## 將暫時憑證與 Amazon Cognito 搭配使用
<a name="security_iam_service-with-iam-roles-tempcreds"></a>

**支援臨時憑證：**是

臨時登入資料提供對 AWS 資源的短期存取，並在您使用聯合或切換角色時自動建立。 AWS 建議您動態產生臨時登入資料，而不是使用長期存取金鑰。如需詳細資訊，請參閱《*IAM 使用者指南*》中的 [IAM 中的臨時安全憑證](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html)與[可與 IAM 搭配運作的AWS 服務](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html)。

## Amazon Cognito 的跨服務主體許可
<a name="security_iam_service-with-iam-principal-permissions"></a>

**支援轉寄存取工作階段 (FAS)**：否 

 轉送存取工作階段 (FAS) 使用呼叫 的委託人許可 AWS 服務，並結合 AWS 服務 請求向下游服務提出請求。如需提出 FAS 請求時的政策詳細資訊，請參閱[轉發存取工作階段](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_forward_access_sessions.html)。

## Amazon Cognito 的服務角色
<a name="security_iam_service-with-iam-roles-service"></a>

**支援服務角色：**是

 服務角色是服務擔任的 [IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)，可代您執行動作。IAM 管理員可以從 IAM 內建立、修改和刪除服務角色。如需詳細資訊，請參閱《*IAM 使用者指南*》中的[建立角色以委派許可給 AWS 服務](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)。

如需 Amazon Cognito 服務角色的詳細資訊，請參閱 [啟用推播同步](identity-pools.md#enable-push-synchronization) 和 [實作推送同步](push-sync.md)。

**警告**  
變更服務角色的許可有可能會中斷 Amazon Cognito 功能。只有在 Amazon Cognito 提供指引時，才能編輯服務角色。

## Amazon Cognito 的服務連結角色
<a name="security_iam_service-with-iam-roles-service-linked"></a>

**支援服務連結角色：**是

 服務連結角色是連結至 的一種服務角色 AWS 服務。服務可以擔任代表您執行動作的角色。服務連結角色會出現在您的 中 AWS 帳戶 ，並由服務擁有。IAM 管理員可以檢視，但不能編輯服務連結角色的許可。

如需建立或管理 Amazon Cognito 服務連結角色的詳細資訊，請參閱 [使用 Amazon Cognito 的服務連結角色](using-service-linked-roles.md)。