Skip to content

Commit

Permalink
Check if the Authorization header for Basic Authentication is valid
Browse files Browse the repository at this point in the history
If the header is not valid, DRF returns None when calling the
authenticate() method. This can cause troubles when users are
leveraging the remote authentication because Pulp thinks they
are using anonymous tokens. In the end, authorized users cannot
push or pull content from Pulp.

closes pulp#1577
  • Loading branch information
lubosmj committed Apr 13, 2024
1 parent f377a9c commit 51ed1c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/1577.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug that disallowed users from leveraging the remote authentication.
12 changes: 9 additions & 3 deletions pulp_container/app/token_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ class RegistryAuthentication(BasicAuthentication):
A basic authentication class that accepts empty username and password as anonymous.
"""

PULP_AUTHENTICATION_CLASS = "pulpcore.app.authentication.PulpRemoteUserAuthentication"
PULP_REMOTE_AUTHENTICATION_CLASS = "pulpcore.app.authentication.PulpRemoteUserAuthentication"
AUTH_CLASSES = settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"]
ALLOWS_REMOTE_AUTHENTICATION = PULP_REMOTE_AUTHENTICATION_CLASS in AUTH_CLASSES

def authenticate(self, request):
"""
Expand All @@ -80,13 +81,18 @@ def authenticate(self, request):
return (AnonymousUser, None)

try:
return super().authenticate(request)
result = super().authenticate(request)
except AuthenticationFailed:
if self.PULP_AUTHENTICATION_CLASS in self.AUTH_CLASSES:
if self.ALLOWS_REMOTE_AUTHENTICATION:
return RemoteUserRegistryAuthentication().authenticate(request)
else:
raise

if result is None and self.ALLOWS_REMOTE_AUTHENTICATION:
return RemoteUserRegistryAuthentication().authenticate(request)
else:
return result


class RemoteUserRegistryAuthentication(RemoteUserAuthentication):
"""
Expand Down

0 comments on commit 51ed1c3

Please sign in to comment.