Open aoyama-val opened 5 months ago
@aoyama-val can you check that the role stored in AWS_IAM_ROLE_ARN
has permissions to push to that ECR repo?
If you have permissions, but it still not working, can you list the permissions associated to that role?
The role has these permissions at least:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ecr:BatchCheckLayerAvailability",
"Resource": [
"arn:aws:ecr:*****"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"ecr:CompleteLayerUpload",
"ecr:UploadLayerPart",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:BatchGetImage"
],
"Resource": [
"arn:aws:ecr:*****"
]
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "ecr:GetAuthorizationToken",
"Resource": "*"
}
]
}
The config was working fine with aws-ecr@8.2.1 + aws-cli@3.1.4, however I faced the issue when tried to upgrade the orbs.
Thanks.
I added Allow All permission to the role, but still push failed with the same error.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
]
}
Also I changed the auth method from OIDC to access key/secret, and it worked fine. So I guess something about OIDC is wrong.
@aoyama-val what is the definition for the role that you are using for OIDC? Pay special attention at the Condition
section
Carefully checked it but everything seemed correct. Also tried deleting the whole Condition
, but nothing changed.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::XXXXXXXXXXXX:oidc-provider/oidc.circleci.com/org/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
},
"Action": "sts:AssumeRoleWithWebIdentity"
}
]
}
I'm facing the same problem. I've been using version 9.0.1 and it was working, but as soon as I upgraded to 9.1.0 it's no longer working.
It happens on the attempt to push the image.
#10 ERROR: failed to push ************.dkr.ecr.*********.amazonaws.com/***: unexpected status from HEAD request to https://************.dkr.ecr.*********.amazonaws.com/v2/***: 401 Unauthorized
Same issue, starting v9.0.3
Confirm downgrading to v9.0.1 fix the issue
This is more likely a problem with the aws-cli orb, could you do a aws-cli/setup command alone and validate the authentication worked?
You can do something like this:
- aws-cli/setup:
role_arn: ${ROLE_ARN}
post-steps:
- run:
name: "Validation"
command: aws sts get-caller-identity
A combination of versions that should work using OIDC is: circleci/aws-cli@5.1.0 and circleci/aws-ecr-orb@9.3.0. Please check if it works using these versions.
auth:
shouldn't be required if it's already set previously.
@sylwit That's right, the auth shouldn't be required. Is that causing something related to his issue?
Hello, we face the same issue trying to migrate from circleci/aws-ecr@8.2
to circleci/aws-ecr@9.3.2
with the new auth parameter.
unexpected status from HEAD request... : 401 Unauthorized
Did you guys find a fix? We cannot understand how to do the migration correctly.
@b-jan how are you doing the authentication to ECR? Are you enabling credentials helper?
Thanks @marboledacci,
We fixed our issue by adding these parameters :
use_credentials_helper: false
extra_build_args: '--provenance=false'
We added extra_build_args: '--provenance=false'
to fix this issue.
@aoyama-val were you able to resolve this issue? I'm facing the same situation after updating.
If you just want things to work the way they did before, wherever you use aws-cli/setup
, explicitly export the credential values:
- aws-ecr/build_and_push_image:
auth:
- aws-cli/setup:
role_arn: arn:aws:iam::<account_id>:role/role_name
- run:
name: "Export AWS credentials"
command: |
echo "export AWS_ACCESS_KEY_ID=$AWS_CLI_STR_ACCESS_KEY_ID" >> $BASH_ENV
echo "export AWS_SECRET_ACCESS_KEY=$AWS_CLI_STR_SECRET_ACCESS_KEY" >> $BASH_ENV
echo "export AWS_SESSION_TOKEN=$AWS_CLI_STR_SESSION_TOKEN" >> $BASH_ENV
- run:
name: "Validation"
command: aws sts get-caller-identity
...
This is due to changes in the aws-cli
orb in which it no longer exports the environment variables with their standard names. It is supposed to set up a config profile instead, but for whatever reason that wasn't working for me. They also do this to prevent issues with multiple credentials in a single job, so if you need that, be aware this may mess things up.
I also added a validation step to make sure this is actually succeeding and not pushing the issue down the road after doing a whole Docker image build.
Orb version
9.1.0
What happened
Expected behavior
Push succeeds.