本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将基于身份的策略用于 Amazon CodeBuild
本主题提供了基于身份的策略示例,这些示例演示了账户管理员如何将权限策略附加到IAM身份(即用户、组和角色),从而授予对资源执行操作的权限。 Amazon CodeBuild
重要
我们建议您先阅读介绍性主题,这些主题解释了管理 CodeBuild 资源访问权限的基本概念和选项。有关更多信息,请参阅 管理 Amazon CodeBuild 资源访问权限概述。
主题
以下是一个权限策略示例,仅允许用户在 123456789012
账户的 us-east-2
区域中获取任何以 my
名称开头的构建项目的相关信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetProjects", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
使用 Amazon CodeBuild 控制台所需的权限
使用 Amazon CodeBuild 控制台的用户必须拥有允许该 Amazon 账户描述其他 Amazon 资源的最低权限集。您必须拥有来自以下服务的权限:
-
Amazon CodeBuild
-
Amazon CloudWatch
-
CodeCommit (如果您要将源代码存储在 Amazon CodeCommit 存储库中)
-
亚马逊弹性容器注册表(亚马逊ECR)(如果您使用的构建环境依赖于亚马逊ECR存储库中的 Docker 镜像)
注意
自 2022 年 7 月 26 日起,默认IAM政策已更新。有关更多信息,请参阅 连接 Amazon 弹性容器注册表所需的权限 Amazon CodeBuild。
-
亚马逊弹性容器服务(亚马逊ECS)(如果您使用的构建环境依赖于亚马逊ECR存储库中的 Docker 镜像)
-
Amazon Identity and Access Management (IAM)
-
Amazon Key Management Service (Amazon KMS)
-
Amazon Simple Storage Service (Amazon S3)
如果您创建的IAM策略比所需的最低权限更严格,则控制台将无法按预期运行。
连接 Amazon 弹性容器注册表所需的权限 Amazon CodeBuild
自 2022 年 7 月 26 日 Amazon CodeBuild 起,已更新其亚马逊ECR许可的默认IAM政策。以下权限已从默认策略中删除:
"ecr:PutImage", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload"
对于在 2022 年 7 月 26 日之前创建的 CodeBuild 项目,我们建议您使用以下亚马逊政策更新您的ECR政策:
"Action": [ "ecr:BatchCheckLayerAvailability", "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ]
有关更新您的策略的更多信息,请参阅允许用户与之互动 CodeBuild。
Amazon CodeBuild 控制台连接源提供商所需的权限
Amazon CodeBuild 控制台使用以下API操作连接到源提供商(例如 GitHub 存储库)。
-
codebuild:ListConnectedOAuthAccounts
-
codebuild:ListRepositories
-
codebuild:PersistOAuthToken
-
codebuild:ImportSourceCredentials
您可以使用 Amazon CodeBuild 控制台将源提供程序(例如 GitHub 存储库)与您的构建项目相关联。为此,您必须先将上述API操作添加到与您用于IAM访问 Amazon CodeBuild 控制台的用户相关的访问策略中。
ListConnectedOAuthAccounts
ListRepositories
、和PersistOAuthToken
API操作不打算由您的代码调用。因此,这些API操作不包括在 Amazon CLI 和中 Amazon
SDKs。
Amazon 的托管(预定义)策略 Amazon CodeBuild
Amazon 通过提供由创建和管理的独立IAM策略来解决许多常见用例 Amazon。这些 Amazon 托管策略为常见用例授予必要的权限,因此您可以不必调查需要哪些权限。的托管政策 CodeBuild 还为获得相关政策的用户提供了在其他服务中执行操作的权限IAM, Amazon CodeCommit例如、EC2ECR、Amazon SNS、Amazon、Amazon、Amazon 和 Amazon Ev CloudWatch ents。例如,该AWSCodeBuildAdminAccess
策略是一项管理级别的用户策略,允许拥有此策略的用户创建和管理项目构建 CloudWatch的事件规则,为项目相关事件(名称前缀为SNS的主题arn:aws:codebuild:
)创建和管理通知的 Amazon 主题,以及管理中的项目和报告组。 CodeBuild有关更多信息,请参阅《IAM用户指南》中的Amazon 托管策略。
以下 Amazon 托管策略是特定的,您可以将其附加到账户中的用户 Amazon CodeBuild。
- AWSCodeBuildAdminAccess
-
提供对 CodeBuild 包括管理 CodeBuild 生成项目的权限在内的完全访问权限。
- AWSCodeBuildDeveloperAccess
-
提供对生成项目的访问权限, CodeBuild 但不允许管理生成项目。
- AWSCodeBuildReadOnlyAccess
-
提供对的只读访问权限 CodeBuild。
要访问 CodeBuild 创建的生成输出项目,您还必须附加名为的 Amazon 托管策略AmazonS3ReadOnlyAccess
。
要创建和管理 CodeBuild 服务角色,还必须附加名为的 Amazon 托管策略IAMFullAccess
。
您也可以创建自己的自定义IAM策略,以授予 CodeBuild操作和资源的权限。您可以将这些自定义策略附加到需要这些权限的用户或组。
AWSCodeBuildAdminAccess
该AWSCodeBuildAdminAccess
策略提供对构建项目的完全访问权限 CodeBuild,包括管理 CodeBuild 生成项目的权限。此政策仅适用于管理员级别的用户,以授予他们对您 Amazon 账户中的 CodeBuild 项目、报告组和相关资源的完全控制权,包括删除项目和报告组的权限。
AWSCodeBuildAdminAccess
策略包含以下策略语句:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSServicesAccess",
"Action": [
"codebuild:*",
"codecommit:GetBranch",
"codecommit:GetCommit",
"codecommit:GetRepository",
"codecommit:ListBranches",
"codecommit:ListRepositories",
"cloudwatch:GetMetricStatistics",
"ec2:DescribeVpcs",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ecr:DescribeRepositories",
"ecr:ListImages",
"elasticfilesystem:DescribeFileSystems",
"events:DeleteRule",
"events:DescribeRule",
"events:DisableRule",
"events:EnableRule",
"events:ListTargetsByRule",
"events:ListRuleNamesByTarget",
"events:PutRule",
"events:PutTargets",
"events:RemoveTargets",
"logs:GetLogEvents",
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Sid": "CWLDeleteLogGroupAccess",
"Action": [
"logs:DeleteLogGroup"
],
"Effect": "Allow",
"Resource": "arn:aws:logs:*:*:log-group:/aws/codebuild/*:log-stream:*"
},
{
"Sid": "SSMParameterWriteAccess",
"Effect": "Allow",
"Action": [
"ssm:PutParameter"
],
"Resource": "arn:aws:ssm:*:*:parameter/CodeBuild/*"
},
{
"Sid": "SSMStartSessionAccess",
"Effect": "Allow",
"Action": [
"ssm:StartSession"
],
"Resource": "arn:aws:ecs:*:*:task/*/*"
},
{
"Sid": "CodeStarConnectionsReadWriteAccess",
"Effect": "Allow",
"Action": [
"codestar-connections:CreateConnection",
"codestar-connections:DeleteConnection",
"codestar-connections:UpdateConnectionInstallation",
"codestar-connections:TagResource",
"codestar-connections:UntagResource",
"codestar-connections:ListConnections",
"codestar-connections:ListInstallationTargets",
"codestar-connections:ListTagsForResource",
"codestar-connections:GetConnection",
"codestar-connections:GetIndividualAccessToken",
"codestar-connections:GetInstallationUrl",
"codestar-connections:PassConnection",
"codestar-connections:StartOAuthHandshake",
"codestar-connections:UseConnection"
],
"Resource": [
"arn:aws:codestar-connections:*:*:connection/*",
"arn:aws:codeconnections:*:*:connection/*"
]
},
{
"Sid": "CodeStarNotificationsReadWriteAccess",
"Effect": "Allow",
"Action": [
"codestar-notifications:CreateNotificationRule",
"codestar-notifications:DescribeNotificationRule",
"codestar-notifications:UpdateNotificationRule",
"codestar-notifications:DeleteNotificationRule",
"codestar-notifications:Subscribe",
"codestar-notifications:Unsubscribe"
],
"Resource": "*",
"Condition": {
"StringLike": {
"codestar-notifications:NotificationsForResource": "arn:aws:codebuild:*"
}
}
},
{
"Sid": "CodeStarNotificationsListAccess",
"Effect": "Allow",
"Action": [
"codestar-notifications:ListNotificationRules",
"codestar-notifications:ListEventTypes",
"codestar-notifications:ListTargets",
"codestar-notifications:ListTagsforResource"
],
"Resource": "*"
},
{
"Sid": "CodeStarNotificationsSNSTopicCreateAccess",
"Effect": "Allow",
"Action": [
"sns:CreateTopic",
"sns:SetTopicAttributes"
],
"Resource": "arn:aws:sns:*:*:codestar-notifications*"
},
{
"Sid": "SNSTopicListAccess",
"Effect": "Allow",
"Action": [
"sns:ListTopics",
"sns:GetTopicAttributes"
],
"Resource": "*"
},
{
"Sid": "CodeStarNotificationsChatbotAccess",
"Effect": "Allow",
"Action": [
"chatbot:DescribeSlackChannelConfigurations",
"chatbot:ListMicrosoftTeamsChannelConfigurations"
],
"Resource": "*"
}
]
}
AWSCodeBuildDeveloperAccess
该AWSCodeBuildDeveloperAccess
策略允许访问项目 CodeBuild 和报表组相关资源的所有功能。此政策不允许用户删除 CodeBuild 项目或报告组,或者其他 Amazon 服务(例如 CloudWatch 活动)中的相关资源。建议对大多数用户应用此策略。
AWSCodeBuildDeveloperAccess
策略包含以下策略语句:
{
"Statement": [
{
"Sid": "AWSServicesAccess",
"Action": [
"codebuild:StartBuild",
"codebuild:StopBuild",
"codebuild:StartBuildBatch",
"codebuild:StopBuildBatch",
"codebuild:RetryBuild",
"codebuild:RetryBuildBatch",
"codebuild:BatchGet*",
"codebuild:GetResourcePolicy",
"codebuild:DescribeTestCases",
"codebuild:DescribeCodeCoverages",
"codebuild:List*",
"codecommit:GetBranch",
"codecommit:GetCommit",
"codecommit:GetRepository",
"codecommit:ListBranches",
"cloudwatch:GetMetricStatistics",
"events:DescribeRule",
"events:ListTargetsByRule",
"events:ListRuleNamesByTarget",
"logs:GetLogEvents",
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Sid": "SSMParameterWriteAccess",
"Effect": "Allow",
"Action": [
"ssm:PutParameter"
],
"Resource": "arn:aws:ssm:*:*:parameter/CodeBuild/*"
},
{
"Sid": "SSMStartSessionAccess",
"Effect": "Allow",
"Action": [
"ssm:StartSession"
],
"Resource": "arn:aws:ecs:*:*:task/*/*"
},
{
"Sid": "CodeStarConnectionsUserAccess",
"Effect": "Allow",
"Action": [
"codestar-connections:ListConnections",
"codestar-connections:GetConnection"
],
"Resource": [
"arn:aws:codestar-connections:*:*:connection/*",
"arn:aws:codeconnections:*:*:connection/*"
]
},
{
"Sid": "CodeStarNotificationsReadWriteAccess",
"Effect": "Allow",
"Action": [
"codestar-notifications:CreateNotificationRule",
"codestar-notifications:DescribeNotificationRule",
"codestar-notifications:UpdateNotificationRule",
"codestar-notifications:Subscribe",
"codestar-notifications:Unsubscribe"
],
"Resource": "*",
"Condition": {
"StringLike": {
"codestar-notifications:NotificationsForResource": "arn:aws:codebuild:*"
}
}
},
{
"Sid": "CodeStarNotificationsListAccess",
"Effect": "Allow",
"Action": [
"codestar-notifications:ListNotificationRules",
"codestar-notifications:ListEventTypes",
"codestar-notifications:ListTargets",
"codestar-notifications:ListTagsforResource"
],
"Resource": "*"
},
{
"Sid": "SNSTopicListAccess",
"Effect": "Allow",
"Action": [
"sns:ListTopics",
"sns:GetTopicAttributes"
],
"Resource": "*"
},
{
"Sid": "CodeStarNotificationsChatbotAccess",
"Effect": "Allow",
"Action": [
"chatbot:DescribeSlackChannelConfigurations",
"chatbot:ListMicrosoftTeamsChannelConfigurations"
],
"Resource": "*"
}
],
"Version": "2012-10-17"
}
AWSCodeBuildReadOnlyAccess
该AWSCodeBuildReadOnlyAccess
政策授予对 CodeBuild 其他 Amazon 服务中的相关资源的只读访问权限。将此策略应用于可以查看和运行构建、查看项目和查看报告组但无法对它们作出任何更改的用户。
AWSCodeBuildReadOnlyAccess
策略包含以下策略语句:
{
"Statement": [
{
"Sid": "AWSServicesAccess",
"Action": [
"codebuild:BatchGet*",
"codebuild:GetResourcePolicy",
"codebuild:List*",
"codebuild:DescribeTestCases",
"codebuild:DescribeCodeCoverages",
"codecommit:GetBranch",
"codecommit:GetCommit",
"codecommit:GetRepository",
"cloudwatch:GetMetricStatistics",
"events:DescribeRule",
"events:ListTargetsByRule",
"events:ListRuleNamesByTarget",
"logs:GetLogEvents"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Sid": "CodeStarConnectionsUserAccess",
"Effect": "Allow",
"Action": [
"codestar-connections:ListConnections",
"codestar-connections:GetConnection"
],
"Resource": [
"arn:aws:codestar-connections:*:*:connection/*",
"arn:aws:codeconnections:*:*:connection/*"
]
},
{
"Sid": "CodeStarNotificationsPowerUserAccess",
"Effect": "Allow",
"Action": [
"codestar-notifications:DescribeNotificationRule"
],
"Resource": "*",
"Condition": {
"StringLike": {
"codestar-notifications:NotificationsForResource": "arn:aws:codebuild:*"
}
}
},
{
"Sid": "CodeStarNotificationsListAccess",
"Effect": "Allow",
"Action": [
"codestar-notifications:ListNotificationRules",
"codestar-notifications:ListEventTypes",
"codestar-notifications:ListTargets"
],
"Resource": "*"
}
],
"Version": "2012-10-17"
}
CodeBuild 托管策略和通知
CodeBuild 支持通知,它可以通知用户生成项目的重要更改。的托管策略 CodeBuild 包括通知功能的策略声明。有关更多信息,请参阅什么是通知?。
完全访问托管策略中的通知的相关权限
AWSCodeBuildFullAccess
托管策略包含以下语句,以允许对通知进行完全访问。应用了此托管策略的用户还可以创建和管理通知的 Amazon SNS 主题、为用户订阅和取消订阅主题、列出要选择作为通知规则目标的主题,以及列出为 Slack 配置的 Amazon Chatbot
客户端。
{ "Sid": "CodeStarNotificationsReadWriteAccess", "Effect": "Allow", "Action": [ "codestar-notifications:CreateNotificationRule", "codestar-notifications:DescribeNotificationRule", "codestar-notifications:UpdateNotificationRule", "codestar-notifications:DeleteNotificationRule", "codestar-notifications:Subscribe", "codestar-notifications:Unsubscribe" ], "Resource": "*", "Condition" : { "StringLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:codebuild:*"} } }, { "Sid": "CodeStarNotificationsListAccess", "Effect": "Allow", "Action": [ "codestar-notifications:ListNotificationRules", "codestar-notifications:ListTargets", "codestar-notifications:ListTagsforResource", "codestar-notifications:ListEventTypes" ], "Resource": "*" }, { "Sid": "CodeStarNotificationsSNSTopicCreateAccess", "Effect": "Allow", "Action": [ "sns:CreateTopic", "sns:SetTopicAttributes" ], "Resource": "arn:aws:sns:*:*:codestar-notifications*" }, { "Sid": "SNSTopicListAccess", "Effect": "Allow", "Action": [ "sns:ListTopics" ], "Resource": "*" }, { "Sid": "CodeStarNotificationsChatbotAccess", "Effect": "Allow", "Action": [ "chatbot:DescribeSlackChannelConfigurations", "chatbot:ListMicrosoftTeamsChannelConfigurations" ], "Resource": "*" }
只读托管策略中的通知的相关权限
AWSCodeBuildReadOnlyAccess
托管策略包含以下语句,以允许对通知进行只读访问。应用此托管策略的用户可以查看资源的通知,但无法创建、管理或订阅这些通知。
{ "Sid": "CodeStarNotificationsPowerUserAccess", "Effect": "Allow", "Action": [ "codestar-notifications:DescribeNotificationRule" ], "Resource": "*", "Condition" : { "StringLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:codebuild:*"} } }, { "Sid": "CodeStarNotificationsListAccess", "Effect": "Allow", "Action": [ "codestar-notifications:ListNotificationRules", "codestar-notifications:ListEventTypes", "codestar-notifications:ListTargets" ], "Resource": "*" }
其他托管策略中的通知的相关权限
AWSCodeBuildDeveloperAccess
托管策略包含以下语句,以允许用户创建、编辑和订阅通知。用户无法删除通知规则或管理资源的标签。
{ "Sid": "CodeStarNotificationsReadWriteAccess", "Effect": "Allow", "Action": [ "codestar-notifications:CreateNotificationRule", "codestar-notifications:DescribeNotificationRule", "codestar-notifications:UpdateNotificationRule", "codestar-notifications:Subscribe", "codestar-notifications:Unsubscribe" ], "Resource": "*", "Condition" : { "StringLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:codebuild*"} } }, { "Sid": "CodeStarNotificationsListAccess", "Effect": "Allow", "Action": [ "codestar-notifications:ListNotificationRules", "codestar-notifications:ListTargets", "codestar-notifications:ListTagsforResource", "codestar-notifications:ListEventTypes" ], "Resource": "*" }, { "Sid": "SNSTopicListAccess", "Effect": "Allow", "Action": [ "sns:ListTopics" ], "Resource": "*" }, { "Sid": "CodeStarNotificationsChatbotAccess", "Effect": "Allow", "Action": [ "chatbot:DescribeSlackChannelConfigurations", "chatbot:ListMicrosoftTeamsChannelConfigurations" ], "Resource": "*" }
有关IAM和通知的更多信息,请参阅 Identity and Access Management for AWS CodeStar 通知。
CodeBuild Amazon 托管策略的更新
查看 CodeBuild 自该服务开始跟踪这些更改以来 Amazon 托管策略更新的详细信息。要获得有关此页面变更的自动提醒,请订阅订阅 RSS Feed Amazon CodeBuild 用户指南文档历史记录 。
更改 | 描述 | 日期 |
---|---|---|
|
CodeBuild 在这些政策中添加了支持 Amazon CodeConnections 品牌重塑的资源。
|
2024 年 4 月 18 日 |
|
CodeBuild 使用向这些策略添加了支持其他通知类型的权限 Amazon Chatbot。
|
2023 年 5 月 16 日 |
CodeBuild 已开始跟踪更改 |
CodeBuild 开始跟踪其 Amazon 托管策略的更改。 |
2023 年 5 月 16 日 |
客户管理型策略示例
本节的用户策略示例介绍如何授予执行 Amazon CodeBuild 操作的权限。当您使用、或时 CodeBuild API Amazon SDKs,这些策略会起作用 Amazon CLI。当您使用控制台时,您必须授予特定于控制台的其他权限。有关信息,请参阅使用 Amazon CodeBuild 控制台所需的权限。
您可以使用以下示例IAM策略来限制用户和角色的 CodeBuild 访问权限。
主题
- 允许用户获取有关构建项目的信息
- 允许用户获取有关舰队的信息
- 允许用户获取有关报告组的信息
- 允许用户获取有关报告的信息
- 允许用户创建构建项目
- 允许用户创建舰队
- 允许用户创建报告组
- 允许用户删除舰队
- 允许用户删除报告组
- 允许用户删除报告
- 允许用户删除构建项目
- 允许用户获取构建项目名称的列表
- 允许用户更改有关构建项目的信息
- 允许用户更改舰队
- 允许用户更改报告组
- 允许用户获取有关构建的信息
- 允许用户获取构建IDs项目的构建列表
- 允许用户获取版本列表 IDs
- 允许用户获取舰队列表
- 允许用户获取报告组列表
- 允许用户获取报告列表
- 允许用户获取报告组的报告列表
- 允许用户获取报告的测试用例的列表
- 允许用户开始运行构建
- 允许用户尝试停止构建
- 允许用户尝试删除构建
- 允许用户获取有关由管理的 Docker 镜像的信息 CodeBuild
- 允许用户为舰队服务角色添加权限策略
- 允许 CodeBuild 访问创建VPC网络接口所需的 Amazon 服务
- 使用 deny 语句防止 Amazon CodeBuild 与源提供商断开连接
允许用户获取有关构建项目的信息
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取任何以名称 my
开头的构建项目的信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetProjects", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允许用户获取有关舰队的信息
以下示例政策声明允许用户为账户123456789012
获取有关该us-east-2
地区舰队的信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetFleets", "Resource": "arn:aws:codebuild:us-east-2:123456789012:fleet/*" } ] }
允许用户获取有关报告组的信息
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取有关报告组的信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetReportGroups", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户获取有关报告的信息
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取有关报告的信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetReports", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户创建构建项目
以下示例策略声明允许用户使用任意名称创建构建项目,但只能在账户us-east-2
所在区域中创建构建项目,123456789012
并且只能使用指定的 CodeBuild 服务角色:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:CreateProject", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/*" }, { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::123456789012:role/CodeBuildServiceRole" } ] }
以下示例策略声明允许用户使用任何名称创建构建项目,但只能在账户us-east-2
所在区域中创建构建项目,123456789012
并且只能使用指定的 CodeBuild 服务角色。它还强制用户只能将指定的服务角色与任何其他服务一起使用, Amazon CodeBuild 而不能使用任何其他 Amazon 服务。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:CreateProject", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/*" }, { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::123456789012:role/CodeBuildServiceRole", "Condition": { "StringEquals": {"iam:PassedToService": "codebuild.amazonaws.com"} } } ] }}
允许用户创建舰队
以下示例政策声明允许用户us-east-2
在该地区为账户创建舰队123456789012
:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:CreateFleet", "Resource": "arn:aws:codebuild:us-east-2:123456789012:fleet/*" } ] }
允许用户创建报告组
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中创建报告组:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:CreateReportGroup", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户删除舰队
以下示例政策声明允许用户删除us-east-2
该地区中账户的舰队123456789012
:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:DeleteFleet", "Resource": "arn:aws:codebuild:us-east-2:123456789012:fleet/*" } ] }
允许用户删除报告组
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中删除报告组:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:DeleteReportGroup", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户删除报告
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中删除报告:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:DeleteReport", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户删除构建项目
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中删除任何以名称 my
开头的构建项目:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:DeleteProject", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允许用户获取构建项目名称的列表
以下示例策略语句允许用户获取同一账户的构建项目名称的列表:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListProjects", "Resource": "*" } ] }
允许用户更改有关构建项目的信息
以下示例策略语句仅允许用户在 123456789012
账户的 us-east-2
区域中更改有关使用任何名称的构建项目的信息,并且只能使用指定的 Amazon CodeBuild 服务角色:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:UpdateProject", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/*" }, { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::123456789012:role/CodeBuildServiceRole" } ] }
允许用户更改舰队
以下示例政策声明允许用户为账户更改该us-east-2
地区的舰队123456789012
:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:UpdateFleet", "Resource": "arn:aws:codebuild:us-east-2:123456789012:fleet/*" } ] }
允许用户更改报告组
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中更改报告组:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:UpdateReportGroup", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户获取有关构建的信息
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取名为 my-build-project
和 my-other-build-project
的构建项目的信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetBuilds", "Resource": [ "arn:aws:codebuild:us-east-2:123456789012:project/my-build-project", "arn:aws:codebuild:us-east-2:123456789012:project/my-other-build-project" ] } ] }
允许用户获取构建IDs项目的构建列表
以下示例政策声明允许用户获取该us-east-2
区域IDs中名为my-build-project
和123456789012
的构建项目的构建列表my-other-build-project
:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListBuildsForProject", "Resource": [ "arn:aws:codebuild:us-east-2:123456789012:project/my-build-project", "arn:aws:codebuild:us-east-2:123456789012:project/my-other-build-project" ] } ] }
允许用户获取版本列表 IDs
以下示例政策声明允许用户获取同一个账户的所有版本IDs的列表:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListBuilds", "Resource": "*" } ] }
允许用户获取舰队列表
以下示例政策声明允许用户获取us-east-2
该地区的车队列表,供其账户123456789012
使用:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListFleets", "Resource": "*" } ] }
允许用户获取报告组列表
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取有关报告组的列表:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListReportGroups", "Resource": "*" } ] }
允许用户获取报告列表
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取有关报告的列表:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListReports", "Resource": "*" } ] }
允许用户获取报告组的报告列表
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取报告组的报告列表:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListReportsForReportGroup", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户获取报告的测试用例的列表
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中获取报告的测试用例列表:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:DescribeTestCases", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允许用户开始运行构建
以下示例策略语句允许用户在 123456789012
账户的 us-east-2
区域中运行任何以名称 my
开头的构建项目:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:StartBuild", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允许用户尝试停止构建
以下示例策略语句仅允许用户在 123456789012
账户的 us-east-2
区域中尝试停止任何以名称 my
开头的运行中构建项目:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:StopBuild", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允许用户尝试删除构建
以下示例策略语句仅允许用户在 123456789012
账户的 us-east-2
区域中尝试为任何以名称 my
开头的构建项目删除构建:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchDeleteBuilds", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允许用户获取有关由管理的 Docker 镜像的信息 CodeBuild
以下示例策略声明允许用户获取有关由 CodeBuild管理的所有 Docker 镜像的信息:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListCuratedEnvironmentImages", "Resource": "*" } ] }
允许用户为舰队服务角色添加权限策略
以下示例资源策略声明允许用户为舰队服务角色添加VPC权限策略:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "CodeBuildFleetVpcCreateNI", "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterface" ], "Resource": [ "arn:aws:ec2:
region
:account-id
:subnet/subnet-id-1", "arn:aws:ec2:region
:account-id
:security-group/security-group-id-1", "arn:aws:ec2:region
:account-id
:network-interface/*" ] }, { "Sid": "CodeBuildFleetVpcPermission", "Effect": "Allow", "Action": [ "ec2:DescribeDhcpOptions", "ec2:DescribeNetworkInterfaces", "ec2:DescribeSecurityGroups", "ec2:DescribeSubnets", "ec2:DescribeVpcs", "ec2:ModifyNetworkInterfaceAttribute", "ec2:DeleteNetworkInterface" ], "Resource": "*" }, { "Sid": "CodeBuildFleetVpcNIPermission", "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterfacePermission" ], "Resource": "arn:aws:ec2:region
:account-id
:network-interface/*", "Condition": { "StringEquals": { "ec2:Subnet": [ "arn:aws:ec2:region
:account-id
:subnet/subnet-id-1" ] } } } ] }
以下示例资源策略声明允许用户为队列服务角色添加自定义 Amazon Managed Image (AMI) 权限策略:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "ec2:DescribeImages", "Resource": "*" } ] }
以下示例信任策略声明允许用户为舰队服务角色添加权限策略:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "CodeBuildFleetVPCTrustPolicy", "Effect": "Allow", "Principal": { "Service": "codebuild.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "
account-id
" } } } ] }
允许 CodeBuild 访问创建VPC网络接口所需的 Amazon 服务
以下示例策略声明授予在VPC具有两个子网的中创建网络接口的 Amazon CodeBuild 权限:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterface", "ec2:DescribeDhcpOptions", "ec2:DescribeNetworkInterfaces", "ec2:DeleteNetworkInterface", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups", "ec2:DescribeVpcs" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterfacePermission" ], "Resource": "arn:aws:ec2:
region
:account-id
:network-interface/*", "Condition": { "StringEquals": { "ec2:AuthorizedService": "codebuild.amazonaws.com" }, "ArnEquals": { "ec2:Subnet": [ "arn:aws:ec2:region
:account-id
:subnet/subnet-id-1", "arn:aws:ec2:region
:account-id
:subnet/subnet-id-2" ] } } } ] }
使用 deny 语句防止 Amazon CodeBuild 与源提供商断开连接
以下示例策略语句使用 Deny 语句阻止 Amazon CodeBuild 与源提供商断开连接。它使用 codebuild:DeleteOAuthToken
(codebuild:PersistOAuthToken
和 codebuild:ImportSourceCredentials
的倒数)连接到源提供商。有关更多信息,请参阅 Amazon CodeBuild 控制台连接源提供商所需的权限。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": "codebuild:DeleteOAuthToken", "Resource": "*" } ] }