AWS CodeStar 身分型政策範例 - AWS CodeStar

2024 年 7 月 31 日,Amazon Web Services (AWS) 將停止建立和檢視AWS CodeStar專案的支援。2024 年 7 月 31 日之後,您將無法再存取AWS CodeStar主控台或建立新專案。但是AWS CodeStar,由建立的AWS資源 (包括您的來源儲存庫、管道和組建) 將不受此變更的影響,並將繼續運作。 AWS CodeStar連線和AWS CodeStar通知不會受到此停止的影響。

 

如果您想要追蹤工作、開發程式碼以及建置、測試和部署應用程式,Amazon CodeCatalyst 提供簡化的入門程序和其他功能來管理軟體專案。進一步了解 Amazon 的功能定價 CodeCatalyst。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS CodeStar 身分型政策範例

依預設,IAM 使用者和角色沒有建立或修改 AWS CodeStar 資源的權限。他們也無法使用 AWS Management Console、AWS CLI 或 AWS API 執行任務。管理員必須建立 IAM 政策,授與使用者和角色在指定資源上執行特定 API 操作所需的許可。管理員接著必須將這些政策連接至需要這些許可的 IAM 使用者或群組。

若要了解如何使用這些範例 JSON 政策文件建立 IAM 身分型政策,請參閱《IAM 使用者指南》中的在 JSON 標籤上建立政策

政策最佳實務

以身分識別為基礎的政策會決定某人是否可以在您的帳戶中建立、存取或刪除 AWS CodeStar 資源。這些動作可能會讓您的 AWS 帳戶 產生費用。當您建立或編輯身分型政策時,請遵循下列準則及建議事項:

  • 開始使用 AWS 受管政策並朝向最低權限許可的目標邁進:如需開始授予許可給使用者和工作負載,請使用 AWS 受管政策,這些政策會授予許可給許多常用案例。它們可在您的 AWS 帳戶 中使用。我們建議您定義特定於使用案例的 AWS 客戶管理政策,以便進一步減少許可。如需更多資訊,請參閱 IAM 使用者指南中的 AWS 受管政策任務職能的 AWS 受管政策

  • 套用最低許可許可 – 設定 IAM 政策的許可時,請僅授予執行任務所需的權限。為實現此目的,您可以定義在特定條件下可以對特定資源採取的動作,這也稱為最低權限許可。如需使用 IAM 套用許可的更多相關資訊,請參閱 IAM 使用者指南中的 IAM 中的政策和許可

  • 使用 IAM 政策中的條件進一步限制存取權 – 您可以將條件新增至政策,以限制動作和資源的存取。例如,您可以撰寫政策條件,指定必須使用 SSL 傳送所有請求。您也可以使用條件來授予對服務動作的存取權,前提是透過特定 AWS 服務(例如 AWS CloudFormation)使用條件。如需更多資訊,請參閱《IAM 使用者指南》中的 IAM JSON 政策元素:條件

  • 使用 IAM Access Analyzer 驗證 IAM 政策,確保許可安全且可正常運作 – IAM Access Analyzer 驗證新政策和現有政策,確保這些政策遵從 IAM 政策語言 (JSON) 和 IAM 最佳實務。IAM Access Analyzer 提供 100 多項政策檢查及切實可行的建議,可協助您編寫安全且實用的政策。如需更多資訊,請參閱 IAM 使用者指南中的 IAM Access Analyzer 政策驗證

  • 需要多重要素驗證 (MFA):如果存在需要 AWS 帳戶中 IAM 使用者或根使用者的情況,請開啟 MFA 提供額外的安全性。如需在呼叫 API 操作時請求 MFA,請將 MFA 條件新增至您的政策。如需更多資訊,請參閱 IAM 使用者指南中的設定 MFA 保護的 API 存取

有關 IAM 中最佳實務的更多相關資訊,請參閱 IAM 使用者指南中的 IAM 最佳安全實務

AWSCodeStarServiceRole 政策

aws-codestar-service-role 政策會連接到允許 AWS CodeStar 對其他服務執行動作的服務角色。第一次登入時 AWS CodeStar,您會建立服務角色。您只需要建立一次。政策會在您建立服務角色之後自動連接到服務角色。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ProjectEventRules", "Effect": "Allow", "Action": [ "events:PutTargets", "events:RemoveTargets", "events:PutRule", "events:DeleteRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:*:*:rule/awscodestar-*" ] }, { "Sid": "ProjectStack", "Effect": "Allow", "Action": [ "cloudformation:*Stack*", "cloudformation:CreateChangeSet", "cloudformation:ExecuteChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:GetTemplate" ], "Resource": [ "arn:aws:cloudformation:*:*:stack/awscodestar-*", "arn:aws:cloudformation:*:*:stack/awseb-*", "arn:aws:cloudformation:*:*:stack/aws-cloud9-*", "arn:aws:cloudformation:*:aws:transform/CodeStar*" ] }, { "Sid": "ProjectStackTemplate", "Effect": "Allow", "Action": [ "cloudformation:GetTemplateSummary", "cloudformation:DescribeChangeSet" ], "Resource": "*" }, { "Sid": "ProjectQuickstarts", "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::awscodestar-*/*" ] }, { "Sid": "ProjectS3Buckets", "Effect": "Allow", "Action": [ "s3:*" ], "Resource": [ "arn:aws:s3:::aws-codestar-*", "arn:aws:s3:::elasticbeanstalk-*" ] }, { "Sid": "ProjectServices", "Effect": "Allow", "Action": [ "codestar:*", "codecommit:*", "codepipeline:*", "codedeploy:*", "codebuild:*", "autoscaling:*", "cloudwatch:Put*", "ec2:*", "elasticbeanstalk:*", "elasticloadbalancing:*", "iam:ListRoles", "logs:*", "sns:*", "cloud9:CreateEnvironmentEC2", "cloud9:DeleteEnvironment", "cloud9:DescribeEnvironment*", "cloud9:ListEnvironments" ], "Resource": "*" }, { "Sid": "ProjectWorkerRoles", "Effect": "Allow", "Action": [ "iam:AttachRolePolicy", "iam:CreateRole", "iam:DeleteRole", "iam:DeleteRolePolicy", "iam:DetachRolePolicy", "iam:GetRole", "iam:PassRole", "iam:GetRolePolicy", "iam:PutRolePolicy", "iam:SetDefaultPolicyVersion", "iam:CreatePolicy", "iam:DeletePolicy", "iam:AddRoleToInstanceProfile", "iam:CreateInstanceProfile", "iam:DeleteInstanceProfile", "iam:RemoveRoleFromInstanceProfile" ], "Resource": [ "arn:aws:iam::*:role/CodeStarWorker*", "arn:aws:iam::*:policy/CodeStarWorker*", "arn:aws:iam::*:instance-profile/awscodestar-*" ] }, { "Sid": "ProjectTeamMembers", "Effect": "Allow", "Action": [ "iam:AttachUserPolicy", "iam:DetachUserPolicy" ], "Resource": "*", "Condition": { "ArnEquals": { "iam:PolicyArn": [ "arn:aws:iam::*:policy/CodeStar_*" ] } } }, { "Sid": "ProjectRoles", "Effect": "Allow", "Action": [ "iam:CreatePolicy", "iam:DeletePolicy", "iam:CreatePolicyVersion", "iam:DeletePolicyVersion", "iam:ListEntitiesForPolicy", "iam:ListPolicyVersions", "iam:GetPolicy", "iam:GetPolicyVersion" ], "Resource": [ "arn:aws:iam::*:policy/CodeStar_*" ] }, { "Sid": "InspectServiceRole", "Effect": "Allow", "Action": [ "iam:ListAttachedRolePolicies" ], "Resource": [ "arn:aws:iam::*:role/aws-codestar-service-role", "arn:aws:iam::*:role/service-role/aws-codestar-service-role" ] }, { "Sid": "IAMLinkRole", "Effect": "Allow", "Action": [ "iam:CreateServiceLinkedRole" ], "Resource": "*", "Condition": { "StringEquals": { "iam:AWSServiceName": "cloud9.amazonaws.com" } } }, { "Sid": "DescribeConfigRuleForARN", "Effect": "Allow", "Action": [ "config:DescribeConfigRules" ], "Resource": [ "*" ] }, { "Sid": "ProjectCodeStarConnections", "Effect": "Allow", "Action": [ "codestar-connections:UseConnection", "codestar-connections:GetConnection" ], "Resource": "*" }, { "Sid": "ProjectCodeStarConnectionsPassConnections", "Effect": "Allow", "Action": "codestar-connections:PassConnection", "Resource": "*", "Condition": { "StringEqualsIfExists": { "codestar-connections:PassedToService": "codepipeline.amazonaws.com" } } } ] }

AWSCodeStarFullAccess 政策

設定 AWS CodeStar指示中,您附加了名為 AWSCodeStarFullAccess IAM 使用者的政策。此政策陳述式允許使用者執行 AWS CodeStar 中所有可用的動作,包括與 AWS 帳戶關聯的所有可用 AWS CodeStar 資源。這包括建立和刪除專案。下列範例是代表性 AWSCodeStarFullAccess 政策的程式碼片段。實際政策會根據您在啟動新 AWS CodeStar 專案時選取的範本而有所不同。

在沒有目標堆疊的cloudformation::DescribeStacks情況下呼叫時,AWS CloudFormation 需要cloudformation::ListStacks許可。

許可詳細資訊

此策略包含執行下列動作的權限:

  • ec2— 擷取 EC2 執行個體的相關資訊以建立AWS CodeStar專案。

  • cloud9擷取有關AWS Command Line Interface環境的資訊。

  • cloudformation擷取有關AWS CodeStar專案堆疊的資訊。

  • codestar在AWS CodeStar專案中執行動作。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "CodeStarEC2", "Effect": "Allow", "Action": [ "codestar:*", "ec2:DescribeKeyPairs", "ec2:DescribeVpcs", "ec2:DescribeSubnets", "cloud9:DescribeEnvironment*" ], "Resource": "*" }, { "Sid": "CodeStarCF", "Effect": "Allow", "Action": [ "cloudformation:DescribeStack*", "cloudformation:ListStacks*", "cloudformation:GetTemplateSummary" ], "Resource": [ "arn:aws:cloudformation:*:*:stack/awscodestar-*" ] } ] }

您可能不會想要提供所有使用者如此多的存取權限。反之,您可以使用 AWS CodeStar 管理的專案角色以新增專案層級的許可。此角色將特定層級的存取權限授予 AWS CodeStar 專案,並命名如下:

  • Owner

  • 作者群

  • 觀眾

AWS CodeStar 擁有者角色原則

AWS CodeStar 擁有者角色政策允許使用者在 AWS CodeStar 專案中不受任何限制地執行所有動作。AWS 將CodeStar_project-id_Owner政策 CodeStar 套用至擁有者存取層級的專案團隊成員。

... { "Effect": "Allow", "Action": [ ... "codestar:*", ... ], "Resource": [ "arn:aws:codestar:us-east-2:111111111111:project/project-id", "arn:aws:iam::account-id:policy/CodeStar_project-id_Owner" ] }, { "Effect": "Allow", "Action": [ "codestar:DescribeUserProfile", "codestar:ListProjects", "codestar:ListUserProfiles", "codestar:VerifyServiceRole", ... ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "codestar:*UserProfile", ... ], "Resource": [ "arn:aws:iam::account-id:user/user-name" ] } ...

AWS CodeStar 作者群角色政策

AWS CodeStar 參與者角色政策可讓使用者為專案做出貢獻,並變更專案儀表板。AWS 會將該CodeStar_project-id_Contributor政策 CodeStar 套用至具有參與者存取層級的專案團隊成員。具有參與者存取的使用者可以參與專案和變更專案儀表板,但無法新增或移除專案成員。

... { "Effect": "Allow", "Action": [ ... "codestar:Describe*", "codestar:Get*", "codestar:List*", "codestar:PutExtendedAccess", ... ], "Resource": [ "arn:aws:codestar:us-east-2:111111111111:project/project-id", "arn:aws:iam::account-id:policy/CodeStar_project-id_Contributor" ] }, { "Effect": "Allow", "Action": [ "codestar:DescribeUserProfile", "codestar:ListProjects", "codestar:ListUserProfiles", "codestar:VerifyServiceRole", ... ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "codestar:*UserProfile", ... ], "Resource": [ "arn:aws:iam::account-id:user/user-name" ] } ...

AWS CodeStar 檢視者角色原則

AWS 檢視 CodeStar 器角色政策可讓使用者在 AWS 中檢視專案 CodeStar。AWS 將CodeStar_project-id_Viewer政策 CodeStar 套用至具有檢視者存取層級的專案團隊成員。具有檢視者存取權的使用者可以在 AWS 中檢視專案 CodeStar,但不能變更其資源,也無法新增或移除團隊成員。

... { "Effect": "Allow", "Action": [ ... "codestar:Describe*", "codestar:Get*", "codestar:List*", ... ], "Resource": [ "arn:aws:codestar:us-east-2:111111111111:project/project-id", "arn:aws:iam::account-id:policy/CodeStar_project-id_Viewer" ] }, { "Effect": "Allow", "Action": [ "codestar:DescribeUserProfile", "codestar:ListProjects", "codestar:ListUserProfiles", "codestar:VerifyServiceRole", ... ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "codestar:*UserProfile", ... ], "Resource": [ "arn:aws:iam::account-id:user/user-name" ] } ...

AWS CodeStar工具鏈背景工作者角色政策 (在 2018 年 12 月 6 日 (太平洋標準時間)

針對在 2018 年 12 月 6 日 PDT 之後建立的AWS CodeStar專案,AWS CodeStar 會為背景工作者角色建立內嵌政策,以便在其他AWS服務中為您的專案建立資源。政策的內容取決於您要建立的專案類型。以下政策為一個範例。如需詳細資訊,請參閱用於工作者角色的 IAM 政策

{ "Statement": [ { "Action": [ "s3:GetObject", "s3:GetObjectVersion", "s3:GetBucketVersioning", "s3:PutObject*", "codecommit:CancelUploadArchive", "codecommit:GetBranch", "codecommit:GetCommit", "codecommit:GetUploadArchiveStatus", "codecommit:GitPull", "codecommit:UploadArchive", "codebuild:StartBuild", "codebuild:BatchGetBuilds", "codebuild:StopBuild", "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "cloudformation:DescribeStacks", "cloudformation:DescribeChangeSet", "cloudformation:CreateChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:ExecuteChangeSet", "codepipeline:StartPipelineExecution", "lambda:ListFunctions", "lambda:InvokeFunction", "sns:Publish" ], "Resource": [ "*" ], "Effect": "Allow" }, { "Action": [ "iam:PassRole" ], "Resource": [ "*" ], "Effect": "Allow" }, { "Action": [ "kms:GenerateDataKey*", "kms:Encrypt", "kms:Decrypt" ], "Resource": [ "*" ], "Effect": "Allow" } ] }

AWS CloudFormation 工作者角色政策

針對 2018 年 12 月 6 日 (太平洋標準時間) 之後建立的AWS CodeStar專案,AWS CodeStar 會為工作者角色建立內嵌政策,為您的 AWS CodeStar 專案建立AWS CloudFormation資源。政策的內容取決於您的專案所需的資源類型。以下政策為一個範例。如需詳細資訊,請參閱用於工作者角色的 IAM 政策

{ { "Statement": [ { "Action": [ "s3:PutObject", "s3:GetObject", "s3:GetObjectVersion" ], "Resource": [ "arn:aws:s3:::aws-codestar-region-id-account-id-project-id", "arn:aws:s3:::aws-codestar-region-id-account-id-project-id/*" ], "Effect": "Allow" }, { "Action": [ "apigateway:DELETE", "apigateway:GET", "apigateway:PATCH", "apigateway:POST", "apigateway:PUT", "codedeploy:CreateApplication", "codedeploy:CreateDeployment", "codedeploy:CreateDeploymentConfig", "codedeploy:CreateDeploymentGroup", "codedeploy:DeleteApplication", "codedeploy:DeleteDeployment", "codedeploy:DeleteDeploymentConfig", "codedeploy:DeleteDeploymentGroup", "codedeploy:GetDeployment", "codedeploy:GetDeploymentConfig", "codedeploy:GetDeploymentGroup", "codedeploy:RegisterApplicationRevision", "codestar:SyncResources", "config:DeleteConfigRule", "config:DescribeConfigRules", "config:ListTagsForResource", "config:PutConfigRule", "config:TagResource", "config:UntagResource", "dynamodb:CreateTable", "dynamodb:DeleteTable", "dynamodb:DescribeContinuousBackups", "dynamodb:DescribeTable", "dynamodb:DescribeTimeToLive", "dynamodb:ListTagsOfResource", "dynamodb:TagResource", "dynamodb:UntagResource", "dynamodb:UpdateContinuousBackups", "dynamodb:UpdateTable", "dynamodb:UpdateTimeToLive", "ec2:AssociateIamInstanceProfile", "ec2:AttachVolume", "ec2:CreateSecurityGroup", "ec2:createTags", "ec2:DescribeIamInstanceProfileAssociations", "ec2:DescribeInstances", "ec2:DescribeSecurityGroups", "ec2:DescribeSubnets", "ec2:DetachVolume", "ec2:DisassociateIamInstanceProfile", "ec2:ModifyInstanceAttribute", "ec2:ModifyInstanceCreditSpecification", "ec2:ModifyInstancePlacement", "ec2:MonitorInstances", "ec2:ReplaceIamInstanceProfileAssociation", "ec2:RunInstances", "ec2:StartInstances", "ec2:StopInstances", "ec2:TerminateInstances", "events:DeleteRule", "events:DescribeRule", "events:ListTagsForResource", "events:PutRule", "events:PutTargets", "events:RemoveTargets", "events:TagResource", "events:UntagResource", "kinesis:AddTagsToStream", "kinesis:CreateStream", "kinesis:DecreaseStreamRetentionPeriod", "kinesis:DeleteStream", "kinesis:DescribeStream", "kinesis:IncreaseStreamRetentionPeriod", "kinesis:RemoveTagsFromStream", "kinesis:StartStreamEncryption", "kinesis:StopStreamEncryption", "kinesis:UpdateShardCount", "lambda:CreateAlias", "lambda:CreateFunction", "lambda:DeleteAlias", "lambda:DeleteFunction", "lambda:DeleteFunctionConcurrency", "lambda:GetFunction", "lambda:GetFunctionConfiguration", "lambda:ListTags", "lambda:ListVersionsByFunction", "lambda:PublishVersion", "lambda:PutFunctionConcurrency", "lambda:TagResource", "lambda:UntagResource", "lambda:UpdateAlias", "lambda:UpdateFunctionCode", "lambda:UpdateFunctionConfiguration", "s3:CreateBucket", "s3:DeleteBucket", "s3:DeleteBucketWebsite", "s3:PutAccelerateConfiguration", "s3:PutAnalyticsConfiguration", "s3:PutBucketAcl", "s3:PutBucketCORS", "s3:PutBucketLogging", "s3:PutBucketNotification", "s3:PutBucketPublicAccessBlock", "s3:PutBucketVersioning", "s3:PutBucketWebsite", "s3:PutEncryptionConfiguration", "s3:PutInventoryConfiguration", "s3:PutLifecycleConfiguration", "s3:PutMetricsConfiguration", "s3:PutReplicationConfiguration", "sns:CreateTopic", "sns:DeleteTopic", "sns:GetTopicAttributes", "sns:ListSubscriptionsByTopic", "sns:ListTopics", "sns:SetSubscriptionAttributes", "sns:Subscribe", "sns:Unsubscribe", "sqs:CreateQueue", "sqs:DeleteQueue", "sqs:GetQueueAttributes", "sqs:GetQueueUrl", "sqs:ListQueueTags", "sqs:TagQueue", "sqs:UntagQueue" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "lambda:AddPermission", "lambda:RemovePermission" ], "Resource": [ "arn:aws:lambda:region-id:account-id:function:awscodestar-*" ], "Effect": "Allow" }, { "Action": [ "iam:PassRole" ], "Resource": [ "arn:aws:iam::account-id:role/CodeStar-project-id*" ], "Effect": "Allow" }, { "Condition": { "StringEquals": { "iam:PassedToService": "codedeploy.amazonaws.com" } }, "Action": [ "iam:PassRole" ], "Resource": [ "arn:aws:iam::account-id:role/CodeStarWorker-project-id-CodeDeploy" ], "Effect": "Allow" }, { "Action": [ "cloudformation:CreateChangeSet" ], "Resource": [ "arn:aws:cloudformation:region-id:aws:transform/Serverless-2016-10-31", "arn:aws:cloudformation:region-id:aws:transform/CodeStar" ], "Effect": "Allow" }, { "Action": [ "iam:CreateServiceLinkedRole", "iam:GetRole", "iam:DeleteRole", "iam:DeleteUser" ], "Resource": "*", "Effect": "Allow" }, { "Condition": { "StringEquals": { "iam:PermissionsBoundary": "arn:aws:iam::account-id:policy/CodeStar_project-id_PermissionsBoundary" } }, "Action": [ "iam:AttachRolePolicy", "iam:AttachUserPolicy", "iam:CreateRole", "iam:CreateUser", "iam:DeleteRolePolicy", "iam:DeleteUserPolicy", "iam:DetachUserPolicy", "iam:DetachRolePolicy", "iam:PutUserPermissionsBoundary", "iam:PutRolePermissionsBoundary" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "kms:CreateKey", "kms:CreateAlias", "kms:DeleteAlias", "kms:DisableKey", "kms:EnableKey", "kms:UpdateAlias", "kms:TagResource", "kms:UntagResource" ], "Resource": "*", "Effect": "Allow" }, { "Condition": { "StringEquals": { "ssm:ResourceTag/awscodestar:projectArn": "arn:aws:codestar:project-id:account-id:project/project-id" } }, "Action": [ "ssm:GetParameter*" ], "Resource": "*", "Effect": "Allow" } ] }

AWS CloudFormation背景工作者角色原則 (太平洋時間 2018 年 12 月 6 日之前)

如果您的 AWS CodeStar 專案是在 2018 年 12 月 6 日 (太平洋標準時間) 之前建 CodeStar 立的,則 AWS 會為AWS CloudFormation背景工作者角色建立內嵌政策。下列政策陳述式一個範例。

{ "Statement": [ { "Action": [ "s3:PutObject", "s3:GetObject", "s3:GetObjectVersion" ], "Resource": [ "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe/*" ], "Effect": "Allow" }, { "Action": [ "codestar:SyncResources", "lambda:CreateFunction", "lambda:DeleteFunction", "lambda:AddPermission", "lambda:UpdateFunction", "lambda:UpdateFunctionCode", "lambda:GetFunction", "lambda:GetFunctionConfiguration", "lambda:UpdateFunctionConfiguration", "lambda:RemovePermission", "lambda:listTags", "lambda:TagResource", "lambda:UntagResource", "apigateway:*", "dynamodb:CreateTable", "dynamodb:DeleteTable", "dynamodb:DescribeTable", "kinesis:CreateStream", "kinesis:DeleteStream", "kinesis:DescribeStream", "sns:CreateTopic", "sns:DeleteTopic", "sns:ListTopics", "sns:GetTopicAttributes", "sns:SetTopicAttributes", "s3:CreateBucket", "s3:DeleteBucket", "config:DescribeConfigRules", "config:PutConfigRule", "config:DeleteConfigRule", "ec2:*", "autoscaling:*", "elasticloadbalancing:*", "elasticbeanstalk:*" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "iam:PassRole" ], "Resource": [ "arn:aws:iam::account-id:role/CodeStarWorker-project-id-Lambda" ], "Effect": "Allow" }, { "Action": [ "cloudformation:CreateChangeSet" ], "Resource": [ "arn:aws:cloudformation:us-east-1:aws:transform/Serverless-2016-10-31", "arn:aws:cloudformation:us-east-1:aws:transform/CodeStar" ], "Effect": "Allow" } ] }

AWS CodePipeline背景工作者角色原則 (太平洋時間 2018 年 12 月 6 日之前)

如果您的 AWS CodeStar 專案是在 2018 年 12 月 6 日 (太平洋標準時間) 之前建 CodeStar 立的,則 AWS 會為 CodePipeline 背景工作者角色建立內嵌政策。下列政策陳述式一個範例。

{ "Statement": [ { "Action": [ "s3:GetObject", "s3:GetObjectVersion", "s3:GetBucketVersioning", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe/*" ], "Effect": "Allow" }, { "Action": [ "codecommit:CancelUploadArchive", "codecommit:GetBranch", "codecommit:GetCommit", "codecommit:GetUploadArchiveStatus", "codecommit:UploadArchive" ], "Resource": [ "arn:aws:codecommit:us-east-1:account-id:project-id" ], "Effect": "Allow" }, { "Action": [ "codebuild:StartBuild", "codebuild:BatchGetBuilds", "codebuild:StopBuild" ], "Resource": [ "arn:aws:codebuild:us-east-1:account-id:project/project-id" ], "Effect": "Allow" }, { "Action": [ "cloudformation:DescribeStacks", "cloudformation:DescribeChangeSet", "cloudformation:CreateChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:ExecuteChangeSet" ], "Resource": [ "arn:aws:cloudformation:us-east-1:account-id:stack/awscodestar-project-id-lambda/*" ], "Effect": "Allow" }, { "Action": [ "iam:PassRole" ], "Resource": [ "arn:aws:iam::account-id:role/CodeStarWorker-project-id-CloudFormation" ], "Effect": "Allow" } ] }

AWS CodeBuild背景工作者角色原則 (太平洋時間 2018 年 12 月 6 日之前)

如果您的 AWS CodeStar 專案是在 2018 年 12 月 6 日 (太平洋標準時間) 之前建 CodeStar 立的,則 AWS 會為 CodeBuild 背景工作者角色建立內嵌政策。下列政策陳述式一個範例。

{ "Statement": [ { "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "s3:PutObject", "s3:GetObject", "s3:GetObjectVersion" ], "Resource": [ "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe/*", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-app", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-app/*" ], "Effect": "Allow" }, { "Action": [ "codecommit:GitPull" ], "Resource": [ "arn:aws:codecommit:us-east-1:account-id:project-id" ], "Effect": "Allow" }, { "Action": [ "kms:GenerateDataKey*", "kms:Encrypt", "kms:Decrypt" ], "Resource": [ "arn:aws:kms:us-east-1:account-id:alias/aws/s3" ], "Effect": "Allow" } ] }

Amazon CloudWatch 活動工作者角色政策(在太平洋時間 2018 年 12 月 6 日之前)

如果您的 AWS CodeStar 專案是在 2018 年 12 月 6 日 (太平洋標準時間) 之前建 CodeStar 立的,則 AWS 會為 CloudWatch 事件工作者角色建立內嵌政策。下列政策陳述式一個範例。

{ "Statement": [ { "Action": [ "codepipeline:StartPipelineExecution" ], "Resource": [ "arn:aws:codepipeline:us-east-1:account-id:project-id-Pipeline" ], "Effect": "Allow" } ] }

AWS CodeStar 許可邊界政策

如果您在太平洋標準時間 2018 年 12 月 6 日之後建立 AWS CodeStar 專案,AWS CodeStar 會為您的專案建立許可界限政策。此政策可防止將權限提升至專案外部的資源。這是一個動態政策,會隨著專案演進更新。政策的內容取決於您要建立的專案類型。以下政策為一個範例。如需詳細資訊,請參閱IAM 許可界限

{ "Version": "2012-10-17", "Statement": [ { "Sid": "1", "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::*/AWSLogs/*/Config/*" ] }, { "Sid": "2", "Effect": "Allow", "Action": [ "*" ], "Resource": [ "arn:aws:codestar:us-east-1:account-id:project/project-id", "arn:aws:cloudformation:us-east-1:account-id:stack/awscodestar-project-id-lambda/eefbbf20-c1d9-11e8-8a3a-500c28b4e461", "arn:aws:cloudformation:us-east-1:account-id:stack/awscodestar-project-id/4b80b3f0-c1d9-11e8-8517-500c28b236fd", "arn:aws:codebuild:us-east-1:account-id:project/project-id", "arn:aws:codecommit:us-east-1:account-id:project-id", "arn:aws:codepipeline:us-east-1:account-id:project-id-Pipeline", "arn:aws:execute-api:us-east-1:account-id:7rlst5mrgi", "arn:aws:iam::account-id:role/CodeStarWorker-project-id-CloudFormation", "arn:aws:iam::account-id:role/CodeStarWorker-project-id-CloudWatchEventRule", "arn:aws:iam::account-id:role/CodeStarWorker-project-id-CodeBuild", "arn:aws:iam::account-id:role/CodeStarWorker-project-id-CodePipeline", "arn:aws:iam::account-id:role/CodeStarWorker-project-id-Lambda", "arn:aws:lambda:us-east-1:account-id:function:awscodestar-project-id-lambda-GetHelloWorld-KFKTXYNH9573", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-app", "arn:aws:s3:::aws-codestar-us-east-1-account-id-project-id-pipe" ] }, { "Sid": "3", "Effect": "Allow", "Action": [ "apigateway:GET", "config:Describe*", "config:Get*", "config:List*", "config:Put*", "logs:CreateLogGroup", "logs:CreateLogStream", "logs:DescribeLogGroups", "logs:PutLogEvents" ], "Resource": [ "*" ] } ] }

列出專案的資源

在此範例中,您想要授與AWS帳戶中指定的 IAM 使用者存取權限,以列出AWS CodeStar專案的資源。

{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "codestar:ListResources", ], "Resource" : "arn:aws:codestar:us-east-2:project/my-first-projec" } ] }

使用 AWS CodeStar 主控台

存取 AWS CodeStar 主控台不需要特定許可,但除非您擁有AWSCodeStarFullAccess政策或其中一個AWS CodeStar專案層級角色:擁有者、參與者或檢視者,否則您無法執行任何有用的操作。如需 AWSCodeStarFullAccess 的詳細資訊,請參閱 AWSCodeStarFullAccess 政策。如需專案層級政策的詳細資訊,請參閱用於專案團隊成員的 IAM 政策

對於僅呼叫 AWS CLI 或 AWS API 的使用者,您不需要允許其最基本主控台許可。反之,只需允許存取符合您嘗試執行之 API 操作的動作就可以了。

允許使用者檢視自己的許可

此範例會示範如何建立政策,允許 IAM 使用者檢視附加到他們使用者身分的內嵌及受管政策。此政策包含在主控台上,或是使用 AWS CLI 或 AWS API 透過編寫程式的方式完成此動作的許可。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }

更新AWS CodeStar 專案

在此範例中,您想要授與AWS帳戶中指定的 IAM 使用者存取權,以編輯AWS CodeStar專案的屬性,例如專案說明。

{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "codestar:UpdateProject" ], "Resource" : "arn:aws:codestar:us-east-2:project/my-first-projec" } ] }

新增團隊成員到專案

在此範例中,您想要授與指定的 IAM 使用者將團隊成員新增至具有AWS CodeStar專案 ID 的功能 my-first-projec,但要明確拒絕該使用者移除團隊成員的能力:

{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "codestar:AssociateTeamMember", ], "Resource" : "arn:aws:codestar:us-east-2:project/my-first-projec" }, { "Effect" : "Deny", "Action" : [ "codestar:DisassociateTeamMember", ], "Resource" : "arn:aws:codestar:us-east-2:project/my-first-projec" } ] ] }

列出與AWS帳戶相關聯的使用者設定檔

在此範例中,您允許已附加此政策的 IAM 使用者列出與AWS帳戶相關聯的所有AWS CodeStar使用者設定檔:

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

根據標籤檢視 AWS CodeStar 專案

您可以使用身分型政策中的條件,根據標籤控制 AWS CodeStar 專案的存取。此範例會示範如何建立政策,允許檢視專案。但是,只有在專案標籤 Owner 的值是該使用者的使用者名稱時,才會授予許可。此政策也會授予在主控台完成此動作的必要許可。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListProjectsInConsole", "Effect": "Allow", "Action": "codestar:ListProjects", "Resource": "*" }, { "Sid": "ViewProjectIfOwner", "Effect": "Allow", "Action": "codestar:GetProject, "Resource": "arn:aws:codestar:*:*:project/*", "Condition": { "StringEquals": {"codestar:ResourceTag/Owner": "${aws:username}"} } } ] }

您可以將此政策連接到您帳戶中的 IAM 使用者。如果命名的使用者richard-roe嘗試檢視 AWS CodeStar 專案,則必須標記該專案Owner=richard-roeowner=richard-roe。否則他便會被拒絕存取。條件標籤鍵 Owner 符合 Ownerowner,因為條件索引鍵名稱不區分大小寫。如需詳細資訊,請參閱《IAM 使用者指南》中的 IAM JSON 政策元素:條件

AWS CodeStarAWS受管理策略的更新

檢視有關 AWS AWS 受管政策更新的詳細資訊, CodeStar 因為此服務開始追蹤這些變更。如需有關此頁面變更的自動警示,請訂閱 AWS CodeStar 文件歷史記錄頁面上的 RSS 摘要。

變更 描述 日期

AWSCodeStarFullAccess 政策 — 更新政 AWSCodeStarFullAccess 策

AWS CodeStar存取角色原則已更新。政策的結果是相同的,但雲形成需要除 ListStacks 了 DescribeStacks,這是已經需要的。

2023 年 3 月 24 日

AWSCodeStarServiceRole 政策 — 更新政 AWSCodeStarServiceRole 策

AWS CodeStar 服務角色的政策已更新,以更正政策聲明中的冗餘動作。

服務角色政策允許 AWS CodeStar 服務代表您執行動作。

2021 年 9 月 23 日

AWS CodeStar 開始追蹤變更

AWS CodeStar 開始追蹤AWS受管政策的變更。

2021 年 9 月 23 日