CodePipeline -> CodeDeploy blue/green ECS Insufficient permissions

0

I'm trying to set up CodePipeline to do a blue/green CodeDeploy in a different account. I've been following the documentation at https://docs.aws.amazon.com/codepipeline/latest/userguide/pipelines-create-cross-account.html and https://docs.aws.amazon.com/AmazonECS/latest/developerguide/codedeploy_IAM_role.html

So far the CodeDeploy deployment works in the deployment account, but I cannot get the Pipeline step to invoke it.

I have three IAM roles involved. In the build account the CodePipeline role has permission to assume the Deployment role in the deployment account. The Deployment role has permission to invoke CodeDeploy and read the shared S3 bucket and KMS key (both are held in the build account and have policies allowing the deployment account access). The CodeDeploy role has all the permissions documented to do a blue/green deployment.

The only error I get is "Insufficient permissions
The provided role does not have sufficient permissions to access CodeDeploy", but the role passed in to CodePipeline has full access to CodeDeploy. There must be a permission I'm missing but given the lack of information I cannot figure out what it is.

질문됨 5년 전1544회 조회
3개 답변
0

After more investigation I've found the API event in CloudTrail. It's getting

{  [...]
    "errorCode": "AccessDenied",
    "errorMessage": "User: arn:aws:sts::xxxx:assumed-role/codedeploy_pipeline_xxxx_test/xxxx is not authorized to perform: codedeploy:GetApplication on resource: arn:aws:codedeploy:ap-southeast-2:xxxx:application:xxxx-test",
}

but the IAM policy document for that role contains

        {
            "Action": [
                "codedeploy:*"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },

It was more restrictive but I added the wildcard to try to debug. The policy simulator says GetApplication should work.

답변함 5년 전
0

After even more digging through CloudTrail I discovered the root was a missing iam:PassRole for the ECS container role. This was present on the CodeDeploy role but not on the role passed to CodePipeline to invoke CodeDeploy. The final policy for the CodeDeploy role is

{
  "Version": "2012-10-17",
  "Statement": [
    {
        "Action": [
            "codedeploy:CreateDeployment",
            "codedeploy:GetDeployment",
            "codedeploy:GetDeploymentConfig",
            "codedeploy:GetApplicationRevision",
            "codedeploy:RegisterApplicationRevision",
            "codedeploy:GetApplication",
            "ecs:RegisterTaskDefinition"
        ],
        "Resource": "*",
        "Effect": "Allow"
    },
    {
        "Action": [
            "s3:GetObject*",
            "s3:PutObject",
            "s3:PutObjectAcl"
        ],
        "Resource": "arn:aws:s3:::deployment_intermediate_bucket/*",
        "Effect": "Allow"
    },
    {
        "Action": [ "s3:ListBucket"],
        "Resource": "arn:aws:s3:::deployment_intermediate_bucket",
        "Effect": "Allow"
    },
    {
        "Effect": "Allow",
        "Action": [
            "kms:DescribeKey",
            "kms:GenerateDataKey*",
            "kms:Encrypt",
            "kms:ReEncrypt*",
            "kms:Decrypt"
        ],
        "Resource": [
            "${var.deployment_kms_key_arn}"
        ]
    },
    {
        "Action": [
            "iam:PassRole"
        ],
        "Effect": "Allow",
        "Resource": "ecs_container_role_arn"
    }
  ]
}

I'm going to try to lock this down some more, in particular the PassRole. The condition string used on the CodeDeploy side didn't seem to work, but I may have entered it wrong.

Edited by: phillipion on Jun 27, 2019 3:54 PM

답변함 5년 전
0

How did it go?

답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠