Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the Authorization header for Basic Authentication is valid #1589

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
18 changes: 9 additions & 9 deletions pulp_container/app/token_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ 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):
"""
Perform basic authentication with the exception to accept empty credentials.
For anonymous user, Podman sends 'Authorization': 'Basic Og=='.
This represents ":" in base64.
If basic authentication could not success, remote webserver authentication is considered.
"""
if request.headers.get("Authorization") == "Basic Og==":
return (AnonymousUser, None)

try:
return super().authenticate(request)
user = 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 user is None and self.ALLOWS_REMOTE_AUTHENTICATION:
return RemoteUserRegistryAuthentication().authenticate(request)
else:
return user


class RemoteUserRegistryAuthentication(RemoteUserAuthentication):
"""
Expand Down
Loading