

终止支持通知：2026 年 10 月 7 日， AWS 将终止对的支持。 AWS Proton 2026 年 10 月 7 日之后，您将无法再访问 AWS Proton 控制台或 AWS Proton 资源。您部署的基础架构将保持不变。有关更多信息，请参阅《[AWS Proton 服务弃用和迁移指南》](https://docs.aws.amazon.com/proton/latest/userguide/proton-end-of-support.html)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# AWS Proton IAM 服务角色策略示例
<a name="security_iam_service-role-policy-examples"></a>

管理员拥有并管理根据环境和服务模板定义 AWS Proton 创建的资源。他们将允许代表他们创建资源的 IAM 服务角色附加 AWS Proton 到自己的账户。管理员为资源提供 IAM 角色和 AWS Key Management Service 密钥，这些资源随后由开发人员在 AWS Proton 环境中作为 AWS Proton 服务 AWS Proton 部署其应用程序时拥有和管理。有关 AWS KMS 和数据加密的更多信息，请参阅[中的数据保护 AWS Proton](data-protection.md)。

服务角色是一个 Amazon Web Services (IAM) 角色， AWS Proton 允许您代表您调用资源。如果指定服务角色， AWS Proton 将使用该角色的凭证。使用服务角色明确指定 AWS Proton 可以执行的操作。

您可以使用 IAM 服务创建服务角色及其权限策略。有关创建服务角色的更多信息，请参阅 *IAM 用户指南*中的[创建角色以向 AWS 服务委派权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)。

## AWS Proton 使用进行置备的服务角色 CloudFormation
<a name="proton-svc-role"></a>

作为平台团队的成员，您可以作为管理员创建一个 AWS Proton 服务角色，并在创建环境 AWS Proton 时将其作为环境的 CloudFormation 服务角色（[CreateEnvironment](https://docs.aws.amazon.com/proton/latest/APIReference/API_CreateEnvironment.html)API 操作的`protonServiceRoleArn`参数）提供给该角色。当环境或其中运行的任何服务实例使用 AWS托管配置时，此角色允许 AWS Proton 您代表您对其他服务进行 API 调用， AWS CloudFormation 并配置基础架构。

我们建议您为 AWS Proton 服务角色使用以下 IAM 角色和信任策略。当您使用 AWS Proton 控制台创建环境并选择创建新角色时，该策略会 AWS Proton 添加到它为您创建的服务角色中。在缩小此策略的权限范围时，请记住如果`Access Denied`出错 AWS Proton 就会失败。

**重要**  
请注意，以下示例中显示的策略为任何可以在您的账户中注册模板的人授予管理员权限。由于我们不知道您将在 AWS Proton 模板中定义哪些资源，因此这些策略具有广泛的权限。我们建议您将权限范围缩小到在您的环境中部署的特定资源。

### AWS Proton 的服务角色策略示例 CloudFormation
<a name="proton-svc-role.details"></a>

`{{123456789012}}`用您的 AWS 账户 身份证替换。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "cloudformation:CancelUpdateStack",
        "cloudformation:ContinueUpdateRollback",
        "cloudformation:CreateChangeSet",
        "cloudformation:CreateStack",
        "cloudformation:DeleteChangeSet",
        "cloudformation:DeleteStack",
        "cloudformation:DescribeChangeSet",
        "cloudformation:DescribeStackDriftDetectionStatus",
        "cloudformation:DescribeStackEvents",
        "cloudformation:DescribeStackResourceDrifts",
        "cloudformation:DescribeStacks",
        "cloudformation:DetectStackResourceDrift",
        "cloudformation:ExecuteChangeSet",
        "cloudformation:ListChangeSets",
        "cloudformation:ListStackResources",
        "cloudformation:UpdateStack"
      ],
      "Resource": "arn:aws:cloudformation:*:{{123456789012}}:stack/AWSProton-*"
    },
    {
      "Effect": "Allow",
      "NotAction": [
        "organizations:*",
        "account:*"
      ],
      "Resource": "*",
      "Condition": {
        "ForAnyValue:StringEquals": {
          "aws:CalledVia": [
            "cloudformation.amazonaws.com"
          ]
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "organizations:DescribeOrganization",
        "account:ListRegions"
      ],
      "Resource": "*",
      "Condition": {
        "ForAnyValue:StringEquals": {
          "aws:CalledVia": [
            "cloudformation.amazonaws.com"
          ]
        }
      }
    }
  ]
}
```

------

### AWS Proton 服务信任政策
<a name="proton-svc-role.trust.details"></a>

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "ServiceTrustRelationshipWithConfusedDeputyPrevention",
    "Effect": "Allow",
    "Principal": {
      "Service": "proton.amazonaws.com"
    },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": {
        "aws:SourceAccount": "{{123456789012}}"
      },
      "ArnLike": {
        "aws:SourceArn": "arn:aws:proton:*:{{123456789012}}:environment/*"
      }
    }
  }
}
```

------

### 缩小范围 AWS-托管配置服务角色策略
<a name="proton-svc-role.scoped-down.details"></a>

以下是限定范围的 AWS Proton 服务角色策略的示例，如果您只需要 AWS Proton 服务来配置 S3 资源，则可以使用该策略。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "cloudformation:CancelUpdateStack",
        "cloudformation:ContinueUpdateRollback",
        "cloudformation:CreateChangeSet",
        "cloudformation:CreateStack",
        "cloudformation:DeleteChangeSet",
        "cloudformation:DeleteStack",
        "cloudformation:DescribeChangeSet",
        "cloudformation:DescribeStackDriftDetectionStatus",
        "cloudformation:DescribeStackEvents",
        "cloudformation:DescribeStackResourceDrifts",
        "cloudformation:DescribeStacks",
        "cloudformation:DetectStackResourceDrift",
        "cloudformation:ExecuteChangeSet",
        "cloudformation:ListChangeSets",
        "cloudformation:ListStackResources",
        "cloudformation:UpdateStack"
      ],
      "Resource": "arn:aws:cloudformation:*:{{123456789012}}:stack/AWSProton-*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:*"
      ],
      "Resource": "*",
      "Condition": {
        "ForAnyValue:StringEquals": {
          "aws:CalledVia": [
            "cloudformation.amazonaws.com"
          ]
        }
      }
    }
  ]
}
```

------

## AWS Proton 用于 CodeBuild 置备的服务角色
<a name="codebuild-proton-svc-role"></a>

作为平台团队的成员，您可以作为管理员创建一个 AWS Proton 服务角色，并在创建环境 AWS Proton 时将其作为环境的 CodeBuild 服务角色（[CreateEnvironment](https://docs.aws.amazon.com/proton/latest/APIReference/API_CreateEnvironment.html)API 操作的`codebuildRoleArn`参数）提供给该角色。当环境或其中运行的任何服务实例使用预配置来配置基础设施时，此角色允许 AWS Proton 您代表您对其他服务进行 API CodeBuild 调用。

当您使用 AWS Proton 控制台创建环境并选择创建新角色时， AWS Proton 会将具有管理员权限的策略添加到它为您创建的服务角色中。在创建自己的角色并缩小权限范围时，请记住，如果出现`Access Denied`错误， AWS Proton 则会失败。

**重要**  
请注意， AWS Proton 附加到它为您创建的角色的策略会向任何可以向您的账户注册模板的人授予管理员权限。由于我们不知道您将在 AWS Proton 模板中定义哪些资源，因此这些策略具有广泛的权限。我们建议您将权限范围缩小到在您的环境中部署的特定资源。

### AWS Proton 的服务角色策略示例 CodeBuild
<a name="codebuild-proton-svc-role.details"></a>

以下示例为提供了 CodeBuild 使用配置资源的权限 AWS Cloud Development Kit (AWS CDK)。

`{{123456789012}}`用您的 AWS 账户 身份证替换。

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

****  

```
 {
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Action": [
        "logs:CreateLogStream",
        "logs:CreateLogGroup",
        "logs:PutLogEvents"
      ],
      "Resource": [
        "arn:aws:logs:{{us-east-1}}:{{123456789012}}:log-group:/aws/codebuild/AWSProton-   Shell-*",
        "arn:aws:logs:{{us-east-1}}:{{123456789012}}:log-group:/aws/codebuild/AWSProton-   Shell-*:*"
      ],
      "Effect": "Allow"
    },
    {
      "Action": "proton:NotifyResourceDeploymentStatusChange",
      "Resource": "arn:aws:proton:{{us-east-1}}:{{123456789012}}:*",
      "Effect": "Allow"
    },
    {
      "Action": "sts:AssumeRole",
      "Resource": [
        "arn:aws:iam::{{123456789012}}:role/cdk-*-deploy-role-*",
        "arn:aws:iam::{{123456789012}}:role/cdk-*-file-publishing-role-*"
      ],
      "Effect": "Allow"
    }
  ]
}
```

------

### AWS Proton CodeBuild 信任政策
<a name="codebuild-proton-svc-role.trust.details"></a>

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "CodeBuildTrustRelationshipWithConfusedDeputyPrevention",
    "Effect": "Allow",
    "Principal": {
      "Service": "codebuild.amazonaws.com"
    },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": {
        "aws:SourceAccount": "{{123456789012}}"
      },
      "ArnLike": {
        "aws:SourceArn": "arn:aws:proton:*:{{123456789012}}:environment/*"
      }
    }
  }
}
```

------

## AWS Proton 管道服务角色
<a name="codepipeline-proton-svc-role"></a>

要配置服务管道， AWS Proton 需要权限才能对其他服务进行 API 调用。所需的服务角色与您在创建环境时提供的服务角色类似。但是，创建管道的角色将在您 AWS 账户中的所有服务之间共享，您可以在控制台中或通过 [UpdateAccountSettings](https://docs.aws.amazon.com/proton/latest/APIReference/API_UpdateAccountSettings.html)API 操作将这些角色作为**账户设置**提供。

当您使用 AWS Proton 控制台更新账户设置并选择为 CloudFormation 或 CodeBuild 服务角色创建新角色时， AWS Proton 添加到控制台为您创建的服务角色的策略与前面章节中描述的策略相同，[AWS托管式预置角色](#proton-svc-role)以及[CodeBuild 置备角色](#codebuild-proton-svc-role)。在缩小此策略的权限范围时，请记住如果`Access Denied`出错 AWS Proton 就会失败。

**重要**  
请注意，前面几节中的示例策略为任何可以在您的账户中注册模板的人授予管理员权限。由于我们不知道您将在 AWS Proton 模板中定义哪些资源，因此这些策略具有广泛的权限。我们建议您将权限范围缩小到在您的管道中部署的特定资源。

## AWS Proton 组件角色
<a name="proton-custom-comp-role"></a>

作为平台团队的成员，您可以作为管理员创建一个 AWS Proton 服务角色，并在创建环境 AWS Proton 时将其作为环境的 CloudFormation 组件角色（[CreateEnvironment](https://docs.aws.amazon.com/proton/latest/APIReference/API_CreateEnvironment.html)API 操作的`componentRoleArn`参数）提供给该角色。该角色缩小了直接定义的组件可以预置的基础设施范围。有关组件的更多信息，请参阅[AWS Proton 组件](ag-components.md)。

以下示例策略支持创建直接定义的组件，该组件预置一个 Amazon Simple Storage Service (Amazon S3) 存储桶和相关的访问策略。

### AWS Proton 组件角色策略示例
<a name="proton-custom-comp-role.details"></a>

`{{123456789012}}`用您的 AWS 账户 身份证替换。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "cloudformation:CancelUpdateStack",
        "cloudformation:CreateChangeSet",
        "cloudformation:DeleteChangeSet",
        "cloudformation:DescribeStacks",
        "cloudformation:ContinueUpdateRollback",
        "cloudformation:DetectStackResourceDrift",
        "cloudformation:DescribeStackResourceDrifts",
        "cloudformation:DescribeStackEvents",
        "cloudformation:CreateStack",
        "cloudformation:DeleteStack",
        "cloudformation:UpdateStack",
        "cloudformation:DescribeChangeSet",
        "cloudformation:ExecuteChangeSet",
        "cloudformation:ListChangeSets",
        "cloudformation:ListStackResources"
      ],
      "Resource": "arn:aws:cloudformation:*:{{123456789012}}:stack/AWSProton-*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:CreateBucket",
        "s3:DeleteBucket",
        "s3:GetBucket*",
        "iam:CreatePolicy",
        "iam:DeletePolicy",
        "iam:GetPolicy",
        "iam:ListPolicyVersions",
        "iam:DeletePolicyVersion"
      ],
      "Resource": "*",
      "Condition": {
        "ForAnyValue:StringEquals": {
          "aws:CalledVia": "cloudformation.amazonaws.com"
        }
      }
    }
  ]
}
```

------

### AWS Proton 组件信任策略
<a name="proton-custom-comp-role.trust.details"></a>

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "ServiceTrustRelationshipWithConfusedDeputyPrevention",
    "Effect": "Allow",
    "Principal": {
      "Service": "proton.amazonaws.com"
    },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": {
        "aws:SourceAccount": "{{123456789012}}"
      },
      "ArnLike": {
        "aws:SourceArn": "arn:aws:proton:*:{{123456789012}}:environment/*"
      }
    }
  }
}
```

------