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 主题

    • 检索有关亚马逊 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: CodeDeploy 授予访问 Amazon ECS 和部署所需的任何其他资源的权限,但以下情况除外:

    • 在 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 通知的身份和访问管理