-
Notifications
You must be signed in to change notification settings - Fork 300
Fixes #38424: correct response code of oauth2 token request to registry #11389
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
base: master
Are you sure you want to change the base?
Conversation
If oauth2 authentication (via POST request) is not supported, the registry should respond with code 404, but we currently respond with 415 (Unsupported Media Type). By disabling the media type check for the token endpoint, we will return 401 (unauthorized) instead, which is enough for some clients to then try the regular token authentication. Adding a custom before_action, we can achieve that 404 is returned, thus we are fully compliant with the spec: https://docker-docs.uclv.cu/registry/spec/auth/oauth/
Reviewer's GuideDisable media type validation and add a pre-filter on the token endpoint so that unsupported POST requests return 404, bringing OAuth2 token handling into spec compliance. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MartinSpiessl - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @MartinSpiessl!
I believe there's a more straight-forward way to make POST requests return 404s via our registry:
katello/config/routes/api/registry.rb
Line 9 in fc2993d
match '/v2/token' => 'registry_proxies#token', :via => :post |
If this line is removed, sending a POST to the token endpoint should result in a 404.
However, this makes me wonder why we have defined a POST endpoint for tokens if it does not work. It looks like the endpoint fails because our API only expects JSON input, not application/x-www-form-urlencoded.
It looks like it was added 7 years ago: #7249
I suppose either the standard changed at some point, or perhaps even the POST route snuck in without proper testing.
It would be nice to get this endpoint to work properly -- we might not be far away from a working implementation. I won't make that a requirement of this PR though. I'll at least make sure a redmine gets filed for it depending on the outcome of this PR.
To add to my review - is there a deeper end goal for some specific tool / client to work with our registry? |
@MartinSpiessl Do you mind coming back to this? |
Yes, sorry, I will look at it today, I had a bit of a pile up of todos here recently
For now the goal is to make it work with helm, where there are also other issues things I am currently investigating.
Thanks! Yes it would be great to have that end point work, but for now I would focus on get the registry work for helm, and I would treat the POST endpoint as an orthogonal issue.
Thanks, I will try that out and get back with an update to this PR. |
If oauth2 authentication (via POST request) is not supported, a container registry should respond with code 404, but we currently respond with 415 (Unsupported Media Type). By disabling the media type check for the token endpoint, we will return 401 (unauthorized) instead, which is enough for some clients to then try the regular token authentication. Adding a custom before_action, we can achieve that 404 is returned, thus we are fully compliant with the spec:
https://docker-docs.uclv.cu/registry/spec/auth/oauth/
What are the changes introduced in this pull request?
Considerations taken when implementing this change?
What are the testing steps for this pull request?
The following curl request can be used to test the response (replace foreman.example.com with your foreman instance, orgname with your orgname, productname with your product name for the container registry, and containername is arbitrary, as is username and password):
This will yield the following output:
With the fix applied the output is simply:
Summary by Sourcery
Ensure compliance with OAuth2 spec by returning 404 for unsupported POST requests to the /v2/token endpoint.
Bug Fixes:
Enhancements: