fix(auth): require lightwell-network feature for lightwell domain's P…#1306
Merged
Conversation
…yPI reads DomainBasedPermission previously let any authenticated user with a valid identity header read the lightwell domain's PyPI views (simple API, package metadata), leaking proprietary package info to non-subscribers. SAFE_METHOD requests to those views now require either a DomainOrg association or the lightwell-network feature entitlement, checked against the Features Service using the same cache as FeatureContentGuard. public- domains, other domains' PyPI views, non-PyPI endpoints, and write operations are unaffected. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Reviewer's GuideAdds a lightwell-network feature gate for SAFE_METHOD access to the lightwell domain’s PyPI views, reusing FeatureContentGuard’s cache, and extends unit/functional tests to cover new authorization and caching behavior while keeping other domains and non-PyPI endpoints unchanged. Sequence diagram for SAFE_METHOD access to lightwell PyPI viewssequenceDiagram
actor User
participant PyPIView
participant DomainBasedPermission
participant FeatureContentGuard
participant FeatureContentGuardCache
participant FeaturesService
User->>PyPIView: HTTP GET /pypi/simple (lightwell)
PyPIView->>DomainBasedPermission: has_permission(request, view)
DomainBasedPermission->>DomainBasedPermission: _check_pypi_safe_method_access(request, view, domain)
DomainBasedPermission->>DomainBasedPermission: _has_pypi_read_access(request, domain)
DomainBasedPermission->>DomainBasedPermission: get_decoded_identity_header(request)
DomainBasedPermission->>DomainBasedPermission: get_org_id(decoded_header_content)
alt user has DomainOrg
DomainBasedPermission-->>PyPIView: allow
else no DomainOrg
DomainBasedPermission->>DomainBasedPermission: _has_lightwell_network_feature(org_id)
DomainBasedPermission->>FeatureContentGuard: check_feature(org_id)
FeatureContentGuard->>FeatureContentGuardCache: _get_cached_result(cache, cache_key_digest)
alt cache MISS
FeatureContentGuard->>FeaturesService: _check_for_feature(org_id)
FeaturesService-->>FeatureContentGuard: feature result
FeatureContentGuard->>FeatureContentGuardCache: _set_cached_result(cache, cache_key_digest, account_allowed)
else cache HIT
end
FeatureContentGuard-->>DomainBasedPermission: account_allowed
alt account_allowed
DomainBasedPermission-->>PyPIView: allow
else not allowed
DomainBasedPermission-->>PyPIView: deny
end
end
PyPIView-->>User: HTTP response
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 helper for building an x-rh-identity header (
_encode_identity_header/_identity_header) is duplicated across unit and functional tests; consider moving this into a shared test utility to avoid divergence in how identities are constructed. - The
LIGHTWELL_DOMAIN_NAMEconstant is redefined inauthorization.py,test_lightwell_feature_permission.py, and implied in comments elsewhere; importing it from a single source instead of using a string or local constant in tests would reduce the risk of subtle drift if the domain name ever changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The helper for building an x-rh-identity header (`_encode_identity_header` / `_identity_header`) is duplicated across unit and functional tests; consider moving this into a shared test utility to avoid divergence in how identities are constructed.
- The `LIGHTWELL_DOMAIN_NAME` constant is redefined in `authorization.py`, `test_lightwell_feature_permission.py`, and implied in comments elsewhere; importing it from a single source instead of using a string or local constant in tests would reduce the risk of subtle drift if the domain name ever changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
… test Fixes ruff S113 violation flagged by CI. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
DomainBasedPermission previously let any authenticated user with a valid identity header read the lightwell domain's PyPI views (simple API, package metadata), leaking proprietary package info to non-subscribers. SAFE_METHOD requests to those views now require either a DomainOrg association or the lightwell-network feature entitlement, checked against the Features Service using the same cache as FeatureContentGuard. public- domains, other domains' PyPI views, non-PyPI endpoints, and write operations are unaffected.
Summary by Sourcery
Tighten authorization for the lightwell domain’s PyPI views by requiring either a domain association or a lightwell-network feature entitlement, and reuse the FeatureContentGuard cache for this check.
Bug Fixes:
Enhancements:
Documentation:
Tests: