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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem where a wrong realm is found in www-authenticate #88

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

t-persson
Copy link
Collaborator

Applicable Issues

fixes: eiffel-community/etos#286

Description of the Change

The token cache returned an invalid token for the container registry and when using that token on the first request we got an incorrect realm in the www-authenticate header.
If that happens we will now invalidate the cache and do a HEAD request without a token to get a proper www-authenticate.
I also added an expiration modifier so that we expire the tokens in the cache before they expire on the container registry side.
Added a few variable verifications and type hinting that my editor complained about.

Alternate Designs

We thought about removing the cache entirely but we are not sure if there are rate limits on certain container registries or not and decided to just retry the authentication if it fails.

Possible Drawbacks

We will, in some cases, do one more request to the container registry but a single extra request should not happen and this bug does not happen that often.

Sign-off

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

Signed-off-by: Tobias Persson [email protected]

The token cache returned an invalid token for the container registry
and when using that token on the first request we got an incorrect
realm in the www-authenticate header.
If that happens we will now invalidate the cache and do a HEAD
request without a token to get a proper www-authenticate.
@t-persson t-persson requested a review from a team as a code owner October 15, 2024 13:25
@t-persson t-persson requested review from fredjn and andmat900 and removed request for a team October 15, 2024 13:25
url.startswith("http://") or url.startswith("https://")
):
raise ValueError(f"No realm URL found in www-authenticate header: {response.headers}")
url = parameters.pop("realm")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we explicitly need to get rid of 'realm', or why do we pop()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the way parameters is used later we add them to the query separately

@t-persson t-persson merged commit 1296b80 into eiffel-community:main Oct 16, 2024
5 checks passed
@t-persson t-persson deleted the fix-docker-digest branch October 16, 2024 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Frequent fails in testrunner validation
2 participants