Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: OCI registry with AWS ECR #3043

Closed
1 task done
thepabloaguilar opened this issue May 3, 2024 · 9 comments
Closed
1 task done

[Bug]: OCI registry with AWS ECR #3043

thepabloaguilar opened this issue May 3, 2024 · 9 comments
Labels

Comments

@thepabloaguilar
Copy link
Contributor

Bug Description

Hi guys, it's me (again 馃槅)! I've found something with the ECR integration that I was unable to see while the auth token doesn't expire and now with a stable deployment I started to see it.

The thing is, using the aws-sdk is indeed working to get the authorization token but when the token expires it doens't get refreshed by oras and the reason is simple, the returned error by the ECR API is:

response status code 403: denied: Your authorization token has expired. Reauthenticate and try again.

The response returned a 403 and not a 401, the key difference is: 401 returns the auth challange (Www-Authenticate header) and 403 don't! So we never get re-authenticadet again because oras only will call the credentials function if a challange is returned.

Version Info

v1.41.1

Search

  • I searched for other open and closed issues before opening this

Steps to Reproduce

Configures a Flipt instance using OCI with AWS ECR and wait the auth token to expire!

Expected Behavior

After the token expires it should be able to re-authenticated again!

Additional Context

No response

@thepabloaguilar
Copy link
Contributor Author

A possible solution to this problem is:

  • Disable cache when aws-ecr is chosen as we know the ECR API will always return a 403 when to token has expired
  • Modify the ECR struct to keep track when the token expire and renew the auth token some minutes before

@thepabloaguilar
Copy link
Contributor Author

I could work on this if needed

@thepabloaguilar
Copy link
Contributor Author

In fact it doesn't reach the challange piece of code, oras has this check:

if resp.StatusCode != http.StatusUnauthorized {
    return resp, nil
}

Source

In this bug the response status is "Forbidden" which will make the if statement condition to pass

@thepabloaguilar thepabloaguilar changed the title [Bug]: OCI reigstry with AWS ECR [Bug]: OCI registry with AWS ECR May 3, 2024
@erka
Copy link
Collaborator

erka commented May 3, 2024

Hey @thepabloaguilar.

Thank you for the report.

I still need to read more AWS docs when http code 403 could be returned to finalize it. What do you think about #3044?

@markphelps
Copy link
Collaborator

In fact it doesn't reach the challange piece of code, oras has this check:

if resp.StatusCode != http.StatusUnauthorized {
    return resp, nil
}

Source

In this bug the response status is "Forbidden" which will make the if statement condition to pass

@thepabloaguilar thanks for reporting! would this be a bug in ORAS then that we could open/issue a patch for? or do you think its only related to how we are using the ORAS client?

@thepabloaguilar
Copy link
Contributor Author

That's a great question @markphelps, I think it's not ORAS issue since it's behaving as it should be as the challange is only returned by Forbidden status code. I do think it's an AWS Issue, at least for my understanding because I think if my token is expired I'm not forbbiden, I'm unauthorized, I no longer have a valid token so I don't have access to anything

@markphelps
Copy link
Collaborator

Hey @thepabloaguilar.

Thank you for the report.

I still need to read more AWS docs when http code 403 could be returned to finalize it. What do you think about #3044?

I like @erka 's solution here! Just need to update to add the header like @thepabloaguilar mentioned

@thepabloaguilar
Copy link
Contributor Author

Me too @markphelps, that should be enough

@thepabloaguilar
Copy link
Contributor Author

Fixed by the @erka PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

3 participants