Repository navigation
Propagate MCPOIDCConfig CA bundle to vmcp OIDC config - #4923
Conversation
VirtualMCPServer referencing an MCPOIDCConfig with a ConfigMap-backed caBundleRef mounted the CA into the pod but never told the vmcp binary where to find it. OIDC discovery against a self-signed issuer then failed with "x509: certificate signed by unknown authority". The vmcp OIDCConfig had no CA-bundle field, so the operator converter silently dropped the resolver's ThvCABundlePath. This mirrors the earlier MCPServer fix (#3142, #3391). - Add CABundlePath to pkg/vmcp/config.OIDCConfig with absolute-path, no-traversal, no-null-byte validation consistent with StaticBackendConfig.CABundlePath. - Populate CABundlePath from resolved.ThvCABundlePath in the operator's mapResolvedOIDCToVmcpConfigFromRef, covering both inline caBundleRef and the Kubernetes service-account CA default. - Wire CABundlePath into auth.TokenValidatorConfig.CACertPath in newOIDCAuthMiddleware so the incoming-OIDC middleware loads the CA into its HTTP client for discovery, JWKS, and introspection. - Add unit tests at each layer and a VirtualMCPServer envtest scenario asserting the rendered vmcp-config ConfigMap contains caBundlePath and the Deployment mounts the ConfigMap read-only at the expected path. Closes #4918 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
task operator-manifests + task crdref-gen after adding CABundlePath to pkg/vmcp/config.OIDCConfig. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4923 +/- ##
==========================================
- Coverage 71.87% 71.87% -0.01%
==========================================
Files 715 715
Lines 73501 73508 +7
==========================================
+ Hits 52830 52834 +4
- Misses 16887 16891 +4
+ Partials 3784 3783 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jhrozek
left a comment
There was a problem hiding this comment.
LGTM. Small, focused fix that mirrors the established StaticBackendConfig.CABundlePath validation pattern and the earlier MCPServer CA-bundle propagation fixes (#3142, #3391).
Tests cover every layer:
- Validator: valid/relative/
../null-byte cases - Operator converter: inline, KSA default, and empty
ThvCABundlePathcases - Auth middleware wiring: valid PEM, empty, and nonexistent-path (proves the field is consumed, not silently dropped)
- Envtest: asserts the rendered vmcp-config ConfigMap contains the mounted CA path AND the Deployment mounts the ConfigMap read-only at
/config/certs/<cm-name>
Non-blocking nit: pkg/vmcp/config/validator.go:121-129 and :169-177 are now two near-identical CA-bundle validation blocks. Extracting a validateCABundlePath(path, field string) error helper would prevent drift if a third caller ever appears — but with only two call sites, leaving it inline is defensible.
|
@jerm-dro I think this is one of those changes that reveal the leakage onto CRDs. The |
|
@ChrisJBurns Is this still pending the model-drift RFC you mentioned? I was looking at my issue #4918 again just because it's blocking some demo-ability and remembered the fix was blocked on this. I wonder if we could go ahead with the fix, knowing it'll leak into the CRD as an internal plumbing field? |
|
@danbarr It is indeed. If we wanted to merge and accept the leak, it's not ideal but its not the first time it will have happened as there is dead fields on the CRDs already |
JAORMX
left a comment
There was a problem hiding this comment.
Re-reviewed the current head (a950058) since my July approval. Production code is solid — the plumbing is correct end-to-end (resolver → converter → OIDCConfig.CABundlePath → TokenValidatorConfig.CACertPath → WithCABundle()), it mirrors the MCPServer fix from #3142/#3391 as the issue asked, the path validation is sound defense-in-depth, and the CRD YAMLs + docs are consistent.
One problem though: the new test code doesn't compile. Both test files reference mcpv1alpha1.* types that don't exist in that package (these CRDs live in mcpv1beta1):
cmd/thv-operator/pkg/vmcpconfig/converter_test.go:189-222— the three newCABundlePathtest cases usemcpv1alpha1.MCPOIDCConfigReference/mcpv1alpha1.MCPOIDCConfigTypeInline/mcpv1alpha1.MCPOIDCConfigTypeKubernetesServiceAccountcmd/thv-operator/test-integration/mcp-oidc-config/mcpoidcconfig_virtualmcpserver_integration_test.go:716+— the entire newContext("When MCPOIDCConfig inline.caBundleRef is set")block (16 references)
Reproduced locally:
vet: cmd/thv-operator/pkg/vmcpconfig/converter_test.go:189:20: undefined: mcpv1alpha1
vet: .../mcpoidcconfig_virtualmcpserver_integration_test.go:716:17: undefined: mcpv1alpha1
So neither the new unit tests nor the envtest scenario have ever run — the stated test coverage is unverified. Fix should be a mechanical s/mcpv1alpha1/mcpv1beta1/ in both files. Once that lands and CI goes green, this LGTM.
The merge from main renamed the operator API package from v1alpha1 to v1beta1, but the CA-bundle test cases added by this PR kept the old mcpv1alpha1 alias, which the files no longer import. This broke the typecheck (lint) and the Go test build. Point the new test cases at the mcpv1beta1 alias the files already import, matching the surrounding code. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The merge from main dropped the generated caBundlePath field from the VirtualMCPServer CRD manifests, so the operator-manifests check failed. Re-run task operator-manifests to restore the field under spec.config.incomingAuth.oidc. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
VirtualMCPServer referencing an
MCPOIDCConfigwith a ConfigMap-backedcaBundleRefmounted the CA into the pod but never told the vmcp binary where to find it, so OIDC discovery against a self-signed issuer failed withx509: certificate signed by unknown authority. This PR closes the plumbing gap by mirroring the earlier MCPServer fix (#3142, #3391): the vMCPOIDCConfignow carries the mounted CA path, and the incoming-OIDC middleware loads it into its HTTP trust store.Closes #4918
Medium level
CABundlePathtopkg/vmcp/config.OIDCConfig(consistent withStaticBackendConfig.CABundlePath) and validated it in the vMCP config validator (absolute path, no null bytes, no traversal).CABundlePathfromresolved.ThvCABundlePathinsidemapResolvedOIDCToVmcpConfigFromRefso both inlinecaBundleRefand the Kubernetes service-account CA default flow through.oidcCfg.CABundlePathintoauth.TokenValidatorConfig.CACertPathinsidenewOIDCAuthMiddleware; the downstream HTTP client builder already reads the field and appends it to the TLS trust store.caBundleRefand asserts both the rendered vmcp config ConfigMap and the Deployment's CA volume mount.Low level
pkg/vmcp/config/config.goCABundlePath stringfield toOIDCConfigwith doc comment and JSON/YAML tagcaBundlePath.pkg/vmcp/config/validator.goOIDCConfig.CABundlePath— reject null bytes,.., and non-absolute paths.pkg/vmcp/config/validator_test.gocmd/thv-operator/pkg/vmcpconfig/converter.goresolved.ThvCABundlePaththrough tovmcpconfig.OIDCConfig.CABundlePathinmapResolvedOIDCToVmcpConfigFromRef.cmd/thv-operator/pkg/vmcpconfig/converter_test.gopkg/vmcp/auth/factory/incoming.gooidcCfg.CABundlePathintoauth.TokenValidatorConfig.CACertPath.pkg/vmcp/auth/factory/incoming_cabundle_test.gocmd/thv-operator/test-integration/mcp-oidc-config/mcpoidcconfig_virtualmcpserver_integration_test.gocaBundlePath: /config/certs/<cm>/<key>and Deployment mounts the ConfigMap read-only.deploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_virtualmcpservers.yamlcaBundlePathunderspec.config.incomingAuth.oidc.deploy/charts/operator-crds/templates/toolhive.stacklok.dev_virtualmcpservers.yamldocs/operator/crd-api.mdType of change
Test plan
task lint-fixpasses (0 issues)task testpassestask buildpassesSpecial notes for reviewers
CABundlePath(matchingStaticBackendConfig.CABundlePathin the same package) overCACertPath(downstreamauth.TokenValidatorConfignaming) orThvCABundlePath(operator-resolver internal name) for consistency withinpkg/vmcp/config.ThvCABundlePath = defaultK8sCABundlePathinresolveFromK8sServiceAccountConfigwhenuseClusterAuthis true, so that path now works automatically. Covered by a dedicated converter test case.pkg/audit/zz_generated.deepcopy.gois stale relative to theDetectApplicationErrorsfield onpkg/audit.Config. Surfaced when runningtask operator-generate, but it's out of scope for this PR — would recommend a separate follow-up to regenerate.Generated with Claude Code