How to access AWS ECR from Azure DC/OS Container Service - amazon-web-services

I am trying to use our ECR to launch instances on Azure DC/OS Container service. I used ssh to login to master on Azure and install awscli there I can execute aws ecr get-login --no-include-email on master and get the docker login ... command that I am supposed to execute. When I do it, nothing happens. I did echo $? afterwards and I get status code 1. That means something went wrong. AWS user access key and secret access key that I am using, have policy permissions ecr:GetAuthorizationToken assigned to it.
Anyone have experience with this or can point me in the right direction? Last resort is to replicate AWS ECR to Azure ACR.

Related

AWS Public Repository Push Image issue

I have created one ECR repository as public. Now, from my on-premises docker server, I build the image and I wanted to push the image in AWS ECR as public image. AWS has given option view push option but It did not work, getting below error while running the below command.
**docker login -u AWS -p $(aws ecr get-login-password --region ap-northeast-2)
public.ecr.aws/m8r0s3o9**
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: login attempt to https://public.ecr.aws/v2/ failed with status: 400 Bad Request
For private repository it works fine for me.
Any suggestion would be highly appreciable, do i need to add any role/policy to my aws user?
Thanks for your feedback guidance.
I found the issue, I was referring "view push command instructions" where respective region show in the command.
But for public repository need to run below command always.
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/<your repo name>
so in short, When authenticating to a public registry, always authenticate to the us-east-1 Region when using the AWS CLI.
It resolved my issue and i was able to push the docker images in ECR. Rest command are same.

Does anyone have a sample buildspec for pushing single built docker image into two different ECR on different AWS accounts?

Can this be done and would I need to login twice in the buildspec?
Looking at completing a build, then on success, to push this image to the same account, as well as two other accounts. Anyone have or know if this can be done within the buildspec?
if this can be done within the buildspec
it lets you define any commands, and all you need console commands. So i would say - yes.
To push image into the AWS ECR you need to execute command docker login .....
which uses token. but there is a aws ecr get-login command which can help you with it.
so you need to have installed and configured aws ecr and then you can do this to login you docker into ecr:
$(aws ecr get-login --no-include-email --region {your ECR region})
after that you can do docker push imagename:latest
repeat 1-2 steps as many times as you need.
cleanup local mess.

"no basic auth credentials" when trying to pull an image from a private ECR

I have the following line somewhere in the middle of my Dockerfile to retrieve an image from my private ECR.
FROM **********.dkr.ecr.ap-southeast-1.amazonaws.com/prod/*************:ff03401
This is the error that I get in AWS Codebuild when trying to build this:
Step 21/36 : FROM **********.dkr.ecr.ap-southeast-1.amazonaws.com/prod/*************:ff03401
Get https://**********.dkr.ecr.ap-southeast-1.amazonaws.com/prod/*************/manifests/ff03401: no basic auth credentials
How can one provide these credentials in the most secure way, and in a way that can also be terraformed?
There are multiple ways to do it.
Using aws access and secret key. In which you set the aws credentials on the ec2 machine and run ecr login command. aws ecr get-login --no-include-email --registry-ids <some-id> --region eu-west-1 and then docker pull should work. But this is not a recommended secure way.
What I prefer is using aws iam roles.
Assuming you want to pull this image on your ec2 machine that was brought up using terraform. Make use of iam roles.
Create an iam role manually or using terraform iam resource.
For contents of iam policy refer this.
While bringing ec2 using terraform instance resource make use of iam_instance_profile attribute, the value of this attribute should be the name of iam role you created.
This should be enough to automatically pull docker images from ECR in a secure way.
Hope this helps.

AWS Windows Powershell ECR Login

I am new to AWS and Docker. I am trying to setup AWS ECR and docker and trying to retrieve ECR Login using windows powershell. I am trying to use the command -
Invoke-Expression -Command (aws ecr get-login)
which gives me the error
My problem is it is trying to use the ccuser on its own. I don't think I have configured it to use this user. I have created a separate user with AmazonEC2ContainerRegistryFullAccess. How do I configure this as the user for AWS Powershell to execute the command?
aws ecr get-login will simply use the creds that you've already setup for the AWS CLI. If you want to change the creds for the CLI, use aws configure to do the setup again, it will ask you for:
AWS Access Key ID []:
AWS Secret Access Key []:
Default region name []:
Default output format []:
If you only want to use that user temporarily without reconfiguring your existing account, here are the docs for doing that.
simple and easy, I was debugging this for while but somehow it worked
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin ecr.amazonaws.com

Pull images from AWS ECR on AWS EC2 without using docker login but using EC2 Instance role and ECR repository permissions

Can we pull images from AWS ECR Repository on an AWS EC2 instance running docker assigning AWS EC2 instance role/policy and AWS ECR Repository permission that provides access to ECR.
I have currently provided all permissions but the error I am getting is "unauthorized: authentication required".
Let me know if this is possible.
you can actually skip the docker login step, even aws ecr get-token which still did the docker login, using ecr credential helper.
with the helper, just config the docker:
{
"credHelpers": {
"aws_account_id.dkr.ecr.region.amazonaws.com": "ecr-login"
}
}
refer to: https://lwpro2.wordpress.com/2019/10/30/authenticating-amazon-ecr-repositories-for-docker-cli-with-credential-helper/
Run the below command in your cron and cron will refresh your login credentials.
COMMAND=`eval aws ecr get-login --region us-west-2`
echo `eval $COMMAND`
So you can avoid any login to ecr itself and access seamlessly all the time.