

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

# 預防跨服務混淆代理人
<a name="cross-service-confused-deputy-prevention"></a>

混淆代理人問題屬於安全性議題，其中沒有執行動作許可的實體可以強制具有更多許可的實體執行該動作。在 中 AWS，跨服務模擬可能會導致混淆代理人問題。在某個服務 (*呼叫服務*) 呼叫另一個服務 (*被呼叫服務*) 時，可能會發生跨服務模擬。可以操縱呼叫服務來使用其許可，以其不應有存取許可的方式對其他客戶的資源採取動作。為了防止這種情況， AWS 提供工具，協助您保護所有 服務的資料，讓 服務主體能夠存取您帳戶中的資源。

我們建議在資源政策中使用 [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn)和 [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceaccount](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceaccount)全域條件內容索引鍵，以限制將另一個服務 CloudFormation 提供給特定資源的許可，例如 CloudFormation 延伸。如果您想要僅允許一個資源與跨服務存取相關聯，則請使用 `aws:SourceArn`。如果您想要允許該帳戶中的任何資源與跨服務使用相關聯，請使用 `aws:SourceAccount`。

確定 的值`aws:SourceArn`是 CloudFormation 存放之資源的 ARN。

防範混淆代理人問題最有效的方法，是使用 `aws:SourceArn` 全域條件內容金鑰，以及資源的完整 ARN。如果不知道資源的完整 ARN，或者如果您指定了多個資源，請使用 `aws:SourceArn` 全域條件內容金鑰，同時使用萬用字元 (`*`) 表示 ARN 的未知部分。例如 `arn:aws:{{cloudformation}}:*:{{123456789012}}:*`。

如果 `aws:SourceArn` 值不包含帳戶 ID，則必須使用這兩個全域條件內容索引鍵來限制許可。

下列範例示範如何在 中使用 `aws:SourceArn`和 `aws:SourceAccount`全域條件內容索引鍵 CloudFormation ，以防止混淆代理人問題。

## 使用 `aws:SourceArn` 和 `aws:SourceAccount` 條件索引鍵的信任政策範例
<a name="cross-service-confused-deputy-prevention-example"></a>

對於登錄服務， CloudFormation 會呼叫 AWS Security Token Service (AWS STS) 以在您的帳戶中擔任服務角色。在 [https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_RegisterType.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_RegisterType.html) 操作中為 `ExecutionRoleArn` 設定此角色，在 [https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_LoggingConfig.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_LoggingConfig.html) 操作中為 `LogRoleArn` 設定。如需詳細資訊，請參閱[為公有擴充功能存取設定具有 IAM 許可和信任政策的執行角色](registry-public.md#registry-public-enable-execution-role)。

此範例角色信任政策使用條件陳述式，將服務角色上的`AssumeRole`功能限制為僅對指定帳戶中指定的 CloudFormation 延伸執行動作。獨立評估 `aws:SourceArn` 和 `aws:SourceAccount` 條件。使用服務角色的任何請求都必須滿足這兩個條件。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "resources.cloudformation.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "{{123456789012}}"
        },
        "ArnLike": {
          "aws:SourceArn": "{{arn:aws:cloudformation:us-east-1:123456789012:type/resource/Organization-Service-Resource}}"
        }
      }
    }
  ]
}
```

------

## 其他資訊
<a name="cross-service-confused-deputy-prevention-additional-information"></a>

如需使用 StackSets 所用服務角色的 `aws:SourceArn` 和 `aws:SourceAccount` 全域條件內容索引鍵的政策範例，請參閱 [設定全域索引鍵以減輕混淆代理人問題](stacksets-prereqs-self-managed.md#confused-deputy-mitigation)。

如需詳細資訊，請參閱《IAM 使用者指南》中的[更新角色信任政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_update-role-trust-policy.html)。**