でのアイデンティティベースのポリシーの使用 AWS CodeBuild - AWS CodeBuild

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

でのアイデンティティベースのポリシーの使用 AWS CodeBuild

このトピックでは、アカウント管理者が IAM ID (ユーザー、グループ、ロール) にアクセス権限ポリシーをアタッチし、それによって 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 日に、デフォルトの IAM ポリシーが更新されました。詳細については、「が Amazon Elastic Container Registry に接続 AWS CodeBuild するために必要なアクセス許可」を参照してください。

  • 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 ポリシーを作成している場合、コンソールは意図したとおりには機能しません。

が Amazon Elastic Container Registry に接続 AWS CodeBuild するために必要なアクセス許可

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" ]

ポリシーの更新の詳細については、「IAM グループまたはユーザーに CodeBuild アクセス許可を追加する」を参照してください。

AWS CodeBuild コンソールがソースプロバイダーに接続するために必要なアクセス許可

AWS CodeBuild コンソールは、次の API アクションを使用してソースプロバイダー (リポジトリなど) GitHub に接続します。

  • codebuild:ListConnectedOAuthAccounts

  • codebuild:ListRepositories

  • codebuild:PersistOAuthToken

  • codebuild:ImportSourceCredentials

AWS CodeBuild コンソールを使用して、ソースプロバイダー (リポジトリなど) GitHub をビルドプロジェクトに関連付けることができます。これを行うには、まず、 AWS CodeBuild コンソールへのアクセスに使用するユーザーに関連付けられた IAM アクセスポリシーに前述の API アクションを追加する必要があります。

ListConnectedOAuthAccountsListRepositories、および PersistOAuthToken の API アクションは、コードで呼び出すことを想定していません。したがって、これらの API アクションは AWS CLI および AWS SDKsには含まれていません。

AWS の マネージド (事前定義) ポリシー AWS CodeBuild

AWS は、 が作成および管理するスタンドアロン IAM ポリシーを提供することで、多くの一般的ユースケースに対応します AWS。これらの AWS 管理ポリシーは、一般的なユースケースに必要なアクセス許可を付与するため、どのアクセス許可が必要かを調査する必要はありません。の マネージドポリシーは、問題のポリシーが付与されたユーザーの責任に必要な IAM、 AWS CodeCommit Amazon EC2、Amazon ECR、Amazon SNS、Amazon CloudWatch Events などの他のサービスでオペレーションを実行するアクセス許可 CodeBuild も提供します。例えば、 AWSCodeBuildAdminAccess ポリシーは、このポリシーを持つユーザーが、プロジェクト関連イベントに関する通知 (名前にプレフィックス が付いているトピックarn:aws:codebuild:) のプロジェクトビルドおよび Amazon SNS トピックのイベントルールを作成および管理 CloudWatchしたり、 でプロジェクトおよびレポートグループを管理したりできるようにする管理レベルのユーザーポリシーです 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 ビルドプロジェクトを管理するアクセス許可を含む、 へのフルアクセスを提供します。このポリシーは、管理レベルのユーザーにのみ適用し、 CodeBuild プロジェクトやレポートグループを削除する機能など、 AWS アカウント内のプロジェクト、レポートグループ、関連リソースを完全に制御できるようにします。

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 プロジェクトやレポートグループ、または CloudWatch イベントなどの他の AWS サービスの関連リソースを削除することはできません。ほとんどのユーザーにこのポリシーを適用することをお勧めします。

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 と通知の詳細については、「AWS CodeStar Notifications の Identity and Access Management」を参照してください。

CodeBuild AWS 管理ポリシーの更新

このサービスがこれらの変更の追跡を開始 CodeBuild してからの の AWS マネージドポリシーの更新に関する詳細を表示します。このページの変更に関する自動通知については、AWS CodeBuild ユーザーガイドのドキュメント履歴 の RSS フィードを購読してください。

変更 説明 日付

AWSCodeBuildAdminAccessAWSCodeBuildDeveloperAccess – 既存のポリシーに対する更新

CodeBuild は、 を使用して追加の通知タイプをサポートするアクセス許可をこれらのポリシーに追加しました AWS Chatbot。

AWSCodeBuildAdminAccess および AWSCodeBuildDeveloperAccess ポリシーが変更され、アクセス許可 chatbot:ListMicrosoftTeamsChannelConfigurations が追加されました。

2023 年 5 月 16 日

CodeBuild が変更の追跡を開始

CodeBuild が AWS マネージドポリシーの変更の追跡を開始しました。

2021 年 5 月 16 日

カスタマーマネージドポリシーの例

このセクションでは、 AWS CodeBuild アクションのアクセス許可を付与するユーザーポリシー例を示しています。これらのポリシーは、 CodeBuild API、 AWS SDKs、または を使用しているときに機能します AWS CLI。コンソールを使用する場合は、コンソールに固有の追加のアクセス許可を付与する必要があります。詳細については、AWS CodeBuild コンソールの使用に必要な許可 を参照してください。

次のサンプル IAM ポリシーを使用して、ユーザーとロールの 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*" } ] }

レポートグループに関する情報の取得をユーザーに許可する

次のポリシーステートメント例では、us-east-2 リージョンにある 123456789012 アカウントのレポートグループについての情報をユーザーが取得するのを許可します。

{ "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 サービスロールのみを使用できます。また、ユーザーが で指定されたサービスロールのみを使用でき 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 の一覧表示をユーザーに許可する

次のポリシーステートメントの例では、us-east-2 リージョンにあり、123456789012 のアカウントで、my-build-project および my-other-build-project という名前のビルドプロジェクトのビルド ID リストをユーザーが取得するのを許可します。

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

ビルドの削除試行をユーザーに許可する

次のポリシーステートメントの例では、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*" } ] }

CodeBuild が管理する Docker イメージに関する情報の取得をユーザーに許可する

次のポリシーステートメントの例では、 CodeBuild で管理するすべての Docker イメージに関する情報を取得することをユーザーに許可します。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codebuild:ListCuratedEnvironmentImages", "Resource": "*" } ] }

VPC ネットワークインターフェイスの作成に必要な AWS サービス CodeBuild へのアクセスを許可する

次のポリシーステートメントの例では、2 つのサブネットを持つ VPC にネットワークインターフェイスを作成する AWS 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" ] } } } ] }

拒否ステートメントを使用して、 がソースプロバイダーから切断 AWS CodeBuild されないようにする

以下のポリシーステートメントの例では、拒否ステートメントを使用して AWS CodeBuild によるソースプロバイダーの切断を防ぎます。ソースプロバイダーと接続するには、codebuild:PersistOAuthToken および codebuild:ImportSourceCredentials の逆である codebuild:DeleteOAuthToken を使用します。詳細については、「AWS CodeBuild コンソールがソースプロバイダーに接続するために必要なアクセス許可」を参照してください。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": "codebuild:DeleteOAuthToken", "Resource": "*" } ] }