【问题标题】:AWS CodeDeploy: Service role Cannot assume role providedAWS CodeDeploy:服务角色无法承担提供的角色
【发布时间】:2017-11-20 00:51:00
【问题描述】:

我正在尝试使用我的 GitHub 设置 CodeDeploy,但我发现了一些问题。

我已经创建了 service role,如文档中所述,使用 AWSCodeDeployRole 策略。

在我的代码部署应用程序创建过程中,我遇到了一个问题:

Cannot assume role provided.

如我所见,我在AWSCodeDeployRole 中的角色有很多自动缩放权限,但我不希望这样做:

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

在一些谷歌搜索过程中,我发现 CodeDeploy 应用程序可能期望类似于:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "codedeploy.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

但是当我尝试手动创建此策略时,它也会失败并出现错误:

This policy contains the following error: Has prohibited field Principal For more information about the IAM policy grammar, see AWS IAM Policies.

那么,Code Deploy Application 的预期服务角色是什么?

顺便说一句,代码部署正在我的 EC2 实例上运行。

【问题讨论】:

  • 我相信您将权限策略与trust relationships policy 混淆了。它们都是策略,语法相似,但用途不同:前者指定角色允许或拒绝的操作(例如自动缩放操作),后者指定哪些实体(主体)可以承担角色(例如 @987654330 @服务主体)。
  • 好吧,我的Service role 的信任关系如下:{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
  • 您是否发现此政策与您在谷歌搜索时发现的政策有相似之处? codedeployec2?
  • @Michael-sqlbot 你可以发表你的建议,我会批准的。以前删除我的答案。
  • 谢谢。我会这样做的。

标签: amazon-web-services amazon-ec2 aws-code-deploy


【解决方案1】:

嗯,根据@Michael 的评论,我发现我的Trust relationships policyService role 存在一些差异。

默认 AWSCodeDeployRole 似乎无法正确处理代码部署。

为了解决这个问题,我将"Service": [ "ec2.amazonaws.com"] 替换为"Service": [ "codedeploy.amazonaws.com"]

而且它有效!

【讨论】:

  • Nice find mate 应该是默认值!
【解决方案2】:

对于那些通过 Google 找到此内容的人 - 在我的 Cloud Formation 模板中,我将 ARN 格式化为错误,并且该错误不是描述性的:

角色需要以这种方式指定: arn:aws:iam::1234567890:role/CodeDeployRole 注意:role/ 而不是:instance-profile/

报错如上,不能承担角色,虽然是你指定错了。

【讨论】:

  • 我建议您不要共享实例 ID 或帐户 ID 等私有数据
  • 这不是真的 - 1234567890
【解决方案3】:

我按照教程进行操作,但没有提到您必须为服务角色编辑信任关系。在更改以下内容之前,我遇到了与上述相同的错误。

我变了

        "Service": "codebuild.amazonaws.com"

"Service" : [
      "codedeploy.amazonaws.com",
      "codebuild.amazonaws.com"
    ]
   

【讨论】:

    猜你喜欢
    • 2018-09-19
    • 1970-01-01
    • 2020-04-29
    • 2023-02-18
    • 2018-08-06
    • 2019-09-15
    • 2019-10-19
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多