Reputation: 1369
I have one question related to AWS ECR and IAM, (I tried to search on internet but didn’t find any satisfactory explanation to me).
Scenario:
my-test-repo
) created under ECR, and I have some images already pushed in it.my-ecr-policy
) which is having all the permissions defined on this ECR resourcemy-ecr-ec2-role
) for which EC2 is trusted entity and having permission attached as IAM policy created above(my-ecr-policy
)my-ecr-ec2-role
) to EC2 instanceBut the docker pull command(on EC2 instance) failed with the error below. From the error It seems that docker login
is still required even when IAM role is attached with this EC2 instance.
ubuntu@ip-90-90-52-12:~$ docker pull <aws-account-id>.dkr.ecr.us-west-2.amazonaws.com/my-test-repo:v999
Error response from daemon: Head "https://<aws-account-id>.dkr.ecr.us-west-2.amazonaws.com/v2/my-test-repo/manifests/v999": no basic auth credentials
My Question :
If any EC2 instance is having IAM role (the role is having EC2 as trusted entity and having permissions to access ECR), then still the docker login is required before doing pull, If yes then what is the purpose of IAM in case of ECR access as I still need to do docker login
with the secrets provided by aws ecr get-login-password
.
Upvotes: 1
Views: 2144
Reputation: 1
If you have an EC2 instance with an IAM role that has the necessary permissions to access Amazon Elastic Container Registry (ECR), you should be able to access ECR without providing any explicit authentication credentials (e.g., access key, secret key, session token).
In this case, you don't need to use aws ecr get-login-password command to generate temporary credentials and run docker login command. Instead, you can use the docker CLI directly to pull images from ECR. The docker CLI should automatically retrieve the necessary credentials from the EC2 instance's IAM role.
However, if you are still being prompted for authentication when you try to pull images from ECR, there may be a misconfiguration in your IAM role or ECR permissions. You can try checking the following:
Upvotes: 0