Skip to content

Use docker image from private ECR repository for codebuild windows server 2022 host

0

I try to setup AWS CodeBuild with a reserved capacity fleet using windows-server-2022. I use a custom docker image from a private ECR repository.

I have the issue that the runner setup fails during the provisioning phase printing only "CLIENT_ERROR: Unable to pull customer's container image". I have no more error information. Using docker cli locally on my normal machine, I can pull the image. As image pull credentials in CodeBuild I use the project service role. The permissions don't seem to be the issue. I attached an admin policy to the role without making any difference.

When using an Amazon provided image the privisioning phase completes successfully.

1 Answer
0

Hello.

Have you tried setting a resource-based policy in ECR?
Try setting the following resource-based policy in ECR to allow access from CodeBuild.
https://docs.aws.amazon.com/codebuild/latest/userguide/sample-ecr.html#:~:text=This%20policy%20is%20displayed%20in%20Permissions.%20The%20principal%20is%20what%20you%20entered%20for%20Principal%20in%20step%203%20of%20this%20procedure%3A

{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "CodeBuildAccessPrincipal",
            "Effect": "Allow",
            "Action": [
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr:BatchCheckLayerAvailability"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:SourceArn": "arn:aws:codebuild:us-east-1:111122223333:project/MyProject",
                    "aws:SourceAccount": "111122223333"
                }
            }
        },
        {
            "Sid": "CodeBuildAccessCrossAccount",
            "Effect": "Allow",
            "Action": [
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr:BatchCheckLayerAvailability"
            ],
            "Resource": "*"
        }
    ]
}

You can set this from the following screen in ECR.
a

EXPERT

answered 10 months ago

  • For testing I tried the following permissive policy, the behavior was equivalent, same error during the provisioning phase:

    { "Statement": [ { "Action": [ "ecr:" ], "Principal": "", "Effect": "Allow", "Sid": "new statement" } ], "Version": "2012-10-17" }

  • Have you set up a CloudTrail trail? If you have set it up, you can check the CloudTrail logs to see if access to ECR has failed, which may help you find the cause. https://docs.aws.amazon.com/AmazonECR/latest/userguide/logging-using-cloudtrail.html

  • The cloudTrail logs showed that there was no problem pulling the image. There was a version mismatch between the windows version used in the image vs the host.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.