Skip to content

Commit b1c5d70

Browse files
committed
Check if the Authorization header for Basic Authentication is valid
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 anonymous users. In the end, authorized users cannot push or pull content from Pulp. This affects only admin users in scenarios where the token authentication is disabled. closes pulp#1577
1 parent e040992 commit b1c5d70

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGES/1577.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a bug that disallowed users from leveraging the remote authentication.

pulp_container/app/token_verification.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,29 @@ class RegistryAuthentication(BasicAuthentication):
6464
A basic authentication class that accepts empty username and password as anonymous.
6565
"""
6666

67-
PULP_AUTHENTICATION_CLASS = "pulpcore.app.authentication.PulpRemoteUserAuthentication"
67+
PULP_REMOTE_AUTHENTICATION_CLASS = "pulpcore.app.authentication.PulpRemoteUserAuthentication"
6868
AUTH_CLASSES = settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"]
69+
ALLOWS_REMOTE_AUTHENTICATION = PULP_REMOTE_AUTHENTICATION_CLASS in AUTH_CLASSES
6970

7071
def authenticate(self, request):
7172
"""
7273
Perform basic authentication with the exception to accept empty credentials.
7374
74-
For anonymous user, Podman sends 'Authorization': 'Basic Og=='.
75-
This represents ":" in base64.
76-
7775
If basic authentication could not success, remote webserver authentication is considered.
7876
"""
79-
if request.headers.get("Authorization") == "Basic Og==":
80-
return (AnonymousUser, None)
81-
8277
try:
83-
return super().authenticate(request)
78+
user = super().authenticate(request)
8479
except AuthenticationFailed:
85-
if self.PULP_AUTHENTICATION_CLASS in self.AUTH_CLASSES:
80+
if self.ALLOWS_REMOTE_AUTHENTICATION:
8681
return RemoteUserRegistryAuthentication().authenticate(request)
8782
else:
8883
raise
8984

85+
if user is None and self.ALLOWS_REMOTE_AUTHENTICATION:
86+
return RemoteUserRegistryAuthentication().authenticate(request)
87+
else:
88+
return user
89+
9090

9191
class RemoteUserRegistryAuthentication(RemoteUserAuthentication):
9292
"""

0 commit comments

Comments
 (0)