Skip to content

Part 1: Add registry access gate and publish/delete claim validation - #649

Merged
blkt merged 1 commit into
mainfrom
registry-access-gate
Apr 2, 2026
Merged

blkt merged 1 commit into
mainfrom
registry-access-gate

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Mar 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Enforces JWT claim-based authorization on two paths that were previously unprotected:

  • Registry access gate: consumer read endpoints (/registry/{reg}/v0.1/...) now check the registry's claims field against the user's JWT before returning data. Returns 403 if the caller's claims don't cover the registry's claims.
  • Publish subset validation: POST /v1/entries validates that request claims are a subset of the publisher's JWT claims, preventing privilege escalation (a user can't publish entries with broader visibility than their own identity allows).
  • Delete authorization: DELETE /v1/entries/{type}/{name}/versions/{ver} validates that the caller's JWT claims cover the entry's stored claims before allowing deletion.

Context

The design plan requires claim-based authorization at multiple levels. Per-user entry filtering was already implemented, but the registry-level access gate and write-path claim validation were missing:

  • lookupRegistryID() fetched the registry row (which includes claims) but discarded them — returning only the UUID
  • The publish handler passed request body claims to the service but never extracted the publisher's JWT claims for subset validation
  • The delete handler had no claim authorization at all

Design decisions

  • WithJWTClaims is separate from WithClaims: WithClaims carries the request body claims (what the publisher wants on the entry). WithJWTClaims carries the publisher's JWT claims (who they are). These are compared — request claims must be ⊆ JWT claims.
  • Anonymous mode bypass: when callerClaims is nil (anonymous auth), all claim checks are skipped. This preserves the existing no-auth development experience.
  • Super-admin bypass: resolved roles are now stored in request context via ContextWithRoles. IsSuperAdmin(ctx) checks for the super-admin role and bypasses claim validation.
  • Old functions removed: lookupRegistryID and checkRegistryExists became dead code after all call sites switched to the gated variants — removed rather than keeping unused code.

Shared infrastructure added

Component File Purpose
ErrClaimsInsufficient service.go Sentinel error → 403
ContextWithRoles / RolesFromContext / IsSuperAdmin auth/claims.go Store resolved roles in context for downstream checks
validateClaimsSubset / validateClaimsSubsetBytes service/db/authz.go Reusable claim validation with anonymous + super-admin bypass
WithJWTClaims option options.go Pass publisher JWT to publish/delete service methods

What this doesn't cover

Test plan

  • Unit tests for validateClaimsSubset helpers (17 cases in authz_test.go)
  • Integration tests for registry gate (11 cases in registry_gate_test.go — nil claims, matching, non-matching, anonymous bypass, super-admin bypass, not-found)
  • Integration tests for publish/delete claim validation (14 cases in publish_claims_test.go — JWT superset, JWT insufficient, anonymous, nil request claims)
  • Handler-level tests for 403 responses (3 cases added to routes_test.go — ListServers, ListVersions, GetVersion)
  • task lint-fix — 0 issues
  • task test — all tests pass
  • Smoke tests via docker compose (31 scenarios, anonymous mode) — no regressions

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Mar 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.17699% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.06%. Comparing base (991d408) to head (7859ecd).

Files with missing lines Patch % Lines
internal/api/v1/entries.go 31.25% 7 Missing and 4 partials ⚠️
internal/service/options.go 0.00% 7 Missing ⚠️
internal/service/options_mcp.go 0.00% 6 Missing ⚠️
internal/service/options_skills.go 0.00% 6 Missing ⚠️
internal/auth/claims.go 28.57% 5 Missing ⚠️
internal/service/db/impl_mcp.go 77.77% 3 Missing and 1 partial ⚠️
internal/service/db/impl_skills.go 76.47% 3 Missing and 1 partial ⚠️
internal/api/x/skills/routes.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #649      +/-   ##
==========================================
+ Coverage   59.03%   59.06%   +0.03%     
==========================================
  Files         100      100              
  Lines        9393     9496     +103     
==========================================
+ Hits         5545     5609      +64     
- Misses       3375     3407      +32     
- Partials      473      480       +7     

☔ 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

Copy link
Copy Markdown
Member Author

How it was tested:

Authorization E2E Test Summary

Test Categories

# Category What's Verified Scenarios
1 System endpoints /health, /readiness, OAuth metadata accessible without auth 3
2 Unauthenticated access Consumer and admin APIs reject requests without JWT (401) 3
3 Registry access gate JWT must cover registry claims; outsider blocked; super-admin bypasses 12
4 Per-user entry filtering Same registry shows different entries per user based on team claims 12
5 Admin source listing Sources filtered by caller's claims; super-admin sees all 6
6 Admin registry listing Registries filtered by caller's claims; super-admin sees all 4
7 Publish claim validation Published claims must be subset of publisher's JWT; wrong role blocked 4
8 Published entry visibility Published entries only visible to users whose JWT covers entry claims 6
9 Delete authorization Can't delete entries with claims outside your JWT; super-admin can 3
10 Config-managed protection Config-defined sources/registries immutable via API (403) 3
Total 5 personas, 10 categories 56

User Personas

Persona JWT Claims Roles
super-admin org=acme, role=super-admin superAdmin (full bypass)
platform-admin org=acme, team=platform, role=admin manageSources, manageRegistries
platform-writer org=acme, team=platform, role=writer manageEntries
data-writer org=acme, team=data, role=writer manageEntries
outsider org=contoso, role=admin manageSources, manageRegistries (wrong org)

How to Run

docker compose -f docker-compose-authz.yaml up --build -d
./examples/authz-test/test-authz.sh
docker compose -f docker-compose-authz.yaml down -v

@rdimitrov rdimitrov changed the title Add registry access gate and publish/delete claim validation Part 1: Add registry access gate and publish/delete claim validation 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

@blkt blkt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple issues that need attention.

Comment thread internal/service/db/authz.go Resolved
Comment thread internal/service/options.go Resolved
Comment thread internal/service/options_mcp.go Resolved
@rdimitrov
rdimitrov force-pushed the registry-access-gate branch from f3a813b to 0a0084d Compare April 1, 2026 12:22
Enforce JWT claim-based authorization on consumer read endpoints
and entry publish/delete operations:

- Registry access gate: consumer endpoints now check the registry's
  claims against the user's JWT. Returns 403 if the caller's claims
  do not cover the registry's claims. Anonymous mode and super-admin
  bypass the check.

- Publish subset validation: the publish endpoint now validates that
  request claims are a subset of the publisher's JWT claims, preventing
  privilege escalation.

- Delete authorization: the delete endpoint validates that the caller's
  JWT claims cover the entry's stored claims before allowing deletion.

Infrastructure added:
- ErrClaimsInsufficient sentinel error
- Roles-in-context (ContextWithRoles/RolesFromContext/IsSuperAdmin)
- Shared authz helpers (validateClaimsSubset, validateClaimsSubsetBytes)
- WithJWTClaims service option for publish/delete paths

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comment thread internal/service/options.go Resolved
Comment thread internal/service/options_mcp.go Resolved
@blkt
blkt force-pushed the registry-access-gate branch from 0a0084d to 7859ecd Compare April 2, 2026 09:06
@blkt
blkt merged commit ec8234f into main Apr 2, 2026
9 checks passed
@blkt
blkt deleted the registry-access-gate branch April 2, 2026 11:31
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