Repository navigation
Report unsupported external auth types - #6242
Conversation
|
Hi @jhrozek — no rush at all, just flagging that this is ready for review whenever you have time. Happy to adjust anything about the approach. |
jhrozek
left a comment
There was a problem hiding this comment.
Thanks for digging into #5930 — the compatibility matrix itself is right. I checked every cell against the code rather than against the docs: the VirtualMCPServer and MCPServerEntry rows match the converter registry in pkg/vmcp/auth/converters/interface.go exactly, and the MCPServer/MCPRemoteProxy rows line up with the dispatcher switch in controllerutil/tokenexchange.go, including the non-obvious awsSts-on-MCPServer case, which fails on the empty-RemoteURL check in pkg/runner/middleware.go rather than silently no-opping. I also traced the reconcile flow to confirm it returns before the Deployment block, so this does close the unauthenticated-deploy footgun rather than just annotating it.
My main concern is scope. The issue asked for two things: reconcile-time validation surfaced as status conditions, and the supported consumer kinds documented in the field godoc. Both are here. But a lot came along with them, and some of it changes behaviour nobody asked to change.
The one I'd push back on hardest is the outgoing-auth precedence change in pkg/vmcp/aggregator/discoverer.go. In discovered mode an explicit per-backend override now wins over auth discovered from the backend resource, where previously discovered auth won. That decides which credential a live backend authenticates with. It may well be the right call, but it needs its own issue and its own discussion — it shouldn't be settled as a side effect of a PR about reporting unsupported types. Same goes for ExplicitBackends and its nil-versus-empty compatibility semantics, which exist only to support that change.
ExcludedBackends and DefaultAuthFailed are closer to the mark but still past the ask. The issue's vMCP line is "surface the skipped backend in VirtualMCPServer status rather than log-and-drop", which is a status condition. What's here is a fail-closed routing rework threaded through the discoverer, the watcher and the static path. I'd keep the condition and leave routing semantics for a separate change.
The examples fix (snake_case to camelCase under examples/operator/external-auth/) is a real bug and a good catch, but it's unrelated — worth its own PR so it can land quickly on its own merits.
Two things I'd treat as blocking regardless of what happens to the scope:
ensureVmcpConfigConfigMap now deep-copies the VirtualMCPServer, sets Spec.OutgoingAuth to nil, runs converter.Convert against that, then patches Source back on afterwards. That line is the only caller of Convert in the tree, so Converter.convertOutgoingAuth and convertBackendAuthConfig are now unreachable in production — they survive only in their own unit tests, which will keep passing while covering code that no longer runs. The controller already had a near-duplicate in convertBackendAuthConfigToVMCP, and this PR updates that copy to match the converter's behaviour. Better to pick one and delete the other than to disable the original by feeding it a modified input.
ExternalAuthConfigValidated on MCPServer has no path back to True. Both False branches are there (the new UnsupportedAuthType one and the pre-existing MultiUpstream one), plus RemoveStatusCondition when the ref goes away, but there's no success setter — MCPRemoteProxy has the matching block at the end of its handleExternalAuthConfig and MCPServer doesn't. Point a server at a two-upstream config, then edit that config down to one, and the condition stays False permanently. The MultiUpstream half predates this PR, but the new branch reproduces it in a function you're already editing.
Smaller things, several of which follow conventions already present in the files being changed:
excludedBackendsandexplicitBackendsneed+listType=atomic. That's what's failing the CRD Schema Compatibility check, and there's an existing+listType=atomicabout 200 lines up inpkg/vmcp/config/config.go. The other red checks aren't yours: the E2E lifecycle jobs all died on a Docker Hub 502 pullingpython:3.9-slim, and the unit-test failure is a flaky transparent-proxy test unrelated to this change.pkg/vmcp/backendregistry/registry.go:130still callsNewBackendWatcherwithout the auth config, and the comment directly above it asks that it stay in sync withcli/serve.go. It's only reachable frominternal/exampleembeddertoday, butNewKubernetesBackendRegistryis the exported constructor for embedders and now has no way to pass anOutgoingAuthConfigat all.- The "failed default means deny" rule is implemented three times:
ResolveForBackend,dependsOnFailedDefaultin the discoverer, and again inline inbackend_reconciler.go. They agree today, nothing keeps them agreeing, and drift reopens the hole this is meant to close. Same foroutgoingAuthExclusionSet, copy-pasted verbatim into two packages — it'd be better as a method onOutgoingAuthConfig. support_test.gore-declaressupportMatrixas a literal and assertsSupports()matches it, so it can only fail on a typo made differently twice. The test that would earn its place asserts the vMCP rows equal the key set ofconverters.DefaultRegistry()and the MCPServer/MCPRemoteProxy rows equal the non-no-op arms of the dispatcher switch. That one breaks when someone adds a converter and forgets the table, which is the failure this package exists to prevent.- Three new
...WithAuthConfigconstructors for two production callers of the old ones. Changing the signatures is smaller. - MCPRemoteProxy sets
Ready=FalsewithReason: DeploymentNotReadyfor an external-auth configuration error.
One structural thought worth weighing before the next revision. The silent no-ops in AddExternalAuthConfigOptions are the actual subject of #5930 and they're still there — headerInjection, upstreamInject and xaa all still return nil. The support matrix is a second, hand-maintained source of truth sitting beside them, with nothing enforcing agreement. Making those arms return the UnsupportedTypeError directly would put the guard at the choke point every consumer already routes through, and the MCPServer/MCPRemoteProxy rows could then derive from the switch instead of restating it.
8fda367 to
57eb59b
Compare
|
Thanks for the thorough review, @jhrozek — checking the matrix cell-by-cell against the code is exactly what this needed, and you were right about the scope. Reworked accordingly; the diff against main went from ~+3,300 to +1,620/−380, and every runtime behaviour change is gone. Scope
The two blockers
Structural suggestion — taken. Smaller items. Validation: build and |
|
@3nesdeniz Thanks for narrowing the PR after Jakub’s review. I found a change in failure behavior that I think we should resolve before merging. When an explicitly configured Could you preserve the protection against that fallback while surfacing the status condition, and add a test of the resulting config or routing behavior? The PR also currently has merge conflicts; please resolve those against the latest |
57eb59b to
c61237c
Compare
|
@Sanskarzz thanks, you were right. Removing the converter's outgoing-auth path is what let a config be published without the failed entry. What changed in this push:
Merging the converter's and the reconciler's conversion into one path changes which failures are fatal, so I left it out of this PR. Locally, the operator unit tests with |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6242 +/- ##
==========================================
+ Coverage 82.15% 82.33% +0.17%
==========================================
Files 932 936 +4
Lines 94529 95434 +905
==========================================
+ Hits 77659 78572 +913
+ Misses 16865 16857 -8
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MCPExternalAuthConfig has nine types, but each consumer kind implements only a subset, and some unsupported combinations failed silently: the resource read as valid, the workload ran, and the credential was never injected (stacklok#5930). Validate the consumer/type combination at reconcile time and surface failures as ExternalAuthConfigValidated=False with reason UnsupportedAuthType on MCPServer and MCPServerEntry, and as per-entry conditions on VirtualMCPServer. On MCPServer and MCPServerEntry these terminal configuration errors return without requeueing; the watches on the spec and the referenced config trigger reconciliation when either changes. Document each consumer's supported types in the field godoc so the CRD schemas and reference docs carry them. The support matrix lives in one place and cannot drift from the code: the vMCP-backed rows derive from the converter registry, and the MCPServer/MCPRemoteProxy rows are enforced at the run-config dispatch in AddExternalAuthConfigOptions, which now takes the consumer and returns a typed UnsupportedTypeError for a type outside the consumer's row. A test drives that dispatch with every type for both consumers and requires agreement with the matrix in both directions. headerInjection, upstreamInject, and xaa stay accepted on MCPServer and MCPRemoteProxy. The proxy runner does nothing with them, but discovered mode reads the reference from the backend resource and the VirtualMCPServer applies it when it calls that backend, so rejecting them on the backend would take the backend, and discovered mode with it, down. The field godoc now says who applies them. On VirtualMCPServer the published config does not change. The converter still resolves every entry declared in spec.outgoingAuth and fails as a whole when one cannot be resolved, so no config is written with the entry missing and no backend falls back to another credential or to no auth. The reconciler now records which entry failed, and why, before returning that error, so the refusal is explained in status and not only in the operator log. The unsupported-type condition is owned by local validation, like the CA bundle and run-config failures, so the mirror's clear branch leaves it in place instead of removing and re-adding it on every reconcile. Closes stacklok#5930. Signed-off-by: Enes Deniz <[email protected]>
c61237c to
5da3fb9
Compare
|
One more change after CI. The Discovered mode reads the auth reference from the backend resource. The VirtualMCP e2e suites rely on that: an MCPServer backend references a So That leaves one cell of #5930 answered by documentation instead of a condition: a standalone MCPServer or MCPRemoteProxy with |
Resolve conflicts with the OSS Entra OBO port (stacklok#7201) and the external auth mirror rework (stacklok#7162): - Keep the UnsupportedAuthType check alongside main's OBO incoming-auth check in MCPServer, and treat UnsupportedAuthType as a local-validation reason in isLocalValidationFailure. - Route the MCPServer terminal-error path through main's markExternalAuthConfigFailed, keeping the PR's skip of unchanged status writes. - Drop "obo when an enterprise handler is registered" wording and the deprecated EnterpriseRequired reason from the PR's godoc and tests; obo is now built in. - Move the support-matrix dispatch test into a fresh tokenexchange_test.go (main deleted the old file) and pass the consumer in main's OBO tests. - Regenerate CRD manifests and API docs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Chris Burns <[email protected]>
Merging main added the obo incoming-auth check next to the unsupported-type check in handleExternalAuthConfig, pushing its cyclomatic complexity past the gocyclo limit. Move both consumer checks into validateMCPServerExternalAuthConsumer. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Chris Burns <[email protected]>
|
/retest |
|
Thanks for sticking with this through three rounds. The scope is right now, and both earlier blockers (the unreachable converter path and the missing success setter) plus the fail-closed concern on declared outgoing auth are resolved. I checked the head against #5930, ran What I saw work
One thing worth adding to the description: on 1. The The issue singles out A non-failing advisory condition would close this without hurting discovered mode: keep 2. An inline VirtualMCPServer stays I changed an inline-mode VirtualMCPServer's So it reads as having applied generation 2 while it serves generation 1's auth, which is the "looks configured, isn't" pattern #5930 is about. The reconcile also returns a plain error, so it requeues with backoff forever (17 reconcile errors in the first 3 minutes) even though nothing heals until the spec changes. The Ready/observedGeneration part predates this PR. But this PR is where the operator first knows the refusal is a terminal 3. PR description Per
It should also reference #5930 ( |
When an entry declared in spec.outgoingAuth referenced an auth type VirtualMCPServer does not support, the operator kept the previous ConfigMap but still reported Phase=Ready with observedGeneration advanced, and requeued with backoff forever although only a spec or referenced-config change can heal it. Treat a conversion failure as a SpecValidationError when every failed declared entry is an UnsupportedTypeError: Phase=Failed, Ready=False / UnsupportedAuthType, no requeue. Other failures still return the error and retry. reconcileResources now ends the reconcile on a SpecValidationError. Before, the pod-based status pass ran afterwards and overwrote the Failed phase, which also affected the existing delegate-client, OIDC file path and auth server integration validation errors. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Chris Burns <[email protected]>
|
/retest |
MCPServer and MCPRemoteProxy accept headerInjection, upstreamInject and xaa so that a VirtualMCPServer can discover the reference on the backend and apply it. The proxy runner itself does nothing with them, but the backend reported ExternalAuthConfigValidated=True with "is valid", so a backend used on its own read as protected by a config that is never applied. That is the headerInjection case stacklok#5930 singles out. Keep the condition True, since failing it would take discovered mode down, but give it the reason AppliedByVirtualMCPServer and a message saying the backend does not apply the type itself and it takes effect only when a VirtualMCPServer discovers the backend. Both controllers use one helper built on externalauthsupport.AppliedByVirtualMCPServer. Signed-off-by: Enes Deniz <[email protected]>
|
Thanks for the careful review and for running the upgrade test, @rdimitrov, and thanks @ChrisJBurns for taking item 2 in a2e4bf7. Status of the three points: 1. 2. VirtualMCPServer staying 3. PR description. Rewritten to the template: Type of change, Test plan, API compatibility, and a user-facing section with before/after for each case, including your note that MCPServer + Tests on the pushed head: operator unit suites with |
Summary
MCPExternalAuthConfig has nine
spec.typevalues, but each consumer kind implements only a subset, and the unsupported combinations fail silently: the resource reads as valid, the workload runs, and the credential is never injected. This PR delivers the two things #5930 asks for:ExternalAuthConfigValidated=Falsewith reasonUnsupportedAuthTypeon MCPServer and MCPServerEntry, and a per-backend condition on VirtualMCPServer (including the discovered-mode case where abearerToken-backed MCPRemoteProxy used to vanish from aggregation with only a log line). These are terminal configuration errors and return without requeueing; the existing watches trigger reconciliation when the spec or the referenced config changes.MCPExternalAuthConfigSpec.Typeand on every consumer'sexternalAuthConfigRef, flowing into the generated CRD schemas and reference docs.The support matrix lives in
cmd/thv-operator/pkg/externalauthsupportand cannot drift from the code: the VirtualMCPServer/MCPServerEntry rows derive from the converter registry (converters.DefaultRegistry().RegisteredTypes()), and the MCPServer/MCPRemoteProxy rows are enforced at the run-config dispatch —AddExternalAuthConfigOptionsnow takes the consumer and returns a typedUnsupportedTypeErrorfor a type outside the consumer's row.TestAddExternalAuthConfigOptions_EnforcesSupportMatrixdrives the real dispatch with all nine types for both consumers and requires agreement with the matrix in both directions.headerInjection,upstreamInject, andxaastay accepted on MCPServer and MCPRemoteProxy, and now say what they are. The proxy runner does nothing with them, but discovered mode reads the reference from the backend resource and the VirtualMCPServer applies it when it calls that backend. Rejecting them on the backend would take the backend, and discovered mode with it, down (the VirtualMCP e2e suites cover exactly this). So the condition staysExternalAuthConfigValidated=True, but with reasonAppliedByVirtualMCPServerand a message saying the backend does not apply the type itself and it takes effect only when a VirtualMCPServer discovers the backend. A standalone MCPServer with aheaderInjectionconfig, the case #5930 singles out, no longer reads as plainly valid. MCPServer still rejectsbearerTokenandawsSts; MCPRemoteProxy has no type left to reject.On VirtualMCPServer the published config does not change. The converter still resolves every entry declared in
spec.outgoingAuth(defaultandbackends) and fails as a whole when one cannot be resolved, so no config is written with the entry missing and no backend falls back to another credential or to no auth. What this PR adds is the reporting: the reconciler records which entry failed, and why. When every declared entry that failed has an unsupported type, the refusal is terminal: the resource reportsPhase=FailedwithReady=False(reasonUnsupportedAuthType) and is not requeued, the same way MCPServer treats it. Any other failure (a missing config, a source reportingValid=False) keeps returning its error and is retried. Auth discovered from a backend's ownexternalAuthConfigRefkeeps today's behaviour, with the more specificUnsupportedAuthTypereason on its condition.Closes #5930
Type of change
Test plan
Unit tests (
task test)E2E tests (
task test-e2e)Linting (
task lint-fix)Manual testing (describe below)
Unit:
go test -raceon everything under./cmd/thv-operator/...excepttest-integration, plus./pkg/vmcp/auth/converters/...and./pkg/vmcp/config/....Integration (envtest 1.31.0, run locally):
mcp-external-auth,mcp-remote-proxy,mcp-serverandvirtualmcpsuites.Linting:
go build,go vet,gofmtandgocyclo(limit 15) on the touched trees.golangci-lintv2.15.0 was run on the earlier pushes; for the latest push I rely on CI for it.E2E was not run locally; it runs in CI.
Generated CRDs, Helm CRD templates and
docs/operator/crd-api.mdwere regenerated when the API godoc changed. The latest push adds a condition reason constant only, so nothing is regenerated by it.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.No field, type or CRD schema changes shape. The schema diff is godoc only. Two condition reasons are new:
UnsupportedAuthTypeandAppliedByVirtualMCPServer.Does this introduce a user-facing change?
Yes. What an operator can observe, before and after:
bearerTokenorawsStsconfig. Before:ExternalAuthConfigValidated=True. After:ExternalAuthConfigValidated=False / UnsupportedAuthType,Phase=Failed. The existing Deployment keeps running but no longer receives updates until the reference is fixed. Onmainthis combination is not inert: forbearerTokenthe proxy runner crash-loops withsecrets provider not configured. So for existing users the change turns a crash loop into a clear condition, not a working server into a failed one.headerInjection,upstreamInjectorxaaconfig. Before:ExternalAuthConfigValidated=True / ExternalAuthConfigValid, messageMCPExternalAuthConfig '<name>' is valid. After: stillTrue, but reasonAppliedByVirtualMCPServer, and the message says the backend does not apply the type itself and it takes effect only when a VirtualMCPServer discovers the backend. The workload is unaffected. Anything matching on the old reason for these three types will change.Valid=False. Before:Phase=Valid. After:Phase=Failed. The vMCP now skips the entry.ConversionFailed. After:UnsupportedAuthTypefor unsupported types. Anything alerting on the old reason will change.spec.outgoingAuthentry (defaultorbackends) has an unsupported type. Before: the config build failed with a plain error and was retried with backoff indefinitely; a resource that was already serving keptPhase=Ready,Ready=TrueandAuthConfigured=Trueat the newobservedGeneration. After: the published config is still left untouched, and the resource reportsPhase=FailedandReady=False / UnsupportedAuthType, with a message naming the entries, and is not requeued. It heals on the next change to the spec or to the referenced MCPExternalAuthConfig.Special notes for reviewers
SpecValidationErrornow ends the VirtualMCPServer reconcile (a2e4bf7). Before,Reconcilewent on to the pod-based status pass, which overwrote theFailedphase with the state of the pods still running the previous config. This also applies to the threeSpecValidationErrorpaths that were already inensureVmcpConfigConfigMap(invalid delegate clients, invalid incoming OIDC file paths, invalid auth server integration): theirPhase=Failednow persists as well.UnsupportedAuthType. A declared entry that fails for another reason next to an unsupported one keeps the plain error and the retries, so a missing config that appears later is still picked up. The config-build tests cover that mixed case.ConditionReasonAppliedByVirtualMCPServersits next toConditionReasonUnsupportedAuthTypeinconditions.goand is used by both MCPServer and MCPRemoteProxy through one helper,externalAuthValidCondition.Out of scope, split out per review
pkg/vmcpruntime (discoverer, watcher, backend reconciler, workloads, CLI) is untouched by this PR. The precedence question is now Discovered-mode outgoing auth: should an explicit per-backend override win over discovered auth? #6329.Generated with Claude Code