Repository navigation
Initialize identity modifiers for standalone use - #7063
Conversation
rdimitrov
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
-
pkg/authserver/server.go:168— registration is one layer too high. Two exported paths reachupstream.NewOAuth2Providerwithoutauthserver.New:authserver.DefaultUpstreamFactory(server_impl.go:76), whose doc invites embedders to call it for built-in behaviour;upstream.NewOAuth2Provideritself (upstream/oauth2.go:625), whichupstream/doc.go:57shows as the standard usage.
Scenario: an embedder builds a provider through either of them with
IdentityFromToken.SubjectPath: "access_token|@upstreamjwt|sub"in a process whereauthserver.Newhasn'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: callRegisterModifiers()at the top ofNewOAuth2Provider, which it's alreadysync.Once-guarded for, or register in a packageinit()(precedent:oauthproto/grants.go,authz/*/core.go). Then drop the call fromauthserver.New. The subprocess test keeps working unchanged, and the "Callers constructing upstream providers directly still need to callupstream.RegisterModifiers()" caveat in the PR body goes away. -
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@upstreamjwtidentity 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
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]>
6770f09 to
109521c
Compare
|
@rdimitrov Addressed both points in 109521c.
Checked the consumer source paths: SEP already registers early before provider preflight/rebuild, so its existing call remains safe; mecatl uses Validation: |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Summary
@upstreamjwtunless they registered modifiers themselves, because initialization happened only inrunner.NewEmbeddedAuthServer.authserver.Newandupstream.NewOAuth2Provider, covering custom factories, direct providers,DefaultUpstreamFactory, and both runner constructors while retaining the sharedsync.Onceguard.Type of change
Test plan
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.task lint-fix); zero issues.authserver.New, observed the new assertion fail before provider construction, restored the call, and reran the full suite successfully.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 asaccess_token|@upstreamjwt|subto work. Now registration is automatic. The ordinaryrunner.NewEmbeddedAuthServerpath already registered these modifiers, so its successful behavior remains unchanged. Existing explicit calls toupstream.RegisterModifiers()remain safe.Special notes for reviewers
Registration remains in
authserver.Newas well asNewOAuth2Providerdeliberately: 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 samesync.Onceguards 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.