适用于 CodeDeploy 的 Amazon 托管(预定义)策略
Amazon通过提供由Amazon创建和管理的独立 IAM 策略来满足许多常用案例的要求。这些 Amazon 托管策略授予常用案例的必要权限,这样您不需要调查需要哪些权限。有关更多信息,请参阅《IAM 用户指南》中的 Amazon 托管策略。
CodeDeploy 的 Amazon 托管策略列表
以下 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 服务中的资源
策略包含以下代码:
-
-
AWSCodeDeployRoleForLambda:授予 CodeDeploy 权限以访问 Amazon Lambda 和部署所需的任何其他资源。 -
AWSCodeDeployRoleForECS:授予 CodeDeploy 权限以访问 Amazon ECS 和部署所需的任何其他资源。 -
AWSCodeDeployRoleForECSLimited:授予 CodeDeploy 权限以访问 Amazon ECS 和部署所需的任何其他资源,以下情况除外:-
在 AppSpec 文件的
hooks部分中,只能使用以CodeDeployHook_开头的 Lambda 函数。有关更多信息,请参阅 用于 Amazon ECS 部署的 AppSpec 的“hooks”部分。 -
S3 存储桶访问权限仅限于具有注册标记
UseWithCodeDeploy且值为true的 S3 存储桶。有关更多信息,请参阅对象标记。
-
-
AmazonEC2RoleforAWSCodeDeployLimited:授予 CodeDeploy 权限以获取和列出 CodeDeploy Amazon S3 存储桶中的对象。策略包含以下代码:
部署过程的某些方面的权限已授予两个代表 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 policy,以便授予 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 通知的身份和访问权限管理。