Repository navigation
feat(authbridge): replace spiffe-helper with in-process go-spiffe SDK Provider - #432
Merged
huang195 merged 27 commits intoMay 23, 2026
Merged
Conversation
Captures the agreed approach for kagenti-extensions#332: an in-process spiffe.Provider built on go-spiffe SDK replaces the bundled spiffe-helper binary, exposing in-memory X509Source and JWTSource for hot paths plus an opt-in file-mirror goroutine that preserves /opt/svid*.pem and /opt/jwt_svid.token for external readers (debugging, e2e probes, future envoy-sidecar mTLS via filesystem SDS). Scope: authbridge Go only. Operator, chart, and backend cleanups are follow-ups; the kagenti chart adding spiffe.jwt_audience rendering must precede the implementation PR. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
19-task TDD plan covering: workload X.509/JWT sources, atomic file mirror, Provider type, top-level spiffe config block, plugin dependency injection (BuildWithSPIFFE + ProviderConsumer), main.go rewiring for proxy/envoy/lite, entrypoint and Dockerfile cleanups, and File*Source deletion. Self-review checklist and spec coverage table included. Companion to docs/superpowers/specs/2026-05-22-authbridge-go-spiffe-sdk-design.md. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Implements the existing X509Source interface against *workloadapi.X509Source. Used by the upcoming Provider type to feed authbridge's TLS listeners directly from the SPIRE Workload API without spiffe-helper. Adds github.com/spiffe/go-spiffe/v2 v2.6.0 as a direct dependency. Tests exercise the adapter through a small package-private x509SVIDFetcher interface satisfied by *workloadapi.X509Source in production and a hand-rolled fake in tests, since go-spiffe's fakeworkloadapi lives under internal/test and is not importable from outside the SDK. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Code-quality review feedback: replace //nolint:unused with a compile-time interface assertion (var _ X509Source = ...) so the contract is verified at build time and self-documenting. Tighten the TrustBundle comment so it doesn't overpromise federation support that GetX509BundleForTrustDomain doesn't actually deliver. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
workloadJWT fetches JWT-SVIDs for a fixed audience via *workloadapi.JWTSource. Will be returned by the upcoming Provider so the tokenexchange plugin can produce client-assertion JWTs without spiffe-helper. Mirrors workload_x509.go's seam-via-package-private- interface approach since go-spiffe's fake is internal. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
POSIX same-directory tmp+rename so external readers of /opt/svid*.pem during rotation always observe either the old or the new file, never a partial write. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Subscribes to X.509 Updated() and runs a JWT refresh loop at 90% lifetime, writing svid.pem / svid_key.pem / svid_bundle.pem / jwt_svid.token via atomic tmp+rename. Mirror failures are logged at WARN; the in-memory hot path remains the source of truth. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
NewProvider blocks until the first X.509-SVID arrives (cold-start gate via workloadapi.NewX509Source's context), constructs the JWT source only when JWTAudience is non-empty, and starts the file-mirror goroutine when MirrorFiles is true. Close shuts down both SDK sources and the mirror via context cancellation. Unit tests cover JWTSource nil-guard and Close idempotence with direct struct construction; the cold-start integration path lives behind //go:build integration since the SDK's fake is internal. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
New SPIFFEConfig with Socket, JWTAudience, MirrorFiles, MirrorDir. Defaults match today's helper.conf-driven setup. Cross-block validation against tokenexchange identity arrives in a later commit (Task 8 in the plan). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Replaced by the new top-level spiffe block + Provider. Old fields are silently ignored by the yaml loader (pinning test added) so chart- rendered configs continue to boot during the cross-repo migration. cmd/* main.go references will be rewired in plan tasks T12-T14. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Token-exchange's spiffe identity path no longer reads a file path from its own config; the audience comes from the framework spiffe block and the JWTSource will be injected by plugins.BuildWithSPIFFE (planned in T10/T11). The buildClientAuthFrom function panics on the spiffe path for now -- only callable through tests, and the existing test suite avoids it by using client-secret identity. Cross-block validation in config.Validate rejects configs that set identity.type=spiffe without spiffe.jwt_audience. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Tighten the spiffe-identity panic recover in plugin_test.go so that only the expected T11-related panic is treated as 'skip until wired'; unrelated panics fail the test. Document validate.go's choice to apply cross-block checks to all token-exchange entries regardless of on_error: off. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Plugins implement this to receive the framework Provider before Configure runs. Used by the upcoming plugins.BuildWithSPIFFE. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
New build entrypoint that injects a *spiffe.Provider into every plugin satisfying spiffe.ProviderConsumer before Configure runs. Existing Build() is unchanged and still used by call sites that don't need SPIFFE. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
TokenExchange now implements spiffe.ProviderConsumer. The spiffe identity path uses provider.JWTSource() (a workload-api-backed JWT source) instead of constructing a FileJWTSource from a config field. The framework's plugins.BuildWithSPIFFE injects the Provider before Configure runs. Replaces the T8-era panic with a proper error return when the provider is absent. The skipped T8 test now runs to completion. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Replaces the FileX509Source + helper.conf-driven file-wait pattern with spiffe.NewProvider, which blocks until the first X.509-SVID arrives in memory. mTLS listeners get provider.X509Source(); the plugin pipeline is built via BuildWithSPIFFE so token-exchange's spiffe identity path receives an injected JWTSource. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Same pattern as authbridge-proxy: build spiffe.NewProvider from cfg.SPIFFE, switch to plugins.BuildWithSPIFFE so token-exchange's spiffe identity path receives an injected JWTSource. envoy-sidecar mode currently doesn't terminate mTLS at the authbridge process, so no X509Source is consumed here yet — but the Provider's file mirror preserves the on-disk SVID files for upcoming envoy mTLS work. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Same pattern as authbridge-proxy (T12) and authbridge-envoy (T13): build spiffe.NewProvider from cfg.SPIFFE, drop the file-existence wait loop (NewProvider blocks until first SVID), pass provider.X509Source() to mTLS listeners, use plugins.BuildWithSPIFFE so token-exchange gets the injected JWTSource. This unblocks cmd/authbridge-lite which has been failing to build since T7 dropped the MTLSConfig file-path fields. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Authbridge processes now talk to the SPIRE agent socket directly via the in-process spiffe.Provider; the bundled spiffe-helper binary is no longer needed. Phase 1 of each entrypoint is gone, and the remaining phases are renumbered. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Each combined image shrinks by ~16 MB after spiffe-helper binary removal. Verified locally: authbridge-proxy: 44.3 MB -> 28.5 MB authbridge-envoy: 146 MB -> 130 MB authbridge-lite: 44.2 MB -> 28.3 MB The agent socket mount stays in place; it is now consumed by authbridge's in-process Provider (via go-spiffe's WorkloadAPI client) instead of spiffe-helper. Also drops the now-unused binutils apk package and the spiffe-stripper build stage from each Dockerfile. go.mod / go.sum entries for github.com/spiffe/go-spiffe/v2 are added to each cmd/authbridge-* module so the Docker build (which runs with GOWORK=off) can resolve the dependency that authlib introduced in T1-T15. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
No runtime caller after the Provider/workloadX509 migration. Deletion follows the kagenti CLAUDE.md guidance to remove unused code rather than leave it behind. The X509Source interface is preserved in source.go for current consumers (Provider, listeners, authlib/tls). Also drops the now-stale FileX509Source mention from provider.go's DefaultMirrorDir doc comment. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
No runtime caller after the Provider/workloadJWT migration. Plugin now consumes a JWTSource injected via plugins.BuildWithSPIFFE. The JWTSource interface declaration in source.go is preserved. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
The credential files are now written by an in-process goroutine instead of the spiffe-helper binary. Authbridge's hot path reads SVIDs from memory; the files exist for external readers (e2e tests, debugging shells, future Envoy filesystem SDS). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
go-jose/v4 v4.1.3, pulled in transitively via go-spiffe/v2 v2.6.0, has a high-severity JWE-decryption panic flagged by the dependency-review CI gate. v4.1.4 contains the fix. Updated as an indirect dep in authlib + all three cmd/* modules. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Confirmed dead env var: nothing in authbridge/operator/scripts reads it. Companion to dropping JWT_AUDIENCE from kagenti chart and kagenti-operator (separate PRs). The audience for JWT-SVID client assertions is sourced from the SPIFFE provider's per-tokenexchange config, not a cluster-wide env var. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
huang195
force-pushed
the
feat/spiffe-go-sdk-replace-helper
branch
from
May 22, 2026 19:35
4db23e3 to
cc8d722
Compare
The audience for the JWT-SVID client assertion is only consumed by tokenexchange's spiffe identity path. Previous design exposed it at framework level via spiffe.jwt_audience, which forced cross-block validation and made the field exist (but be ignored) when type= client-secret. Move it to tokenexchange.identity.jwt_audience. Provider.JWTSource(audience) now takes audience as a per-call parameter; workloadapi.JWTSource is constructed lazily on first use. Provider.MirrorJWT(ctx, audience) is the new plugin-driven path for writing /opt/jwt_svid.token; tokenexchange's Init calls it when type=spiffe so the file mirror only fires when there's a consumer. The cross-block validation in config.validateCrossBlock is gone; tokenexchange's Configure validates jwt_audience locally. Companion chart commit will move the rendering from a top-level spiffe block to the per-plugin tokenexchange.identity block. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
5 tasks
- provider_integration_test.go: align with the new ProviderConfig shape (no JWTAudience field) and the new JWTSource(audience) two- return signature. Without this the file fails to compile under `go test -tags=integration` (CI runs without the tag, so this slipped). - Provider.MirrorJWT: harden the single-audience contract. A second call with a DIFFERENT audience now returns an explicit error rather than silently spawning a second goroutine that races the first on the shared jwt_svid.token path. The audience-conflict check runs before SDK construction so misconfiguration fails fast at the config-validation layer. New unit test pins the behavior. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
3 tasks
pdettori
approved these changes
May 23, 2026
pdettori
left a comment
Member
There was a problem hiding this comment.
Clean migration from external spiffe-helper binary to in-process go-spiffe/v2 SDK Provider.
Reviewed: Go implementation (Provider, mirror, DI, config), Dockerfiles, entrypoint scripts, security (file perms, socket validation, goroutine lifecycle, atomic writes), backward compatibility.
Findings: No blocking issues. Implementation is well-structured — 27 logically sequenced commits, proper context cancellation, mutex-protected lazy init, atomic file writes with correct modes (key 0600), and clean unknown-field tolerance for rolling upgrades. The go-jose/v4 CVE bump is a welcome bonus.
All CI checks pass.
5 tasks done
This was referenced Jun 2, 2026
3 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #332.
Summary
Replace the bundled
spiffe-helperbinary in authbridge images with an in-processgo-spiffe v2SDK integration. A newspiffe.Providerper container owns oneworkloadapi.Clientand exposes:X509Sourceconsumed by mTLS listeners (no per-handshake file I/O).JWTSourceconsumed by thetokenexchangeplugin via a newplugins.BuildWithSPIFFEdependency-injection mechanism./opt/svid.pem,/opt/svid_key.pem,/opt/svid_bundle.pem, and/opt/jwt_svid.tokenatomically on every rotation — preserving today's external-reader contract (Envoy filesystem SDS, e2e probes, debugging shells).The SPIRE agent socket mount stays unchanged; the
spiffe-helperbinary,helper.conf, and the helper-launch logic in all threeentrypoint.shfiles are gone.Why
spiffe-helperbinary is removed fromauthbridge-proxy,authbridge-envoy, andauthbridge-liteimages./opt/svid*.pempaths the new mirror writes, no auth bridge change needed when that work lands.Scope
authlib/spiffe/, config schema,tokenexchangeplugin, plugin DI, all three cmd binaries, entrypoint scripts, Dockerfiles,authbridge/CLAUDE.md,demos/mtls/README.md).spiffe: {}block and per-plugintokenexchange.identity.jwt_audience), kagenti-operator webhook (spiffe-helper-configConfigMap is now harmless but eligible for cleanup later). envoy-sidecar mTLS (separate PR; this design unblocks it via the file mirror).Sequencing
Old config fields (
mtls.{cert_file,key_file,bundle_file},tokenexchange.identity.jwt_svid_path) are silently dropped from the struct so existing chart-rendered configs continue to boot.However: when
tokenexchange.identity.type=spiffeis set, the plugin's Configure now requirestokenexchange.identity.jwt_audience(per-plugin scope — the audience is only meaningful where the spiffe identity path is consumed, so it lives where it's used). The framework also expects an empty top-levelspiffe: {}block to know it should construct the in-process Provider. The companion chart PR kagenti#1653 renders both. That PR is backward-compatible with the OLD authbridge image (additive YAML, unknown keys silently dropped) and can land first or alongside this one.What changed
FileX509Sourcereading/opt/svid*.pemper handshakeworkloadapi.X509Sourcein memoryFileJWTSourcereading/opt/jwt_svid.tokenper callworkloadapi.JWTSourcein memory, injected viaBuildWithSPIFFETesting
authlib/...test suite passes: 20+ packages green, including newauthlib/spiffe/tests (workload sources, atomic write, file mirror with rotation, Provider lifecycle), config cross-block validation,BuildWithSPIFFEDI, and the previously-skipped tokenexchange spiffe-identity test now running.spiffe-helperbinary in/usr/local/bin/.-raceto catch goroutine issues in the file-mirror loops.Manual verification on Kind is intentionally deferred to after this PR opens — the spec includes the checklist.
Design + plan documents
Both committed to the branch for review context.
Test plan
kind-full-test.sh; verify/opt/svid.pem,/opt/svid_key.pem,/opt/svid_bundle.pem,/opt/jwt_svid.tokenexist within ~10s of pod readyauthbridge-proxypods succeeds/opt/svid.pemmtime updates (rotation works)verify-spire-keycloak.shAssisted-By: Claude Code