Skip to content

Initialize identity modifiers for standalone use - #7063

Merged
jhrozek merged 1 commit into
mainfrom
safe-01-identity-boundary
Nov 6, 2026
Merged

jhrozek merged 1 commit into
mainfrom
safe-01-identity-boundary

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Standalone authserver and direct OAuth2 provider callers could not resolve identity paths using @upstreamjwt unless they registered modifiers themselves, because initialization happened only in runner.NewEmbeddedAuthServer.
  • Register modifiers in both authserver.New and upstream.NewOAuth2Provider, covering custom factories, direct providers, DefaultUpstreamFactory, and both runner constructors while retaining the shared sync.Once guard.
  • Add fresh-process regression tests for server and direct-provider construction, and document automatic registration for embedders.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Static review of constructor paths, registration ordering, and subprocess isolation.
  • Unit tests (TMPDIR=/tmp task test), including race detection. The initial run with the default temporary directory encountered macOS Unix-socket path-length failures; the full suite passed with the shorter path.
  • Linting (task lint-fix); zero issues.
  • Regression proof: temporarily removed registration from authserver.New, observed the new assertion fail before provider construction, restored the call, and reran the full suite successfully.
  • E2E tests (task test-e2e)

Does this introduce a user-facing change?

Yes. Before, standalone authserver.New, runner.NewEmbeddedAuthServerWithStorage, and direct OAuth2 provider/factory callers needed registration elsewhere for modifier-bearing identity paths such as access_token|@upstreamjwt|sub to work. Now registration is automatic. The ordinary runner.NewEmbeddedAuthServer path already registered these modifiers, so its successful behavior remains unchanged. Existing explicit calls to upstream.RegisterModifiers() remain safe.

Special notes for reviewers

Registration remains in authserver.New as well as NewOAuth2Provider deliberately: this preserves registration before custom factories run and during OIDC-only server construction, rather than postponing the first global registration until a later OAuth2 provider is added. The same sync.Once guards both calls; this does not synchronize unrelated third-party gjson registrations or readers.

The server regression test checks modifier availability inside the custom factory before calling NewOAuth2Provider, so provider-level registration cannot mask a missing server-boundary call. Each direct-provider/factory case runs in its own fresh process.

Source review covered SEP's existing explicit early registration and mecatl's storage-injection runner path. Neither consumer was built or run against this commit.

@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Nov 6, 2026
rdimitrov
rdimitrov previously approved these changes Nov 6, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Traced the constructor paths: authserver.New is the only place upstream providers are built (buildUpstreams → server_impl.go), so registering there covers standalone embedders and also NewEmbeddedAuthServerWithStorage, which skipped registration before this change. Ran pkg/authserver and pkg/authserver/runner tests with the Taskfile flags (-race): both pass. With the RegisterModifiers() line reverted, the new subprocess test fails with subjectPath "access_token|@upstreamjwt|sub" path not found, so it guards the regression.

🤖 Reviewed with Claude Code

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up to my earlier approval: on a closer design pass I think the registration belongs inside the upstream package rather than in authserver.New; my approval stands, but this is worth doing here or as a quick follow-up.

Design: The @upstreamjwt modifier is defined and consumed in pkg/authserver/upstream (extractIdentityFromTokenResponse, reached via the rewriter NewOAuth2Provider builds), so that package owns the invariant "the modifier is registered before any identity path is evaluated". This PR moves the call from the runner into authserver.New, which fixes every in-repo path, including runner.NewEmbeddedAuthServerWithStorage, which skipped it before. It still leaves the registration one layer above the code that needs it, so exported entry points that build providers without going through authserver.New keep the same silent failure this PR fixes.

  1. pkg/authserver/server.go:168 — registration is one layer too high. Two exported paths reach upstream.NewOAuth2Provider without authserver.New:

    • authserver.DefaultUpstreamFactory (server_impl.go:76), whose doc invites embedders to call it for built-in behaviour;
    • upstream.NewOAuth2Provider itself (upstream/oauth2.go:625), which upstream/doc.go:57 shows as the standard usage.

    Scenario: an embedder builds a provider through either of them with IdentityFromToken.SubjectPath: "access_token|@upstreamjwt|sub" in a process where authserver.New hasn't run. Every login then fails at runtime with "path not found in token response" (identity_from_token.go:117), with no startup error.
    Fix: call RegisterModifiers() at the top of NewOAuth2Provider, which it's already sync.Once-guarded for, or register in a package init() (precedent: oauthproto/grants.go, authz/*/core.go). Then drop the call from authserver.New. The subprocess test keeps working unchanged, and the "Callers constructing upstream providers directly still need to call upstream.RegisterModifiers()" caveat in the PR body goes away.

  2. PR body — "Embedded runner behavior remains unchanged" isn't quite right. Callers of runner.NewEmbeddedAuthServerWithStorage (the storage-injection constructor) previously never registered the modifier, so @upstreamjwt identity paths failed for them. They now work. That's the main user-visible fix and is worth stating as a before/after in the user-facing section.

🤖 Reviewed with Claude Code

@github-actions github-actions Bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Nov 6, 2026
Standalone authserver and direct OAuth2 provider callers could not resolve identity paths using @upstreamjwt unless they registered modifiers themselves. Registration previously happened only in the embedded runner.

Register in authserver.New before custom factories run and in NewOAuth2Provider for direct provider and default-factory callers. Retain the shared sync.Once guard and document automatic initialization for embedders.

Add fresh-process regression tests for both provider entry points and assert registration before the custom factory constructs its provider, so constructor initialization cannot mask a missing server-boundary call.

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the safe-01-identity-boundary branch from 6770f09 to 109521c Compare November 6, 2026 18:47
@jhrozek
jhrozek requested a review from amirejaz as a code owner November 6, 2026 18:47
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Nov 6, 2026
@jhrozek

jhrozek commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@rdimitrov Addressed both points in 109521c.

  1. Added unconditional RegisterModifiers() at the top of upstream.NewOAuth2Provider, so direct provider callers and authserver.DefaultUpstreamFactory no longer depend on prior authserver construction. I retained the call in authserver.New deliberately: it preserves registration before custom factories run and for OIDC-only server startup, rather than deferring the first global registration until a later OAuth2 provider is introduced. Both calls use the existing sync.Once.

    Added separate fresh-process tests for direct provider and default-factory use. The server test now checks modifier availability inside its factory before constructing the provider, so the new provider-level registration cannot mask a regression in the server boundary. Temporarily removing the server registration makes that assertion fail; restored it and reran the full suite successfully.

  2. Corrected the user-facing section to explicitly describe the before/after fix for NewEmbeddedAuthServerWithStorage, and extended it to cover direct provider callers. Also added the embedder documentation to docs/arch/11-auth-server-storage.md.

Checked the consumer source paths: SEP already registers early before provider preflight/rebuild, so its existing call remains safe; mecatl uses NewEmbeddedAuthServerWithStorage and its current builder does not configure IdentityFromToken. Neither consumer was built against this commit.

Validation: TMPDIR=/tmp task test passed with race detection, and task lint-fix passed with zero issues. The shorter temporary path avoids macOS Unix-socket path-length failures in the initial full-suite run.

@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 Nov 6, 2026
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.89%. Comparing base (01f96bf) to head (109521c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7063      +/-   ##
==========================================
- Coverage   80.90%   80.89%   -0.02%     
==========================================
  Files         864      864              
  Lines       88634    88635       +1     
==========================================
- Hits        71709    71700       -9     
- Misses      16920    16930      +10     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 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.

@jhrozek
jhrozek merged commit 5918014 into main Nov 6, 2026
51 of 67 checks passed
@jhrozek
jhrozek deleted the safe-01-identity-boundary branch November 6, 2026 19:15
@github-actions github-actions Bot mentioned this pull request Nov 10, 2026
2 tasks
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.

3 participants