Skip to content

Part 2: Add claim-scoped admin management for sources and registries - #650

Merged
blkt merged 4 commits into
mainfrom
claim-scoped-admin
Apr 2, 2026
Merged

blkt merged 4 commits into
mainfrom
claim-scoped-admin

Conversation

@rdimitrov

Copy link
Copy Markdown
Member

Summary

Enforces JWT claim-based authorization on all admin CRUD operations for sources and registries, completing the v2 authorization model for admin APIs.

  • Source write-path: CreateSource/UpdateSource validate request claims ⊆ caller JWT. UpdateSource/DeleteSource validate caller JWT covers the existing source's claims.
  • Source read-path: ListSources filters to sources within the caller's claim boundary. GetSourceByName returns 404 (hides existence) when claims don't match.
  • Registry write-path: CreateRegistry/UpdateRegistry validate registry claims ⊆ caller JWT AND all referenced sources' claims ⊆ caller JWT. UpdateRegistry/DeleteRegistry validate caller JWT covers existing claims.
  • Registry read-path: ListRegistries filters by caller claims. GetRegistryByName returns 404 when claims don't match.

Bug fixes included

  • RegistryInfo now includes Claims field — previously missing from the API response struct
  • CreateRegistry/UpdateRegistry now persist claims — the UpsertRegistryParams.Claims field was never populated, silently dropping registry claims on API-created registries

Design decisions

  • Claims extracted from context: service methods call claimsFromCtx(ctx) which reads auth.ClaimsFromContext(ctx). No service interface signature changes needed — claims already flow through context from the auth middleware.
  • Hide existence on read failures: GetSourceByName and GetRegistryByName return ErrSourceNotFound/ErrRegistryNotFound (not ErrClaimsInsufficient) when the caller can't see the resource. This prevents information disclosure.
  • Source reference validation on registry create/update: resolveSourceIDsWithGate validates the caller's claims cover each referenced source's claims, preventing users from wiring in sources outside their claim boundary.
  • Dead code removed: non-gated resolveSourceIDs and replaceRegistrySources removed — fully replaced by gated variants.
  • Anonymous + super-admin bypass: same semantics as PR Part 1: Add registry access gate and publish/delete claim validation #649.

Depends on

PR #649 (registry access gate) — this PR is based on registry-access-gate branch.

Test plan

  • Integration tests for source CRUD claim scoping (10 cases in admin_claims_test.go — create, update, delete, list filtering, get hidden, super-admin bypass)
  • Integration tests for registry CRUD claim scoping (9 cases — create, update, delete, list filtering, get hidden, source reference validation)
  • task lint-fix — 0 issues
  • task test — all tests pass
  • Smoke tests via docker compose (16 scenarios, including registry claims in response) — no regressions
  • Verified registry claims field now appears in API responses

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Mar 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.47%. Comparing base (ec8234f) to head (b0162c3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/service/db/impl_registry.go 70.27% 8 Missing and 3 partials ⚠️
internal/service/db/impl_source.go 72.00% 6 Missing and 1 partial ⚠️
internal/api/v1/registries.go 0.00% 2 Missing ⚠️
internal/api/v1/sources.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #650      +/-   ##
==========================================
+ Coverage   59.08%   60.47%   +1.38%     
==========================================
  Files         100      100              
  Lines        9496     9556      +60     
==========================================
+ Hits         5611     5779     +168     
+ Misses       3406     3278     -128     
- Partials      479      499      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov rdimitrov changed the title Add claim-scoped admin management for sources and registries Part 2: Add claim-scoped admin management for sources and registries Mar 31, 2026
@rdimitrov rdimitrov self-assigned this Mar 31, 2026
@rdimitrov
rdimitrov force-pushed the registry-access-gate branch from 7e5bb77 to f3a813b Compare April 1, 2026 05:31
@rdimitrov
rdimitrov force-pushed the claim-scoped-admin branch from c0f8c89 to ca609ac Compare April 1, 2026 05:31
@rdimitrov
rdimitrov force-pushed the registry-access-gate branch from f3a813b to 0a0084d Compare April 1, 2026 12:22
@rdimitrov
rdimitrov force-pushed the claim-scoped-admin branch from ca609ac to 772c752 Compare April 1, 2026 12:22
@blkt
blkt force-pushed the registry-access-gate branch from 0a0084d to 7859ecd Compare April 2, 2026 09:06
Base automatically changed from registry-access-gate to main April 2, 2026 11:31
rdimitrov and others added 4 commits April 2, 2026 14:14
Enforce JWT claim-based authorization on all admin CRUD operations:

Source operations:
- CreateSource/UpdateSource validate request claims are a subset of
  the caller's JWT claims
- UpdateSource/DeleteSource validate the caller's JWT covers the
  existing source's claims before allowing modification
- ListSources filters results to only sources within the caller's
  claim boundary
- GetSourceByName returns 404 (hides existence) when the caller's
  claims don't cover the source

Registry operations:
- CreateRegistry/UpdateRegistry validate registry claims are a subset
  of the caller's JWT and that all referenced sources' claims are
  covered by the caller
- UpdateRegistry/DeleteRegistry validate the caller's JWT covers the
  existing registry's claims
- ListRegistries filters results by caller claims
- GetRegistryByName returns 404 when claims don't match

Bug fixes:
- RegistryInfo now includes Claims field in API responses
- CreateRegistry/UpdateRegistry now persist claims to the database
  (previously silently dropped)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Both entry listing endpoints were missing claim validation — a user
with the manageSources/manageRegistries role could enumerate entries
for any source/registry regardless of claims. Now both validate the
caller's JWT covers the resource's claims before returning data.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Verify that all four skills consumer endpoints (ListSkills,
GetLatestVersion, ListVersions, GetVersion) correctly return
403 when the service returns ErrClaimsInsufficient.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@blkt
blkt force-pushed the claim-scoped-admin branch from 772c752 to b0162c3 Compare April 2, 2026 12:37
Comment thread internal/service/db/impl_source.go Resolved
@blkt
blkt enabled auto-merge (squash) April 2, 2026 12:39
@blkt
blkt disabled auto-merge April 2, 2026 12:39
@blkt
blkt enabled auto-merge (squash) April 2, 2026 12:39
@blkt
blkt merged commit f43ac18 into main Apr 2, 2026
11 checks passed
@blkt
blkt deleted the claim-scoped-admin branch April 2, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants