Return correct error code on failed authentication - #8005
Open
YakBizzarro wants to merge 2 commits into
Open
Conversation
Distinguish authentication failures (no/invalid credentials) from authorization failures (authenticated but not permitted) by introducing an AuthenticationRequired exception. This allows the content app to return HTTP 401 Unauthorized for requests that need authentication, enabling tools like pip to properly detect and retry with credentials. - RBACContentGuard catches NotAuthenticated and AuthenticationFailed → 401 - CompositeContentGuard re-raises authentication errors immediately - Handler maps AuthenticationRequired → HTTPUnauthorized (401) - Other PermissionErrors continue to map to HTTPForbidden (403) Fixes: content app returning 403 for all access denials regardless of auth state. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
test_rbac_content_guard_full_workflow asserted 403 for every unauthorized user, including the anonymous one, which matched the previous (buggy) behavior of the content app. Split the expectation so that: - authorized users still get 404 (no change) - the anonymous user (no credentials at all) now expects 401 - authenticated-but-unauthorized users still expect 403 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Similarly to #3730, if a user try to fetch a Python package wheel from a pulp private PyPI registry without authentication, Pulp returns 403 Forbidden instead of 401 Unauthorized as expected.
This PR address that, by adding a new error class
AuthenticationRequiredwhich is raised when not authenticated. In turn, this raise aaiohttp.web_exceptions.HTTPUnauthorizedwhich emits a 401 error as expected.Fixes #7994
AI assisted the creation of the patch, I manually verified the outcome.
📜 Checklist
See: Pull Request Walkthrough