Repository navigation
Authenticate clients with SPIFFE X.509-SVIDs - #7092
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7092 +/- ##
==========================================
+ Coverage 80.93% 81.03% +0.10%
==========================================
Files 867 869 +2
Lines 88888 89081 +193
==========================================
+ Hits 71939 72189 +250
+ Misses 16944 16887 -57
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rdimitrov
left a comment
There was a problem hiding this comment.
The X.509 design is right, but there are rollout and compatibility gaps, and CI is red. Leaving comments rather than approving.
Design: Checking the X.509-SVID inside the fosite client-authentication strategy is the right place for it. That strategy owns client auth for every endpoint that authenticates clients (token and device authorization), reads only r.TLS, and re-checks the chain against the live bundle on every request. Moving X.509 and JWT-SVID onto one resolver means an association gives the same answer whichever credential is used. Removing the startup gate is what turns this on in production, which makes several pre-existing SPIFFE gaps reachable for the first time. Most of the findings below come from that.
-
pkg/authserver/server/spiffe_client_auth.go:77,:97(withrunner/tls_listener.go:86): any SPIFFE certificate takes over client auth on 8443. Once one association enablesspiffe_x509, the listener asks every client for a certificate. Any leaf that has aspiffe://URI SAN is then forced into the X.509 path. In SPIRE or Istio-style meshes, workloads usually present their SVID on every outbound TLS connection.- A JWT-SVID client whose association enables only
spiffe_jwtgetsinvalid_client. - A delegate client using
client_secret_postorprivate_key_jwtgetsinvalid_clientfrom the mixed-credential check. - A delegate client using HTTP Basic gets
invalid_requestat:135.
All of these worked on the same listener before the X.509 association was added. Suggested fix: use the X.509 path only when the request has no other client credential, or only when the leaf resolves to an association that enables
spiffe_x509. Otherwise treat the certificate as transport identity only. If rejecting is the intended design, state it as a breaking constraint and add a test for it. - A JWT-SVID client whose association enables only
-
docs/arch/18-spiffe-association-declarations.md:111/pkg/authserver/storage/redis.go:877: editing an association stalls the rollout on Redis. With Redis storage, a policy-only edit to an association conflicts with the placeholder already stored, soNewSPIFFEStorageDecoratorfails and new pods never become ready. Policy-only means scopes, audiences, resources or methods. Scenario: an operator narrows a SPIFFE client's scopes. The rollout hangs and the old pods keep serving the wider policy. The doc in this PR now says this "applies today" with no supported way out. Suggested fix: let policy-only edits update the placeholder so only a change of identity conflicts, or reject SPIFFE with Redis in validation until that works. -
SPIFFE-only configs pass the operator but fail at pod start. Take an MCPExternalAuthConfig or VirtualMCPServer with only
spiffeTrustDomainsandinboundGrants.spiffeClientAuth, and no upstreams, delegate clients or jwt-bearer issuer.- It passes the CRD rule (
mcpexternalauthconfig_types.go:927listsspiffeClientAuth),validateEmbeddedAuthServer, and the VirtualMCPServer reconcile check. - It is then rejected at runtime by
validateZeroUpstreamMode(pkg/authserver/config.go:2349), which doesn't count SPIFFE associations.
This gap was hidden while every SPIFFE config failed at startup. Suggested fix: count SPIFFE associations in
validateZeroUpstreamMode, or reject this config at reconcile time. - It passes the CRD rule (
-
The path that actually gets enabled is not tested end to end.
runner/spiffe_x509_listener_test.go:142-146only shows a 400 caused by the missingsubject_token. No test completes a token exchange throughnewServerwith an X.509-SVID or a JWT-SVID. JWT-SVID is tested only in packageserverwith a stubbed resolver. That leaves untested themay_actconsent check, the scope and audience limits fromregistration.NewSPIFFEClient, the real file bundle, the registry and storage. Suggested fix: add runner-level tests that issue a real token for each SVID type, assert itsclient_id, scopes and audience, and cover one rejection caused by the association's policy. -
CI lint is red. The only non-test failure is gocyclo on
(*RunConfig).Validate(pkg/authserver/config.go:507), pushed over the limit by the new loop at:558-564. Moving that loop into avalidateRuntimeSPIFFEBundleSources()helper fixes it and matches the shape of theConfigversion at:1973. The other failures are in tests: exhaustive and unusedwantOK, missingt.Helper(), deprecatedecdsa.PublicKey.X/Y, gci, and unparam. -
The PR body is missing user-facing changes and a test plan.
- It deletes exported
pkg/authserver/spiffesymbols (Middleware,ContextWithSPIFFEID,SPIFFEIDFromContext), which breaks embedders. - SPIFFE clients can no longer redeem ID-JAGs.
bundle_endpointandworkload_apiare now rejected at reconcile.
None of these are mentioned. No Test-plan box is checked. The PR also covers three logical changes across 13 non-test files: the X.509 path, the bundle-source gate, and the ID-JAG exclusion. Please list the breaking changes, and either split the PR or confirm that one PR is intended.
- It deletes exported
🤖 Reviewed with Claude Code
a96d69d to
28aca47
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 28aca47: all six earlier findings are resolved. One new security finding is a docs and threat-model fix, and one breaking change is missing from the PR body.
-
Any SPIFFE certificate taking over client auth on 8443: resolved. The X.509 path now runs only when a form
client_idnames an association that enablesspiffe_x509(checked byusesX509). Every other client uses the default strategy and ignores a presented certificate, and there are runner tests for delegates using HTTP Basic andclient_secret_post. -
Redis rollout stalling on a policy-only edit: resolved. Two placeholders can now replace each other and a WARN is logged. A placeholder and a non-placeholder still never replace each other.
-
SPIFFE-only configs failing at pod start: resolved. Both zero-upstream validators now count SPIFFE associations, and there is a runner test with no upstream.
-
No end-to-end test of the enabled path: resolved.
TestEmbeddedAuthServer_SPIFFETokenExchangeOverTLSissues tokens through the real TLS listener for an X.509-SVID and a JWT-SVID. It also covers the policy andmay_actrejections. -
CI lint red: resolved.
-
PR body missing breaking changes and test plan: resolved, except for the gap in 8 below.
-
docs/arch/18-spiffe-association-declarations.md:21,pkg/authserver/server/spiffe_client_auth.go:189-212: a proxy that re-encrypts traffic to 8443 becomes a confused deputy, and the docs say the opposite.- What's wrong: the client identity is whichever peer completed the TLS handshake. The doc says a mesh or Ingress in front of the listener "cannot supply a client identity". That holds for forwarded headers, but a gateway that re-originates TLS presents its own SVID.
- Scenario: an association
client_id=Xmatchesspiffe://td/ns/prod/*. A Gateway API or Envoy gateway inns/prodre-originates TLS to the 8443 Service with its own SVID. The newappProtocol: httpson that port invites gateways to do exactly that. An external caller then sendsclient_id=Xwith no credential of its own, the gateway's SVID verifies, and the caller authenticates as X. - Fix: say in the doc and in the
Newgodoc that 8443 must receive TLS end to end from the workload. Any hop that re-originates TLS is authenticated as itself, so association patterns must not match proxy or gateway identities. Consider droppingappProtocol: https, or document that it must not be paired with a backend TLS policy.
-
pkg/authserver/server/provider.go:622-631: a breaking change for direct callers is not listed.validateSPIFFEX509WiringmakesNewAuthorizationServerfail whenSPIFFEClientResolverandSPIFFEX509BundleSourceare set without the newSPIFFEX509ClientMatcher. An embedder that buildsAuthorizationServerParamsitself gets that error after upgrade, and the bundle source was previously documented as "not yet read". Add this to the breaking-changes list next to the removedspiffesymbols.
🤖 Reviewed with Claude Code
bbfd2fb to
325dfc8
Compare
|
Thanks for the re-review. On 7 and 8:
On
I also rebased onto main after the clock skew change landed. The only conflict was where the SPIFFE strategy is installed in |
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 325dfc8: approve. Both open findings are resolved, and the rebase conflict resolution is correct.
- Confused deputy via a TLS-terminating hop to 8443: resolved. The arch doc and the
Newgodoc now say TLS must reach the listener end to end, that a hop opening its own TLS is authenticated as itself, and that principal patterns must not match gateway identities. KeepingappProtocol: httpsis fine: it predates this PR and is now documented with the right warning. validateSPIFFEX509Wiringbreaking change not listed: resolved. The PR body lists theSPIFFEX509ClientMatcherrequirement under "Breaking for Go embedders".
The rebase merge in pkg/authserver/server/provider.go keeps main's #7088 chain unchanged on the non-SPIFFE path (guard, error mapping, clock-skew wrapper, fosite). Both SPIFFE arms return before the clock-skew layer, so SVID clients get no extra leniency, and delegate private_key_jwt clients that present a stray certificate still reach the skew wrapper.
🤖 Reviewed with Claude Code
Clients on the auth-server TLS listener can now authenticate with an X.509-SVID, the same way they can with a JWT-SVID. The certificate identity was previously extracted by middleware and never verified, so the server could not safely accept it. The client-authentication strategy now reads the peer certificate directly and verifies it against the live trust bundle on every request. It picks the verifier from the requested client, not from the certificate. A SPIFFE JWT assertion selects the JWT arm and the certificate is ignored. Otherwise the X.509 arm runs only when a client_id names an association that enables spiffe_x509, and it fails closed without a valid certificate. Any other request uses the default strategy, where a presented certificate is transport identity only, so JWT-SVID, delegate and public clients that merely present an SVID keep working on the same listener. Both arms share one resolver, so an association gives the same outcome whichever credential a workload presents. A presented chain is capped at four certificates before verification, which bounds the work a client can force per request. Only the file bundle source has a loader, so bundle_endpoint and workload_api are rejected at every validation point, including the operator's config resource. The "not yet enforced" startup gate is removed. Validation now also rejects an http issuer when an association enables spiffe_x509, a SPIFFE client_id that equals a delegate client_id, and SPIFFE associations with token exchange disabled. It accepts SPIFFE-only configs, with no upstream, delegate client or trusted issuer, in the auth server and vMCP validators. The unused exported helpers Middleware, ContextWithSPIFFEID and SPIFFEIDFromContext are removed. SPIFFE association clients are token-exchange only, so they are excluded from the ID-JAG jwt-bearer grant. A changed association now replaces its stored placeholder and logs a WARN instead of failing startup, so an edit rolls out on Redis. A rejected bundle sequence number and a stale bundle are logged once at WARN, so a bundle rollback no longer fails silently after 24 hours. Part of #6202. Co-authored-by: Mecatl <[email protected]>
325dfc8 to
ccf41b8
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of ccf41b8: still approve. The push only rebases the approved commit onto current main.
The production code is unchanged from 325dfc8. The rebase changed only tests and comments, to fit main's #7104 (the auth server no longer closes storage the caller passed in) and #7096 (the DCR store is now found by type assertion):
- The SPIFFE tests now close their own storage.
- The
authserver.Newgodoc merges main's wording with this PR's.
Neither main change undoes anything the approval relied on:
- DCR store lookup: it runs on the unwrapped storage before the SPIFFE decorator wraps it.
- Close:
server.Closestill releases the bundle source, and owned storage is still closed exactly once on error paths.
🤖 Reviewed with Claude Code
Summary
Workloads could not authenticate to the auth server with an X.509-SVID. The certificate was read by middleware and never verified, and any SPIFFE trust configuration was rejected at startup as a placeholder. This PR makes X.509 client authentication work and turns SPIFFE client authentication on for the
filebundle source.client_idnames an association that enablesspiffe_x509, and it never falls back. Any other request uses the default strategy and a presented certificate is transport identity only. A workload can present an SVID as transport identity on any connection, so JWT-SVID, delegate and public clients must keep working on the same listener.filesource has a loader, sobundle_endpointandworkload_apiare rejected at every validation point, including the operator's config resource.httpissuer, a SPIFFEclient_idequal to a delegateclient_id, and associations with token exchange disabled are rejected.jwt-bearergrant.Middleware,ContextWithSPIFFEIDandSPIFFEIDFromContextare removed. Nothing in the repo used them.Part of #6202.
Type of change
Test plan
task test): the full run on this branch rebased onmainexited 0 and printed no failures. The packages this PR touches (./pkg/authserver/...,./pkg/vmcp/config/, and the operatorapi/v1beta1,controllersandcontrollerutilpackages) also passed in a separate run that reports the realgo testexit code.task test-e2e)task lint-fix): ran over the whole repo after rebasing onmain, 0 issues, no files changed.task docs,operator-manifestsandcrdref-genproduce no diff.New tests issue real tokens through the TLS listener for an X.509-SVID client and a JWT-SVID client and check
client_id, scope, audience andact.sub. They also cover scope and audience rejection from the association's policy, themay_actconsent check, delegate clients that present a stray certificate, and a SPIFFE-only server with no upstream. There is no kind e2e in this PR.API Compatibility
The CRD changes are description-only: five type comments, regenerated into the CRD YAML,
crd-api.md, swagger and the SDK. No schema, validation rule or default changed. The new reconcile-time checks apply only to SPIFFE configs, which could not start before this PR.v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
Most of the diff is tests, generated CRD and SDK output, and docs. Code changes, by area:
pkg/authserver/server/spiffe_client_auth.go,server/provider.go,spiffe/certificate.go,server/client_assertion_errors.gospiffe/middleware.go,spiffe/context.go,runner/tls_listener.gopkg/authserver/config.go,spiffe_trust.go,runner/embeddedauthserver.go,pkg/vmcp/config/validator.go, operatormcpexternalauthconfig_types.goandvirtualmcpserver_controller.gostorage/types.go,storage/spiffe_decorator.go,spiffe_bundle_source.goserver_impl.go,spiffe_association_registry.go,spiffe_preflight.goDoes this introduce a user-facing change?
Before:
spiffeTrustDomainswas rejected with "SPIFFE client authentication is not yet enforced by this build".MCPExternalAuthConfigwith abundle_endpointorworkload_apisource reported valid, and the workload that used it failed at reconcile.After:
filebundle source starts and enforces JWT-SVID and X.509-SVID client authentication.client_idnames aspiffe_x509association authenticates with its client certificate only, at every client-authenticating endpoint on the 8443 listener (token and device authorization). A failure returnsinvalid_client(401), an ambiguousclient_idreturnsinvalid_request(400), and there is no fallback. Every other client ignores a presented certificate. A chain of more than four certificates is rejected.spiffe_x509. No SPIFFE config could start before, so this is new behaviour in practice.spiffe_x509needs atlsListenerand anhttpsissuer. Anhttpissuer fails at validation, and the operator reports it as a condition.bundle_endpointandworkload_apiare rejected at validation:MCPExternalAuthConfigshowsValid=Falseand a VirtualMCPServer shows a failedspec.authServerConfigcondition. The CRD schema still accepts them.client_idequal to a delegateclient_idis rejected at validation.unauthorized_client.configured client replaced with a different policy, withold_resources,new_resourcesoridentity_changedwhen those changed. During a rolling update each replica serves its own configuration, and nothing marks when the rollout ends.spiffeauth.Middleware,ContextWithSPIFFEIDandSPIFFEIDFromContextare removed. Nothing in this repo used them.NewAuthorizationServernow returns an error whenSPIFFEClientResolverandSPIFFEX509BundleSourceare set without the newSPIFFEX509ClientMatcher. Both fields have been in releases since v0.48.0 and the X.509 bundle source was documented as "not yet read", so a hand-builtAuthorizationServerParamsthat sets them now needs the matcher too.SPIFFEIDFromCertificate, and theSPIFFEX509ClientMatcherfield onAuthorizationServerParamsandAuthorizationServerConfig. Embedders ofauthserver.Newmust terminate TLS and request client certificates themselves, and TLS must reach them end to end. A proxy or gateway that opens its own TLS connection is authenticated as itself, so association principal patterns must not match proxy or gateway identities.Special notes for reviewers
spiffe_client_auth.go), validation (config.go,spiffe_trust.go, the operator types), the placeholder and bundle-reload changes, and the docs.bundle_endpointandworkload_apiso the API can be relaxed later without a schema change. Reconcile-time Go checks reject them until a loader exists. Until then thebundle_endpointURL check is unreachable throughMCPExternalAuthConfigadmission.client_credentialsgrant from a later branch.jticheck.inboundGrants: {tokenExchange: {}}passes CRD admission and fails at runtime.