Skip to content

Add registry AuthDefaulter extension point for OIDC discovery#5255

Open
reyortiz3 wants to merge 2 commits into
mainfrom
feat/registry-auth-defaulter
Open

Add registry AuthDefaulter extension point for OIDC discovery#5255
reyortiz3 wants to merge 2 commits into
mainfrom
feat/registry-auth-defaulter

Conversation

@reyortiz3
Copy link
Copy Markdown
Contributor

Summary

  • Why: thv config set-registry <url> and PUT /api/v1beta/registry/{name} currently require the caller to pass --issuer/--client-id (or an auth body) explicitly. Downstream consumers (enterprise builds, GUIs, future managed deployments) want to fill these in automatically from an OIDC discovery document, but there is no extension point to plug that resolver into either entry point.
  • What: Introduces a pluggable registry.AuthDefaulter in pkg/registry/. When the user/API caller omits auth, the CLI and the API handler consult the registered defaulter (if any) and use what it returns. OSS builds register no defaulter and behave exactly as before.

Type of change

  • New feature

Test plan

  • Unit tests (go test ./pkg/registry/... ./pkg/api/v1/... ./cmd/thv/app/...)
    • New: TestResolveAuthDefaults, TestRegisterAuthDefaulter (pkg/registry)
    • New: TestUpdateRegistry_AuthDefaulterFillsMissingAuth (pkg/api/v1, uses a mocked OIDC discovery server)
  • E2E tests (task test-e2e) — not run; behavior unchanged for OSS builds
  • Manual testing — not applicable

Does this introduce a user-facing change?

No (for OSS). The new extension point is dormant unless a build registers a defaulter via registry.RegisterAuthDefaulter. Existing CLI/API contracts are unchanged: explicit --issuer/--client-id or auth body still wins, and omitting them with no defaulter registered still produces a registry with no OAuth (the prior behavior).

Special notes for reviewers

  • Errors from the defaulter fall back to "no auth" so the call site preserves the legacy lenient behavior — we don't want a flaky discovery server to break unrelated CLI commands.
  • RegisterAuthDefaulter(nil) clears the active defaulter (needed by tests).
  • The defaulter sees (issuer, clientID) only — audience and scopes still come from the caller's request or the defaults already in pkg/registry/auth.

🤖 Generated with Claude Code

When `thv config set-registry <url>` is run without --issuer and
--client-id, or PUT /api/v1beta/registry/{name} is called without
an auth object, the registry has no OAuth configured. Downstream
consumers (e.g. enterprise builds) want to fill those in from an
external source — typically an OIDC discovery document — so admins
do not have to distribute issuer/client_id out of band.

This adds a pluggable AuthDefaulter:

  - pkg/registry/auth_defaulter.go: AuthDefaulter type, Register and
    Active accessors, and a ResolveAuthDefaults helper.
  - cmd/thv/app/config.go: set-registry CLI calls ResolveAuthDefaults
    when both --issuer and --client-id are omitted.
  - pkg/api/v1/registry.go: PUT /api/v1beta/registry/{name} calls
    ResolveAuthDefaults when the request body omits auth.

OSS builds register no defaulter and keep the existing behavior
(no auth when none is supplied). The defaulter only fires when
explicitly registered, and an explicit empty auth still wins over
the defaulter.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the size/S Small PR: 100-299 lines changed label May 12, 2026
The defaulter branch pushed updateRegistry's cyclomatic complexity from
15 to 16, tripping gocyclo. Move the "decide which auth to apply and
apply it" block into applyRegistryAuth, and translate its failure modes
through writeRegistryAuthError. Behavior is unchanged: explicit auth
still applies verbatim, no auth still falls back to the AuthDefaulter
then to clearing, and a clear failure still returns 500 while a
processAuthUpdate failure still returns 400.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels May 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.06%. Comparing base (3240eeb) to head (51e9ddd).

Files with missing lines Patch % Lines
pkg/api/v1/registry.go 41.66% 12 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5255      +/-   ##
==========================================
+ Coverage   67.99%   68.06%   +0.07%     
==========================================
  Files         616      617       +1     
  Lines       63005    63037      +32     
==========================================
+ Hits        42840    42909      +69     
+ Misses      16963    16924      -39     
- Partials     3202     3204       +2     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants