-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
When OPA returns allow: false for an authenticated user, the application currently returns 401 Unauthorized. According to HTTP semantics, this should be 403 Forbidden:
- 401 Unauthorized: Authentication failed or missing credentials
- 403 Forbidden: Authenticated but not authorized to access the resource
Current Behavior
When a user is authenticated via OIDC but OPA denies the request based on policy rules, the response is:
{"message": "Unauthorized"}with status code 401.
Expected Behavior
The response should be:
{"message": "Forbidden"}with status code 403.
Root Cause
This is a limitation of the upstream fastapi-opa library, which uses 401 for both authentication failures and authorization denials.
Related
A PR has been opened to fix this in the upstream library:
Action Items
- Wait for the upstream fix to be merged and released
- Update
fastapi-opadependency once the fix is available - Update tests in
tests/test_opa_integration.pyto expect403instead of401
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request