Fix cache scope validation for org-level tokens #2
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
Testing
uv run pytest(fails: missing optional dependencies such as httpx, yaml, structlog, fastapi, redis, pydantic, hypothesis during collection)https://chatgpt.com/codex/tasks/task_e_68f52e796df48326a86cf7159d30a4d9
Greptile Overview
Updated On: 2025-10-31 05:45:19 UTC
Greptile Summary
Reordered the cache scope validation logic in
validate_cache_scopeto prioritize organization-wide scopes over repository-specific scopes, enabling tokens with org-level permissions (e.g.,pull:org-1) to access any repository within their organization.Key changes:
pull:org-{id}) to execute before repo-specific scope check, fixing the previous issue where org-wide tokens were incorrectly denied when a repository parameter was providedtest_manifest_roundtripto verify org-wide scoped tokens can access repositories without requiring repo-specific scope suffixesPermission hierarchy verified:
read_write,read,write) continue to work as beforepull:org-1) grant access to all repos within the organizationpull:org-1/demo) still restrict access to individual reposConfidence Score: 5/5
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant Client participant DockerCacheAPI participant validate_repository_access participant validate_cache_scope Client->>DockerCacheAPI: GET /v2/org-1/demo/manifests/latest Note over Client,DockerCacheAPI: Token has scope: pull:org-1,push:org-1 DockerCacheAPI->>validate_repository_access: Check access for org-1/demo validate_repository_access->>validate_repository_access: Verify org prefix matches token org_id Note over validate_repository_access: Extract repo_suffix = "demo" validate_repository_access->>validate_cache_scope: validate(operation="pull", org_id=1, repo="demo") Note over validate_cache_scope: Step 1: Check legacy scopes validate_cache_scope->>validate_cache_scope: read_write? read? write? Note over validate_cache_scope: Step 2: Check org-wide scope (NEW) validate_cache_scope->>validate_cache_scope: Is "pull:org-1" in scopes? Note over validate_cache_scope: Match found! validate_cache_scope-->>validate_repository_access: True validate_repository_access-->>DockerCacheAPI: Access granted DockerCacheAPI-->>Client: 200 OK