Skip to content

Expose group-based upstream filter via vMCP CRD - #6740

Merged
JAORMX merged 1 commit into
stacklok:mainfrom
hellouz818:feature/6675-pr3-crd
Oct 15, 2026
Merged

JAORMX merged 1 commit into
stacklok:mainfrom
hellouz818:feature/6675-pr3-crd

Conversation

@hellouz818

@hellouz818 hellouz818 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PR 3/3 of #6675. Surfaces the auth-server GroupBasedFilter (added in #6739) through VirtualMCPServerSpec so operators can configure per-user upstream chain narrowing with YAML.

The new AuthServerUpstreamFilter field lives beside AuthServerConfig (rather than nested inside the shared EmbeddedAuthServerConfig, which is also used by MCPExternalAuthConfig where multi-upstream filtering has no meaning). Admission-time CEL enforces two cheap cross-field invariants: the field requires authServerConfig, and at least two upstream providers must be configured. Reconciliation re-runs the full Go filter constructor against the configured upstream list so a resource that bypassed admission (fake client, pre-CEL stored object) is rejected with a terminal AuthServerConfigValidated=False condition before its ConfigMap is written.

The vMCP converter extends the shared BuildAuthServerRunConfig call with the vMCP-only field translation, keeping the shared builder free of vMCP-specific concerns.

  • CRD type additions on VirtualMCPServerSpec + CEL + OpenAPI markers
  • vMCP converter extension (ConvertUpstreamFilter) layered on BuildAuthServerRunConfig
  • Reconciler re-validation (validateAuthServerUpstreamFilter)
  • Architecture doc section with YAML example
  • Regenerated deepcopy, CRD manifests, CRD reference

Both earlier PRs in the series are merged, so this one now sits directly on main. Refs #6675

Type of change

  • New feature

Test plan

  • Unit tests (task test) — 6 cases for validateAuthServerUpstreamFilter, 4 cases for ConvertUpstreamFilter
  • Integration tests (envtest) — 9 Ginkgo cases in test-integration/virtualmcp/virtualmcpserver_upstreamfilter_cel_test.go exercising the CEL rules through the real apiserver
  • Linting (task lint) — 0 issues
  • Generated artifacts verified fresh (task docs-verify, task operator-generate, task operator-manifests, task crdref-gen)
  • Manual testing — deployed to an internal MCP Hub deployment with the field set; a viewer-only user walks the mandatory first upstream and only the slack optional upstream, successfully invokes Slack tools via Claude Code, with atlassian / cobi / salesforce upstream tokens correctly absent (confirmed via operator audit logs and absent-token warnings)

API Compatibility

  • This PR does not break the v1beta1 API.

New optional field on VirtualMCPServerSpec. Omitting it preserves pre-filter behavior (full chain). No existing CRs change meaning.

Does this introduce a user-facing change?

Yes — new optional field VirtualMCPServer.spec.authServerUpstreamFilter lets operators narrow the OAuth chain per user based on an identity claim. See the "Per-User Upstream Filtering" section in docs/arch/10-virtual-mcp-architecture.md for the configuration shape and semantics.

Special notes for reviewers

Where the claim comes from

The filter is fail-closed on an absent claim, and the CRD reference is what an operator reads before enabling the field, so claim's doc comment states where the value is resolved from: the identity the first upstream produces — the validated ID token for an OIDC upstream, the userinfo response for a pure OAuth2 one. Groups carried only in an access token never reach it. An IdP that does not emit the claim locks every principal out. Before enabling the filter, configure the first upstream to include the claim in its ID token or userinfo response, and request any required scopes. This mirrors the GroupBasedFilterConfig.Claim documentation added during the #6739 review, on the surface operators actually configure.

CEL cost budget

The two deeper reference-integrity CEL rules the issue plan called for (every referenced provider must name a configured non-first upstream; mandatory first provider must not be referenced) were originally implemented but exceeded Kubernetes' static validation cost limit because upstreamProviders has no MaxItems bound.

They are enforced at reconciliation time instead, by validateAuthServerUpstreamFilter, which surfaces a terminal AuthServerConfigValidated=False condition. The reconciler calls the same Go constructor used in #6739, keeping reconciliation validation consistent with auth-server initialization.

A proper restoration path would add MaxItems bounds on the shared upstreamProviders type to tame the cost estimator; keeping that out of scope here keeps the shared EmbeddedAuthServerConfig type unchanged for MCPExternalAuthConfig consumers. Happy to open a follow-up PR for the bounded-list restoration if preferred.

Note on OAuth-flow E2E

The issue plan includes a functional E2E deliverable. #6739 added an integration test that drives the filter from a RunConfig through the real multi-leg authorization flow with mock OIDC upstreams.

This PR adds no further flow-level coverage: admission behavior is covered by envtest against a real apiserver, and reconciliation validation and field conversion are covered by unit tests. The end-to-end behavior has additionally been validated manually against an internal MCP Hub deployment.

This follows the test layering used for the SPIFFE CRD exposure in #6500: envtest coverage for admission behavior, without a full OAuth-flow E2E.

Follow-up work tracked

  • pkg/vmcp/auth/strategies/xaa.go still carries its own claim array decoding. Cedar's array-only site moved onto pkg/auth/claims in Add shared JWT claim string-array decoder #6738; the remaining Cedar paths (normalizeMultiValuedClaims, addMultiValuedClaimSets) also accept scalar strings, so they are not candidates for the array-only helper.
  • Optional CEL rule restoration after MaxItems bounds on the shared upstream type.

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.18182% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.51%. Comparing base (d6660c0) to head (89a2822).

Files with missing lines Patch % Lines
...perator/controllers/virtualmcpserver_controller.go 89.28% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6740      +/-   ##
==========================================
- Coverage   79.51%   79.51%   -0.01%     
==========================================
  Files         814      814              
  Lines       82534    82577      +43     
==========================================
+ Hits        65623    65657      +34     
- Misses      16906    16915       +9     
  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.

@hellouz818
hellouz818 force-pushed the feature/6675-pr3-crd branch 2 times, most recently from 40e2300 to e599d67 Compare October 8, 2026 01:59
@hellouz818
hellouz818 force-pushed the feature/6675-pr3-crd branch from e599d67 to 12aad7f Compare October 13, 2026 10:45
Surface the auth-server GroupBasedFilter through VirtualMCPServerSpec so
operators can configure per-user upstream chain narrowing with YAML,
without reaching into the embedded auth-server RunConfig directly.

The new AuthServerUpstreamFilter field lives beside AuthServerConfig
(rather than nested inside EmbeddedAuthServerConfig, which is shared
with MCPExternalAuthConfig and has no meaning for multi-upstream
filtering). CEL at admission enforces the two cheap cross-field
invariants Kubernetes can check cheaply: the field requires
authServerConfig, and at least two upstream providers must be
configured.

The two deeper reference-integrity checks the plan called for —
every referenced provider must name a configured non-first upstream,
and the mandatory first provider must not be referenced — were
originally expressed as CEL but exceeded Kubernetes' static
validation cost limit, because upstreamProviders carries no MaxItems
bound. They are enforced at reconciliation time instead, by
validateAuthServerUpstreamFilter in the VirtualMCPServer controller,
which surfaces a terminal AuthServerConfigValidated=False condition.
A proper restoration would require bounding the shared
upstreamProviders type so the cost estimator can size it; keeping
that out of scope here keeps the shared EmbeddedAuthServerConfig
type unchanged for MCPExternalAuthConfig consumers.

Reconciliation also protects against admission bypass (fake client,
pre-CEL stored object): the full Go filter constructor runs again
against the configured upstream list before the ConfigMap is written,
rejecting malformed configuration before it reaches a crash-looping
pod. The vMCP converter extends the shared BuildAuthServerRunConfig
call with the vMCP-only field translation, keeping the shared builder
free of vMCP-specific concerns.

The claim field documents where its value is resolved from, because
the filter is fail-closed and the CRD reference is what an operator
reads before enabling it: the first upstream must be configured to
carry the claim in its ID token or userinfo response, so an IdP that
does not emit it there locks every principal out.

Generated artifacts (deepcopy, CRD manifests, CRD reference) are
regenerated via task operator-generate, task operator-manifests, and
task crdref-gen.

Refs: stacklok#6675

Signed-off-by: hellouz818 <[email protected]>
@JAORMX
JAORMX merged commit ba991a6 into stacklok:main Oct 15, 2026
49 of 50 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
2 tasks
@hellouz818
hellouz818 deleted the feature/6675-pr3-crd branch November 23, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants