AWS Proton IAM服务角色策略示例 - AWS Proton

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

AWS Proton IAM服务角色策略示例

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

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

您可以使用服务创建服务角色及其权限策略。IAM有关创建服务角色的更多信息,请参阅《IAM用户指南》中的创建角色以向 AWS 服务委派权限

AWS Proton 使用进行置备的服务角色 AWS CloudFormation

作为平台团队的成员,您可以作为管理员创建一个 AWS Proton 服务角色,并在创建环境 AWS Proton 时将其提供给环境的 CloudFormation 服务角色(CreateEnvironmentAPI操作的protonServiceRoleArn参数)。当环境或其中运行的任何服务实例使用 AWS托管配置时,此角色允许 AWS Proton 您代表您API调用其他服务, AWS CloudFormation 并配置基础架构。

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

重要

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

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

{ "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" ] } } } ] }
{ "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 Proton 服务角色策略的示例,如果您只需要 AWS Proton 服务来配置 S3 资源,则可以使用该策略。

{ "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 置备的服务角色

作为平台团队的成员,您可以作为管理员创建一个 AWS Proton 服务角色,并在创建环境 AWS Proton 时将其提供给环境的 CodeBuild 服务角色(CreateEnvironmentAPI操作的codebuildRoleArn参数)。当环境或其中运行的任何服务实例使用预API配置来配置基础设施时,此角色允许 AWS Proton 您代表您 CodeBuild 调用其他服务。

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

重要

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

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

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

{ "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" } ] }
{ "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 管道服务角色

要配置服务管道, AWS Proton 需要API调用其他服务的权限。所需的服务角色与您在创建环境时提供的服务角色类似。但是,创建管道的角色将在您 AWS 账户中的所有服务之间共享,您可以在控制台中或通过UpdateAccountSettingsAPI操作将这些角色作为账户设置提供。

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

重要

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

AWS Proton 组件角色

作为平台团队的成员,您可以作为管理员创建一个 AWS Proton 服务角色,并在创建环境 AWS Proton 时将其作为环境的 CloudFormation 组件角色(CreateEnvironmentAPI操作的componentRoleArn参数)提供给该角色。该角色缩小了直接定义的组件可以预置的基础设施范围。有关组件的更多信息,请参阅AWS Proton 组件

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

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

{ "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" } } } ] }
{ "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/*" } } } }