本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用以身分識別為基礎的原則 AWS CodeBuild
本主題提供身分類型政策範例,示範帳戶管理員如何將許可政策連接至 IAM 身分 (即使用者、群組和角色),並藉此授予許可,以對 AWS CodeBuild 資源執行操作。
重要
我們建議您先檢閱介紹性主題,其中說明可用於管理 CodeBuild 資源存取權的基本概念和選項。如需詳細資訊,請參閱 管理資 AWS CodeBuild 源存取權限概觀。
主題
以下顯示的許可政策範例,可讓使用者取得組建專案的相關資訊,僅針對 us-east-2
區域的帳戶 123456789012
中名稱開頭為 my
的組建專案:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchGetProjects", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
使用 AWS CodeBuild 主控台所需的許可
使用 AWS CodeBuild 主控台的使用者必須擁有一組最低權限,以允許使用者描述 AWS 帳號的其他 AWS 資源。您必須具備下列服務的許可:
-
AWS CodeBuild
-
Amazon CloudWatch
-
CodeCommit (如果您將源代碼存儲在存儲 AWS CodeCommit 庫中)
-
Amazon Elastic Container Registry (Amazon ECR)(如果您使用的是依賴 Amazon ECR 存儲庫中的 Docker 映像的構建環境)
注意
自 2022 年 7 月 26 日起,預設的身分與存取權與存取權管理政策已更新。如需詳細資訊,請參閱 連接 AWS CodeBuild 到 Amazon 彈性容器註冊表所需的許可。
-
Amazon Elastic Container Service (Amazon ECS) (如果您使用的是依賴 Amazon ECR 存儲庫中的 Docker 映像的構建環境)
-
AWS Identity and Access Management (IAM)
-
AWS Key Management Service (AWS KMS)
-
Amazon Simple Storage Service (Amazon S3)
如果您建立的 IAM 政策比所需的最低權限更嚴格,則主控台將無法如預期般運作。
連接 AWS CodeBuild 到 Amazon 彈性容器註冊表所需的許可
自 2022 年 7 月 26 日起, AWS CodeBuild 已更新其針對 Amazon ECR 許可的默認 IAM 政策。下列權限已從預設原則中移除:
"ecr:PutImage", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload"
對於在 2022 年 7 月 26 日之前建立的 CodeBuild 專案,我們建議您使用下列 Amazon ECR 政策更新政策:
"Action": [ "ecr:BatchCheckLayerAvailability", "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ]
如需更新政策的詳細資訊,請參閱將 CodeBuild 存取權限新增至 IAM 群組或使用者。
AWS CodeBuild 主控台連線至來源提供者所需的權限
主 AWS CodeBuild 控台使用下列 API 動作連線至來源提供者 (例如 GitHub 儲存庫)。
-
codebuild:ListConnectedOAuthAccounts
-
codebuild:ListRepositories
-
codebuild:PersistOAuthToken
-
codebuild:ImportSourceCredentials
您可以使用 AWS CodeBuild 控制台將源提供程序(例如 GitHub 存儲庫)與構建項目相關聯。若要這麼做,您必須先將上述 API 動作新增至與您用來存取 AWS CodeBuild 主控台的使用者相關聯的 IAM 存取政策。
ListConnectedOAuthAccounts
、ListRepositories
和 PersistOAuthToken
API 動作不是為了供您的程式碼呼叫。因此,這些 API 動作不會包含在 AWS CLI 和 AWS
SDK 中。
AWS 的管理 (預先定義) 策略 AWS CodeBuild
AWS 透過提供由建立和管理的獨立 IAM 政策來解決許多常見使用案例 AWS。這些 AWS 受管理的政策會為常見使用案例授與必要的權限,因此您可以避免調查需要哪些權限。的受管政策 CodeBuild 還提供許可以在其他服務 (例如 IAM、Amazon EC2、Amazon ECR AWS CodeCommit、Amazon ECR、Amazon SNS 和 Amazon CloudWatch 事件) 中執行操作,這些許可對已授予有關政策的使用者負責所需的責任。例如,該AWSCodeBuildAdminAccess
政策是管理層級的使用者政策,允許具有此政策的使用者建立和管理專案組建的 CloudWatch事件規則,以及針對專案相關事件 (名稱前綴為主題的主題arn:aws:codebuild:
) 建立和管理 Amazon SNS 主題,以及管理中的專案和報表群組。 CodeBuild如需詳細資訊,請參閱《IAM 使用者指南》中的 AWS 受管政策。
下列 AWS 受管理的策略 (您可以附加至帳戶中的使用者) 是特定的 AWS CodeBuild。
- AWSCodeBuildAdminAccess
-
提供完整存取權, CodeBuild 包括管理 CodeBuild 組建專案的權限。
- AWSCodeBuildDeveloperAccess
-
提供存取權, CodeBuild 但不允許組建專案管理。
- AWSCodeBuildReadOnlyAccess
-
提供的唯讀存取權 CodeBuild。
若要存取建 CodeBuild 立的組建輸出成品,您也必須附加名為的 AWS 受管理原則AmazonS3ReadOnlyAccess
。
若要建立和管理 CodeBuild 服務角色,您還必須附加名為的 AWS 受管理策略IAMFullAccess
。
您也可以建立自己的自訂 IAM 政策,以允許 CodeBuild 動作與資源的許可。您可以將這些自訂政策連接至需要這些許可的使用者或群組。
AWSCodeBuildAdminAccess
AWSCodeBuildAdminAccess
原則提供對於的完整存取權 CodeBuild,包括管理 CodeBuild 組建專案的權限。只將此原則套用至系統管理層級的使用者,以授與他們完全控制您 AWS 帳戶中的 CodeBuild 專案、報表群組和相關資源,包括刪除專案和報表群組的功能。
AWSCodeBuildAdminAccess
政策包含以下政策陳述式:
{
"Version": "2012-10-17",
"Statement": [
{
"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": "*"
},
{
"Action": [
"logs:DeleteLogGroup"
],
"Effect": "Allow",
"Resource": "arn:aws:logs:*:*:log-group:/aws/codebuild/*:log-stream:*"
},
{
"Effect": "Allow",
"Action": [
"ssm:PutParameter"
],
"Resource": "arn:aws:ssm:*:*:parameter/CodeBuild/*"
},
{
"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/*"
},
{
"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 專案或報告群組,或其他 AWS 服務 (例如 CloudWatch 事件) 中的相關資源。建議將此政策套用到大多數使用者。
AWSCodeBuildDeveloperAccess
政策包含以下政策陳述式:
{
"Statement": [
{
"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": "*"
},
{
"Effect": "Allow",
"Action": [
"ssm:PutParameter"
],
"Resource": "arn:aws:ssm:*:*:parameter/CodeBuild/*"
},
{
"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/*"
},
{
"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
則會授與其他 AWS 服務中相關資源的唯讀存取權限。 CodeBuild 將此政策套用至可檢視和執行組建、檢視專案,以及檢視報告群組,但無法對其進行任何變更的使用者。
AWSCodeBuildReadOnlyAccess
政策包含以下政策陳述式:
{
"Statement": [
{
"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/*"
},
{
"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 設定的用 AWS 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閱AWS CodeStar通知。
CodeBuild AWS 受管理策略的更新
檢視 CodeBuild 自此服務開始追蹤這些變更以來的 AWS 受管理策略更新詳細資料。如需有關此頁面變更的自動警示,請在訂閱 RSS 摘要AWS CodeBuild 使用者指南文件歷史 。
變更 | 描述 | 日期 |
---|---|---|
|
CodeBuild 為這些策略添加了權限,以支持使用的其他通知類型 AWS Chatbot。
|
2023 年 5 月 16 日 |
CodeBuild 開始追蹤變更 |
CodeBuild 開始追蹤其 AWS 受管理策略的變更。 |
2021年5月 16 日 |
客戶受管政策範例
在本節中,您可以找到授予 AWS CodeBuild 動作許可的使用者政策範例。當您使用 CodeBuild API、 AWS SDK 或 AWS CLI時,這些原則會運作。當您使用主控台時,您必須授予其他主控台特定的許可。如需相關資訊,請參閱 使用 AWS CodeBuild 主控台所需的許可。
您可以使用下列 IAM 政策範例來限制使用者和角色的 CodeBuild 存取權限。
主題
- 允許使用者取得建置專案的相關資訊
- 允許使用者取得報告群組的相關資訊
- 允許使用者取得報告的相關資訊
- 允許使用者建立建置專案
- 允許使用者建立報告群組
- 允許使用者刪除報告群組
- 允許使用者刪除報告
- 允許使用者刪除建置專案
- 允許使用者取得建置專案名稱的清單
- 允許使用者變更建置專案的相關資訊
- 允許使用者變更報告群組
- 允許使用者取得建置的相關資訊
- 允許使用者取得建置專案之建置 ID 的清單
- 允許使用者取得建置 ID 的清單
- 允許使用者取得報告群組的清單
- 允許使用者取得報告的清單
- 允許使用者取得報告群組的報告清單
- 允許使用者取得報告的測試案例清單
- 允許使用者開始執行建置
- 允許使用者嘗試停止建置
- 允許使用者嘗試刪除建置
- 允許使用者取得 CodeBuild 管理之 Docker 映像的相關資訊
- 允許 CodeBuild 存取建立虛擬私人 VPC 網路介面所需的 AWS 服務
- 使用 deny 陳述式來防止 AWS CodeBuild 中斷來源提供者的連線
允許使用者取得建置專案的相關資訊
以下顯示的政策陳述式範例,會允許使用者取得組建專案的相關資訊,針對 us-east-2
區域的帳戶 123456789012
中名稱開頭為 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: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
區域] (Region for account),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
Region for) 帳戶中,而123456789012
且只能使用指定的 CodeBuild 服務角色。它還強制使用者只能搭配任何其他服務使用指定的服務角色, AWS CodeBuild 而不能使用任何其他 AWS 服務。
{ "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"} } } ] }}
允許使用者建立報告群組
以下顯示的政策陳述式範例,會允許使用者建立帳戶 123456789012
在 us-east-2
區域中的報告群組:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:CreateReportGroup", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允許使用者刪除報告群組
以下顯示的政策陳述式範例,會允許使用者刪除帳戶 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/*" } ] }
允許使用者刪除建置專案
以下顯示的政策陳述式範例,會允許使用者刪除組建專案,針對 us-east-2
區域的帳戶 123456789012
中名稱開頭為 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": "*" } ] }
允許使用者變更建置專案的相關資訊
以下顯示的政策陳述式範例,會允許使用者變更使用任何名稱組建專案的相關資訊,但只能針對 us-east-2
區域中的帳戶 123456789012
,並只能使用指定的 AWS 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" } ] }
允許使用者變更報告群組
以下顯示的政策陳述式範例,會允許使用者變更帳戶 123456789012
在 us-east-2
區域中的報告群組:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:UpdateReportGroup", "Resource": "arn:aws:codebuild:us-east-2:123456789012:report-group/*" } ] }
允許使用者取得建置的相關資訊
以下顯示的政策陳述式範例,會允許使用者取得組建的相關資訊,針對 us-east-2
區域的帳戶 123456789012
中名稱為 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" ] } ] }
允許使用者取得建置專案之建置 ID 的清單
以下顯示的政策陳述式範例,會允許使用者取得組建 ID 的清單,針對 us-east-2
區域的帳戶 123456789012
中名稱為 my-build-project
和 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" ] } ] }
允許使用者取得建置 ID 的清單
下列政策陳述式的範例,會允許使用者取得相同帳戶之所有組建 ID 的清單:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListBuilds", "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/*" } ] }
允許使用者開始執行建置
以下顯示的政策陳述式範例,會允許使用者執行組建,針對 us-east-2
區域的帳戶 123456789012
中名稱開頭為 my
的組建專案:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:StartBuild", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允許使用者嘗試停止建置
以下顯示的政策陳述式範例,會允許使用者嘗試停止執行中的組建,僅針對 us-east-2
區域的帳戶 123456789012
中名稱開頭為 my
的組建專案:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:StopBuild", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允許使用者嘗試刪除建置
以下顯示的政策陳述式範例,會允許使用者嘗試刪除建置,僅針對 us-east-2
區域的帳戶 123456789012
中名稱開頭為 my
的建置專案:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:BatchDeleteBuilds", "Resource": "arn:aws:codebuild:us-east-2:123456789012:project/my*" } ] }
允許使用者取得 CodeBuild 管理之 Docker 映像的相關資訊
下列政策陳述式的範例,允許使用者取得 CodeBuild 管理之所有 Docker 影像的相關資訊:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListCuratedEnvironmentImages", "Resource": "*" } ] }
允許 CodeBuild 存取建立虛擬私人 VPC 網路介面所需的 AWS 服務
下列範例原則陳述式 AWS CodeBuild 授與在具有兩個子網路的 VPC 中建立網路介面的權限:
{ "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 陳述式來防止 AWS CodeBuild 中斷來源提供者的連線
以下範例政策陳述式會使用拒絕陳述式,以防止 AWS CodeBuild 中斷與來源提供者的連接。它使用 codebuild:DeleteOAuthToken
(與 codebuild:PersistOAuthToken
和 codebuild:ImportSourceCredentials
相反) 與來源供應商連接。如需詳細資訊,請參閱 AWS CodeBuild 主控台連線至來源提供者所需的權限。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": "codebuild:DeleteOAuthToken", "Resource": "*" } ] }