View a markdown version of this page

Amazon 的托管(预定义)策略 CodeDeploy - Amazon CodeDeploy
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon 的托管(预定义)策略 CodeDeploy

Amazon 通过提供由创建和管理的独立 IAM 策略来解决许多常见用例 Amazon。这些 Amazon托管策略授予常见用例的权限,因此您可以不必调查需要哪些权限。有关更多信息,请参阅《IAM 用户指南》中的 Amazon 托管式策略

的名单 Amazon 的托管策略 CodeDeploy

您可以将以下 Amazon 托管策略附加到账户中的用户,这些策略特定于 CodeDeploy:

  • AWSCodeDeployFullAccess:授与对 CodeDeploy 的完全访问权限。

    注意

    AWSCodeDeployFullAccess 不为部署应用程序所需的其他服务(例如 Amazon EC2 和 Amazon S3)中的操作提供权限,仅向特定于的操作提供权限 CodeDeploy。

  • AWSCodeDeployDeployerAccess:授予注册和部署修订版的权限。

     

  • AWSCodeDeployReadOnlyAccess:授予对 CodeDeploy 的只读访问权限。

     

  • AWSCodeDeployRole: 允 CodeDeploy 许:

    • 阅读实例上的标签,或通过 Amazon EC2 Auto Scaling 组名称识别 Amazon EC2 实例。

    • 读取、创建、更新和删除 Amazon EC2 Auto Scaling 组、生命周期挂钩、扩展策略和暖池功能

    • 将信息发布到 Amazon SNS 主题

    • 检索有关 Amazon CloudWatch 警报的信息

    • 读取和更新 Elastic Load Balancing 服务中的资源

    策略包含以下代码:

    JSON
    { "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "autoscaling:CompleteLifecycleAction", "autoscaling:DeleteLifecycleHook", "autoscaling:DescribeAutoScalingGroups", "autoscaling:DescribeLifecycleHooks", "autoscaling:PutLifecycleHook", "autoscaling:RecordLifecycleActionHeartbeat", "autoscaling:CreateAutoScalingGroup", "autoscaling:CreateOrUpdateTags", "autoscaling:UpdateAutoScalingGroup", "autoscaling:EnableMetricsCollection", "autoscaling:DescribePolicies", "autoscaling:DescribeScheduledActions", "autoscaling:DescribeNotificationConfigurations", "autoscaling:SuspendProcesses", "autoscaling:ResumeProcesses", "autoscaling:AttachLoadBalancers", "autoscaling:AttachLoadBalancerTargetGroups", "autoscaling:PutScalingPolicy", "autoscaling:PutScheduledUpdateGroupAction", "autoscaling:PutNotificationConfiguration", "autoscaling:DescribeScalingActivities", "autoscaling:DeleteAutoScalingGroup", "autoscaling:PutWarmPool", "ec2:DescribeInstances", "ec2:DescribeInstanceStatus", "ec2:TerminateInstances", "tag:GetResources", "sns:Publish", "cloudwatch:DescribeAlarms", "cloudwatch:PutMetricAlarm", "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeLoadBalancerAttributes", "elasticloadbalancing:DescribeInstanceHealth", "elasticloadbalancing:RegisterInstancesWithLoadBalancer", "elasticloadbalancing:DeregisterInstancesFromLoadBalancer", "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetGroupAttributes", "elasticloadbalancing:DescribeTargetHealth", "elasticloadbalancing:RegisterTargets", "elasticloadbalancing:DeregisterTargets" ], "Resource": "*" } ] }

     

  • AWSCodeDeployRoleForLambda:授予访问 CodeDeploy权限 Amazon Lambda 以及部署所需的任何其他资源。

     

  • AWSCodeDeployRoleForECS:授 CodeDeploy 予访问部署所需的 Amazon ECS 和任何其他资源的权限。

     

  • AWSCodeDeployRoleForECSLimited: 授予访问部署所需的 Amazon ECS 和任何其他资源的 CodeDeploy权限,但以下情况除外:

    • 在该 AppSpec 文件的hooks部分中,只能使用名称以开头的 Lambda 函数。CodeDeployHook_有关更多信息,请参阅 AppSpec 亚马逊 ECS 部署的 “挂钩” 部分

    • S3 存储桶访问权限仅限于具有注册标记 UseWithCodeDeploy 且值为 true 的 S3 存储桶。有关更多信息,请参阅对象标记

  • AmazonEC2RoleforAWSCodeDeployLimited:授 CodeDeploy 予获取和列出 CodeDeploy Amazon S3 存储桶中对象的权限。策略包含以下代码:

    JSON
    { "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:GetObjectVersion", "s3:ListBucket" ], "Resource": "arn:aws:s3:::*/CodeDeploy/*" }, { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:GetObjectVersion" ], "Resource": "*", "Condition": { "StringEquals": { "s3:ExistingObjectTag/UseWithCodeDeploy": "true" } } } ] }

部署过程某些方面的权限被授予代表以下两个角色的另外两个角色类型 CodeDeploy:

  • IAM 实例配置文件 是您附加到 Amazon EC2 实例的 IAM 角色。此配置文件包括访问存储应用程序的 Amazon S3 存储桶或存储 GitHub 库所需的权限。有关更多信息,请参阅 步骤 4:为 Amazon EC2 实例创建 IAM 实例配置文件

  • 服务角色是一个 IAM 角色,它向 Amazon 服务授予权限,使其可以访问 Amazon 资源。您附加到服务角色的策略决定了服务可以访问哪些 Amazon 资源以及它可以对这些资源执行的操作。对于 CodeDeploy,服务角色用于以下用途:

    • 读取应用于实例的标签或与实例相关的 Amazon EC2 Auto Scaling 组名。这样就可以 CodeDeploy 确定它可以将应用程序部署到的实例。

    • 对实例、Amazon EC2 Auto Scaling 组和 Elastic Load Balancing 负载均衡器执行操作。

    • 向 Amazon SNS 主题发布信息,以便在发生指定部署或实例事件时发送通知。

    • 检索有关 CloudWatch 警报的信息,为部署设置警报监控。

    有关更多信息,请参阅 步骤 2:为创建服务角色 CodeDeploy

您还可以创建自定义 IAM 策略来授予 CodeDeploy操作和资源的权限。您将这些自定义策略附加到 IAM 角色,然后将角色分配给需要权限的用户或组。

CodeDeploy 托管策略和通知

CodeDeploy 支持通知,让用户知道部署的重要更改。的托管策略 CodeDeploy 包括通知功能的政策声明。有关更多信息,请参阅什么是通知?

完全访问托管式策略中通知的权限

AWSCodeDeployFullAccess 托管策略包含以下语句,以允许对通知进行完全访问。已应用此托管式策略的用户还可以创建和管理通知的 Amazon SNS 主题、为用户订阅和取消订阅主题,以及列出要选择作为通知规则的目标的主题。

{ "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" : { "ArnLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:codedeploy:*:*:application:*"} } }, { "Sid": "CodeStarNotificationsListAccess", "Effect": "Allow", "Action": [ "codestar-notifications:ListNotificationRules", "codestar-notifications:ListTargets", "codestar-notifications:ListTagsforResource" ], "Resource": "*" }, { "Sid": "CodeStarNotificationsSNSTopicCreateAccess", "Effect": "Allow", "Action": [ "sns:CreateTopic", "sns:SetTopicAttributes" ], "Resource": "arn:aws:sns:*:*:codestar-notifications*" }, { "Sid" : "CodeStarNotificationsChatbotAccess", "Effect" : "Allow", "Action" : [ "chatbot:DescribeSlackChannelConfigurations" ], "Resource" : "*" }, { "Sid": "SNSTopicListAccess", "Effect": "Allow", "Action": [ "sns:ListTopics" ], "Resource": "*" }

只读托管式策略中通知的权限

AWSCodeDeployReadOnlyAccess 托管策略包含以下语句,以允许对通知进行只读访问。应用此托管策略的用户可以查看资源的通知,但无法创建、管理或订阅这些通知。

{ "Sid": "CodeStarNotificationsPowerUserAccess", "Effect": "Allow", "Action": [ "codestar-notifications:DescribeNotificationRule" ], "Resource": "*", "Condition" : { "ArnLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:codedeploy:*:*:application:*"} } }, { "Sid": "CodeStarNotificationsListAccess", "Effect": "Allow", "Action": [ "codestar-notifications:ListNotificationRules" ], "Resource": "*" }

其它托管式策略中通知的权限

AWSCodeDeployDeployerAccess 托管式策略包括以下语句,可让用户创建、更新、订阅和查看资源的通知,但无法将其删除。应用了此托管式策略的用户还可以创建和管理用于通知的 Amazon SNS 主题。

此策略包括以下权限:

  • codestar-notifications:CreateNotificationRule:支持主体创建通知。

  • codestar-notifications:DescribeNotificationRule:支持主体检索有关通知的信息。

  • codestar-notifications:UpdateNotificationRule:支持主体更新通知。

  • codestar-notifications:Subscribe:支持主体订阅通知更新。

  • codestar-notifications:Unsubscribe:支持主体取消订阅通知更新。

  • codestar-notifications:ListNotificationRules:支持主体检索通知规则列表。

  • codestar-notifications:ListTargets:支持主体检索目标列表。

  • codestar-notifications:ListTagsforResource:支持主体检索标签列表。

  • codestar-notifications:ListEventTypes:支持主体检索事件类型列表。

  • chatbot:DescribeSlackChannelConfiguration:支持主体检索有关 Slack 通道配置的信息。

  • sns:ListTopics:支持主体检索通知的 Amazon SNS 主题列表。

{ "Sid" : "CodeStarNotificationsReadWriteAccess", "Effect" : "Allow", "Action" : [ "codestar-notifications:CreateNotificationRule", "codestar-notifications:DescribeNotificationRule", "codestar-notifications:UpdateNotificationRule", "codestar-notifications:Subscribe", "codestar-notifications:Unsubscribe" ], "Resource" : "*", "Condition" : { "ArnLike" : { "codestar-notifications:NotificationsForResource" : "arn:aws:codedeploy:*:*:application:*" } } }, { "Sid" : "CodeStarNotificationsListAccess", "Effect" : "Allow", "Action" : [ "codestar-notifications:ListNotificationRules", "codestar-notifications:ListTargets", "codestar-notifications:ListTagsforResource", "codestar-notifications:ListEventTypes" ], "Resource" : "*" }, { "Sid" : "CodeStarNotificationsChatbotAccess", "Effect" : "Allow", "Action" : [ "chatbot:DescribeSlackChannelConfigurations" ], "Resource" : "*" }, { "Sid" : "SNSTopicListAccess", "Effect" : "Allow", "Action" : [ "sns:ListTopics" ], "Resource" : "*" }

有关更多信息,请参阅 AWS CodeStar 通知的身份和访问管理