AWS CodeStar 基于身份的策略示例 - AWS CodeStar

2024 年 7 月 31 日,亚马逊 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 policy,以便为用户和角色授予权限以对所需的指定资源执行特定的 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 Acess 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 项目的特定级别的访问权限,其名称如下:

  • 所有者

  • 贡献者

  • 查看者

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 将该CodeStar_project-id_Contributor策略应用于具有贡献者访问权限级别的项目团队成员。具有贡献者访问权限的用户可向项目添加内容并可更改控制面板,但不能添加或删除团队成员。

... { "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 日太平洋夏令时之后 CodeStar 创建的 AWS CodeStar 项目,AWS 会为工作人员角色创建内联策略,以便在其他 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 日太平洋夏令时之后 CodeStar 创建的 AWS CodeStar 项目,AWS 会为工作人员角色创建内联策略,用于为您的 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 Ev CloudWatch ents 工作人员角色政策(太平洋夏令时 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 日太平洋夏令时之后创 CodeStar 建 AWS CodeStar 项目,AWS 会为您的项目创建权限边界策略。此策略可防止权限升级到项目之外的资源。它是一个动态策略,随项目的发展而更新。此策略的内容取决于您所创建的项目类型。以下是策略示例。有关更多信息,请参阅 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 用户使用项目 ID 向 AWS CodeStar 项目添加团队成员的权限 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 托管策略的更新

查看 CodeStar 自该服务开始跟踪这些更改以来对 AWS AWS 托管策略的更新的详细信息。要获取有关此页面变更的自动提醒,请在 AWS CodeStar 文档历史记录页面上订阅 RSS 提要。

更改 描述 日期

AWSCodeStarFullAccess 政策-更新 AWSCodeStarFullAccess 政策

AWS CodeStar 访问角色策略已更新。该政策的结果是一样的,但是cloudformation还需要 ListStacks 其他内容 DescribeStacks,这已经是必需的。

2023 年 3 月 24 日

AWSCodeStarServiceRole 政策-更新 AWSCodeStarServiceRole 政策

AWS CodeStar 服务角色的策略已更新,更正了策略声明中的冗余操作。

服务角色策略允许 AWS CodeStar 服务代表您执行操作。

2021 年 9 月 23 日

AWS CodeStar 开始跟踪变更

AWS CodeStar 开始跟踪其 AWS 托管策略的变更。

2021 年 9 月 23 日