PULP-1179: Restrict unauthenticated PyPI access to public- domains (using Serena)#926
Open
PULP-1179: Restrict unauthenticated PyPI access to public- domains (using Serena)#926
Conversation
…public- domains. This implements PULP-1179 by adding a new permission class that only allows unauthenticated GET/HEAD/OPTIONS requests to domains whose names start with the 'public-' prefix (case-sensitive). PyPI endpoints now use this permission instead of AllowUnauthPull to restrict public read access. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
Reviewer's GuideImplements a new PublicDomainReadPermission to allow unauthenticated safe-method access only for PyPI distributions in domains whose names start with 'public-', wires this into the readonly PyPI endpoints via patch 0038, adds functional tests covering the permission behavior and case sensitivity, and updates the Docker image to apply an additional Python content endpoint patch (0042). Sequence diagram for unauthenticated access to PyPI endpoint with PublicDomainReadPermissionsequenceDiagram
actor Client
participant PyPIEndpointView
participant PublicDomainReadPermission
participant get_domain_pk
participant DomainModel as Domain
Client->>PyPIEndpointView: HTTP request (method, path, headers)
PyPIEndpointView->>PublicDomainReadPermission: has_permission(request, view)
PublicDomainReadPermission->>PublicDomainReadPermission: check request.method in SAFE_METHODS
alt method_not_safe
PublicDomainReadPermission-->>PyPIEndpointView: False
PyPIEndpointView-->>Client: 403 Forbidden
else method_safe
PublicDomainReadPermission->>get_domain_pk: __call__()
alt domain_context_missing
get_domain_pk-->>PublicDomainReadPermission: raises LookupError
PublicDomainReadPermission-->>PyPIEndpointView: False
PyPIEndpointView-->>Client: 403 Forbidden
else domain_context_available
get_domain_pk-->>PublicDomainReadPermission: domain_pk
PublicDomainReadPermission->>DomainModel: objects.get(pk=domain_pk)
alt domain_not_found
DomainModel-->>PublicDomainReadPermission: raises DoesNotExist
PublicDomainReadPermission-->>PyPIEndpointView: False
PyPIEndpointView-->>Client: 403 Forbidden
else domain_found
DomainModel-->>PublicDomainReadPermission: domain(name)
alt name_starts_with_public_prefix
PublicDomainReadPermission-->>PyPIEndpointView: True
PyPIEndpointView-->>Client: 200 OK (unauthenticated)
else name_without_public_prefix
PublicDomainReadPermission-->>PyPIEndpointView: False
PyPIEndpointView-->>Client: 403 Forbidden
end
end
end
end
Class diagram for PublicDomainReadPermission and related authorization classesclassDiagram
class BasePermission {
<<abstract>>
+has_permission(request, view) bool
}
class AllowUnauthPull {
+has_permission(request, view) bool
}
class PublicDomainReadPermission {
+has_permission(request, view) bool
}
class Domain {
+pk int
+name str
+objects
}
class DomainManager {
+get(pk int) Domain
}
class Logger {
+debug(message str)
+warning(message str)
+error(message str)
}
class SAFE_METHODS {
+methods list
}
class get_domain_pk {
+__call__() int
}
BasePermission <|-- AllowUnauthPull
BasePermission <|-- PublicDomainReadPermission
Domain o-- DomainManager : objects
PublicDomainReadPermission ..> Domain : fetches
PublicDomainReadPermission ..> DomainManager : uses
PublicDomainReadPermission ..> Logger : logs
PublicDomainReadPermission ..> SAFE_METHODS : checks
PublicDomainReadPermission ..> get_domain_pk : obtains_domain_context
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
PublicDomainReadPermissioncatches broadExceptionin multiple places and logs withwarning/error; consider using more specific exception types orlogger.exceptionwhere appropriate so you preserve tracebacks and make debugging permission failures easier. - The four new authentication tests are very similar in their setup (user, domain, repo, distribution); consider extracting a shared helper/fixture or parametrizing the tests to reduce duplication and make future changes to the setup less error-prone.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `PublicDomainReadPermission` catches broad `Exception` in multiple places and logs with `warning`/`error`; consider using more specific exception types or `logger.exception` where appropriate so you preserve tracebacks and make debugging permission failures easier.
- The four new authentication tests are very similar in their setup (user, domain, repo, distribution); consider extracting a shared helper/fixture or parametrizing the tests to reduce duplication and make future changes to the setup less error-prone.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Member
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements PULP-1179 to restrict unauthenticated GET/HEAD/OPTIONS requests to only domains whose names start with the
public-prefix (case-sensitive).Changes
Added
PublicDomainReadPermissionclass inpulp_service/app/authorization.pypublic-(case-sensitive)Updated patch 0038 to use
PublicDomainReadPermissioninstead ofAllowUnauthPullDomainBasedPermissionAdded comprehensive tests in
test_authentication.py:public-works)Backward Compatibility
This is an additive change.
AllowUnauthPullremains unchanged and functional. Only PyPI endpoints are affected by the new permission class.Test plan
🤖 Generated with Claude Code
Summary by Sourcery
Restrict unauthenticated PyPI read access to explicitly public domains and tighten domain-based authorization behavior.
New Features:
Enhancements:
Build:
Tests: