Wire identityFromToken through authserver config and runtime#5285
Open
jhrozek wants to merge 3 commits into
Open
Wire identityFromToken through authserver config and runtime#5285jhrozek wants to merge 3 commits into
jhrozek wants to merge 3 commits into
Conversation
Add the operator-side and runtime-side translation that carries
IdentityFromToken from MCPExternalAuthConfig (v1beta1 CRD) through
the authserver run-config and into upstream.OAuth2Config so the
provider added in the previous commit actually receives the field.
Two translation points mirror the existing TokenResponseMapping
plumbing:
* cmd/thv-operator/pkg/controllerutil/authserver.go
CRD v1beta1.IdentityFromTokenConfig
-> authserver.IdentityFromTokenRunConfig (operator path)
* pkg/authserver/runner/embeddedauthserver.go
authserver.IdentityFromTokenRunConfig
-> upstream.IdentityFromTokenConfig (runtime path)
A new IdentityFromTokenRunConfig type lives next to
TokenResponseMappingRunConfig in pkg/authserver/config.go.
Tests cover the round-trip on both sides and the nil-config case
(no spurious allocation).
IdentityFromToken paths that use the `@upstreamjwt` modifier (e.g. `access_token|@upstreamjwt|sub` for upstreams that embed identity inside a JWS access token) require RegisterModifiers() to run before any extraction. Until now the call lived only in test TestMain functions, so production paths silently no-op'd and operators saw a generic "path not found" error. Add the call near the top of NewEmbeddedAuthServer. Protect the gjson.AddModifier write with a sync.Once so concurrent constructors (parallel test cases, thundering-herd restarts) do not race on the gjson global modifier map.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5285 +/- ##
==========================================
+ Coverage 68.37% 68.41% +0.04%
==========================================
Files 619 619
Lines 63318 63334 +16
==========================================
+ Hits 43293 43333 +40
+ Misses 16794 16765 -29
- Partials 3231 3236 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
identityFromTokenfield was added to the v1beta1 CRD in #5269 but the translation layers that carry it from the CRD into the running auth server were missing, so the field was silently ignored.v1beta1.IdentityFromTokenConfig→authserver.IdentityFromTokenRunConfiginbuildOAuth2UpstreamRunConfig(mirrorsTokenResponseMappingplumbing)authserver.IdentityFromTokenRunConfig→upstream.IdentityFromTokenConfiginbuildPureOAuth2ConfigIdentityFromTokenRunConfigtype topkg/authserver/config.goalongsideTokenResponseMappingRunConfigRegisterModifiers()— the call existed only in testTestMainfunctions, so@upstreamjwtmodifier paths silently no-op'd in production; move the call intoNewEmbeddedAuthServerand guard it withsync.Onceto prevent races between concurrent constructorsidentity_from_tokenconfigs wheresubject_pathis empty (would producesub: ""in issued tokens)omitemptyfromSubjectPathstruct tag to reflect its required-when-set semanticsType of change
Test plan
task test)task lint-fix)Unit tests cover:
TestBuildAuthServerRunConfig) and runner side (TestBuildPureOAuth2ConfigIdentityFromToken) for nil, partial, and full-fields casesOAuth2UpstreamRunConfig.Validatecases for emptySubjectPathrejectionAPI Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
cmd/thv-operator/pkg/controllerutil/authserver.goIdentityFromToken, moved insidebuildOAuth2UpstreamRunConfigcmd/thv-operator/pkg/controllerutil/authserver_test.goIdentityFromTokenpkg/authserver/config.goIdentityFromTokenRunConfigtype; field onOAuth2UpstreamRunConfig;Validaterejects emptySubjectPathpkg/authserver/config_test.goValidatecases forIdentityFromTokenpkg/authserver/runner/embeddedauthserver.goRegisterModifiers()call in constructor; RunConfig → upstream translationpkg/authserver/runner/embeddedauthserver_test.gopkg/authserver/upstream/identity_from_token.gosync.Onceguard on modifier registration; fix stalev1alpha1→v1beta1commentSpecial notes for reviewers
RegisterModifiers()previously relied on callers (only testTestMainfunctions) to register the@upstreamjwtgjson modifier before use. Thesync.Onceguard ensures registration happens exactly once even under concurrentNewEmbeddedAuthServercalls, which is safe because gjson's modifier map has no internal synchronisation.Generated with Claude Code