Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The provided role does not have sufficient permissions to access CodeDeploy

I am implementing CodePipeline; using GitHub, CodeBuild and Amazon ECS (blue/green). The role I am using, is the one generated by the Pipeline: ecsTaskExecutionRole

When generated, it is equipped with the following policies: AmazonECSTaskExecutionRolePolicy (containing the following actions):

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "ecr:GetAuthorizationToken",
            "ecr:BatchCheckLayerAvailability",
            "ecr:GetDownloadUrlForLayer",
            "ecr:BatchGetImage",
            "logs:CreateLogStream",
            "logs:PutLogEvents"
        ],
        "Resource": "*"
    }
]}

And the following Trust relationships:

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

Given that the role is auto-generated, one would assume that either it would have ALL the necessary permissions (for the pipeline to function) OR AWS would have a guide on which permissions to assign (to either a policy OR the trust relationship configuration).

Despite, updating the trust relationship to include:

"Service": [
      "codebuild.amazonaws.com",
      "ecs-tasks.amazonaws.com",
      "ec2.amazonaws.com",
      "codedeploy.amazonaws.com",
      "codepipeline.amazonaws.com",
      "s3.amazonaws.com"
    ]

I still get the error: enter image description here

I have seen this issue raised in multiple blogs/forum, spanning the past 1-2 years; it's incredible that this is still not properly documented as part of the AWS tutorials (or relative blogs).

like image 263
OneMoreNerd Avatar asked Dec 05 '19 11:12

OneMoreNerd


People also ask

How do you create a role in CodePipeline?

Sign in to the AWS Management Console and open the CodePipeline console at http://console.aws.amazon.com/codesuite/codepipeline/home . Choose Create pipeline and complete the Step 1: Choose pipeline settings page in the pipeline creation wizard. After you create a pipeline, you cannot change its name.

What permissions do I need to use codedeploy?

These permissions are provided by the CodeDeploy IAM role ( ecsCodeDeployRole ). IAM users also require permissions to use CodeDeploy; these permissions are described in Blue/green deployment required IAM permissions . There are two managed policies provided.

When should I add the IAM passrole permission to codedeploy?

If the tasks in your Amazon ECS service using the blue/green deployment type require the use of the task execution role or a task role override, then you must add the iam:PassRole permission for each task execution role or task role override to the CodeDeploy IAM role as an inline policy.

Why is my CodePipeline role missing codedeploy permissions?

This error suggests the CodePipeline role is missing "codedeploy:" related permissions. to the role and try again. If you do not want to add all CodeDeploy permissions, you will need to investigate 'AccessDenied' calls in Cloudtrail and allow just those. Usually these are the required ones:

How do I add permissions to my codebuild service role policy?

To add permissions to your CodeBuild service role policy, you create a customer-managed policy that you attach to your CodeBuild service role. The following steps create a policy where the UseConnection permission is specified in the action field, and the connection ARN is specified in the Resource field.


Video Answer


1 Answers

"The provided role does not have sufficient permissions to access CodeDeploy"

This error suggests the CodePipeline role is missing "codedeploy:" related permissions.

Can you please add

codedeploy:*

to the role and try again.

If you do not want to add all CodeDeploy permissions, you will need to investigate 'AccessDenied' calls in Cloudtrail and allow just those. Usually these are the required ones:

{
      "Action": [
        "codedeploy:CreateDeployment",
        "codedeploy:GetApplicationRevision",
        "codedeploy:GetApplication",
        "codedeploy:GetDeployment",
        "codedeploy:GetDeploymentConfig",
        "codedeploy:RegisterApplicationRevision"
      ],
      "Resource": "*",
      "Effect": "Allow"
    },

The default "CodePipeline Service Role Policy" is documented here:

[1] Manage the CodePipeline Service Role - Review the Default CodePipeline Service Role Policy - https://docs.aws.amazon.com/codepipeline/latest/userguide/how-to-custom-role.html#view-default-service-role-policy

like image 117
shariqmaws Avatar answered Oct 07 '22 07:10

shariqmaws