Repository navigation
Description
Background
Sub-issue of #5146, addressing root cause 1: the operator auto-binds PrimaryUpstreamProvider to the first upstream provider's name without exposing a CRD field that lets users override or opt out of that choice.
cmd/thv-operator/pkg/vmcpconfig/converter.go:201-205 unconditionally sets:
if vmcp.Spec.AuthServerConfig != nil && len(vmcp.Spec.AuthServerConfig.UpstreamProviders) > 0 {
incoming.Authz.PrimaryUpstreamProvider = authserver.ResolveUpstreamName(
vmcp.Spec.AuthServerConfig.UpstreamProviders[0].Name,
)
}A user with multiple upstreams configured cannot point Cedar at a non-first provider, and there is no way to ask the controller to leave the field empty (Cedar's documented "fall back to ToolHive-issued token claims" path). The validator at virtualmcpserver_controller.go:570-645 already surfaces an AuthzUpstreamSelectionWarning advisory when multiple upstreams are configured, but offers no remediation knob beyond reordering the list.
The token-exchange and AWS-STS strategies on MCPExternalAuthConfig already follow the desired pattern: they expose an explicit SubjectProviderName on the CRD (mcpexternalauthconfig_types.go:148, :858) and the controller falls back to "first upstream" only when it's empty. This issue brings Cedar/authz to parity.
Goal
Add an optional primaryUpstreamProvider field to vMCP's incoming-auth inline authz config. When set, the controller honors it; when empty, the existing first-upstream auto-binding behavior is preserved verbatim so existing manifests continue to work.
Implementation plan
1. CRD type
Add field to the existing shared InlineAuthzConfig struct at mcpserver_types.go:765-776:
// PrimaryUpstreamProvider names the upstream IDP whose access token's claims
// Cedar should evaluate. Only meaningful for VirtualMCPServer with an embedded
// auth server. When empty and an embedded auth server has upstreams configured,
// the controller defaults to the first upstream provider.
// +optional
PrimaryUpstreamProvider string `json:"primaryUpstreamProvider,omitempty"`The shared-type approach matches the precedent set by SubjectProviderName on the token-exchange and AWS-STS strategies — also defined on shared types but documented as vMCP-only and ignored by MCPServer/MCPRemoteProxy.
(Alternative: introduce a vMCP-specific VirtualMCPInlineAuthzConfig and a vMCP-specific AuthzConfigRef. More accurate typing, larger refactor with knock-on changes in the converter, controllerutil.GenerateOrUpdateInlineAuthzConfigMap, and tests. Recommend the shared-type approach unless reviewers prefer the stricter typing.)
2. Converter wiring
Replace the unconditional first-upstream assignment in converter.go:201-205 with explicit-then-fallback:
if vmcp.Spec.IncomingAuth.AuthzConfig.Inline != nil &&
vmcp.Spec.IncomingAuth.AuthzConfig.Inline.PrimaryUpstreamProvider != "" {
incoming.Authz.PrimaryUpstreamProvider = authserver.ResolveUpstreamName(
vmcp.Spec.IncomingAuth.AuthzConfig.Inline.PrimaryUpstreamProvider,
)
} else if vmcp.Spec.AuthServerConfig != nil && len(vmcp.Spec.AuthServerConfig.UpstreamProviders) > 0 {
incoming.Authz.PrimaryUpstreamProvider = authserver.ResolveUpstreamName(
vmcp.Spec.AuthServerConfig.UpstreamProviders[0].Name,
)
}Run ResolveUpstreamName on the user-supplied value too, so the field is normalized consistently with the auto-selected path.
3. Validation — validateAuthzUpstreamAvailable
Extend the validator at virtualmcpserver_controller.go:570-645:
- Reject (
SpecValidationError,AuthServerConfigValidated=False) when an explicitPrimaryUpstreamProvideris set but does not match any entry inSpec.AuthServerConfig.UpstreamProvidersafterResolveUpstreamNamenormalization on both sides. Cedar would otherwise deny every request at runtime — fail loudly at admission instead. - Suppress the
AuthzUpstreamSelectionWarningadvisory when the user has set the field explicitly: with multiple upstreams and an explicit choice, no auto-selection is happening. Gate the existinglen(upstreamProviders) > 1branch onInline.PrimaryUpstreamProvider == "". - Leave the existing "embedded AS but zero upstreams" reject path unchanged.
4. Tests
- Converter — extend
TestConvertIncomingAuth_PrimaryUpstreamProvider(converter_test.go:1902) with cases: explicit name with single upstream; explicit name overriding the first of multiple; explicit name routed throughResolveUpstreamName(empty user value falls into the auto-select branch — covered already); explicit name with no embedded AS (left as-is via the explicit branch). - Validator — add cases alongside the existing
validateAuthzUpstreamAvailabletests: explicit name matching one of the upstreams (no warning, no error); explicit name not matching any upstream (SpecValidationError); explicit name + multi-upstream (no advisory warning emitted).
5. Generated artifacts
task operator-generate(deepcopy)task operator-manifests(CRD YAML — bothdeploy/charts/operator-crds/files/andtemplates/copies)task -d cmd/thv-operator crdref-gen(API docs)
6. Backward compatibility
Existing manifests without the new field keep current behavior — the converter's fallback branch is unchanged for that path. The advisory warning continues to fire on multi-upstream + no explicit choice, and now points users at a CRD knob to silence it.
Out of scope
- The Cedar opaque-token fallback fix (root cause 3 in VirtualMCPServer Cedar authorization rejects all requests when upstream OIDC provider issues opaque access tokens #5146) lives in
pkg/authz/authorizers/cedar/core.goand is the smallest defensible fix for the original bug. This issue only makes the auto-binding overridable. MCPExternalAuthConfigtoken-exchange/AWS-STS already exposesSubjectProviderName. No work needed there.- Standalone CLI /
thv runmiddleware (pkg/runner/middleware.go) is unaffected.
Estimated size
~3 files of production code (mcpserver_types.go, converter.go, virtualmcpserver_controller.go) + tests + regenerated CRD/deepcopy/docs. Should fit a single PR under the 400-line / 10-file cap.
Activity
tgrunnagle commentedon May 5, 2026
@jhrozek What do you think of removing the "fallback to first upstream provider when none is specified in the CRD" logic for authz enforcement, and use the toolhive issued (or incoming) token by default? I think it's better behavior, but it is a breaking change.
jhrozek commentedon May 6, 2026
Not sure if I understand, would the toolhive issued token be useful at all for cedar policies? Would it have e.g. groups or roles?
tgrunnagle commentedon May 6, 2026
It could have a subject, but yes you're right wouldn't have more details. I see the toolhive issued tokens wouldn't be useful for production- will keep the fallback logic.
Expose explicit primaryUpstreamProvider for Cedar authz on VirtualMCP…