Skip to content

Return correct error code on failed authentication - #8005

Open
YakBizzarro wants to merge 2 commits into
pulp:mainfrom
YakBizzarro:missing_auth_401
Open

Return correct error code on failed authentication#8005
YakBizzarro wants to merge 2 commits into
pulp:mainfrom
YakBizzarro:missing_auth_401

Conversation

@YakBizzarro

Copy link
Copy Markdown

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 AuthenticationRequired which is raised when not authenticated. In turn, this raise a aiohttp.web_exceptions.HTTPUnauthorized which emits a 401 error as expected.

Fixes #7994

AI assisted the creation of the patch, I manually verified the outcome.

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

YakBizzarro and others added 2 commits August 24, 2026 09:44
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pulpcore returns 403 instead of 401 on failed authentication

1 participant