Skip to content

feat(authbridge): replace spiffe-helper with in-process go-spiffe SDK Provider - #432

Merged
huang195 merged 27 commits into
rossoctl:mainfrom
huang195:feat/spiffe-go-sdk-replace-helper
May 23, 2026
Merged

huang195 merged 27 commits into
rossoctl:mainfrom
huang195:feat/spiffe-go-sdk-replace-helper

Conversation

@huang195

@huang195 huang195 commented May 22, 2026 •

Copy link
Copy Markdown
Member

Closes #332.

Summary

Replace the bundled spiffe-helper binary in authbridge images with an in-process go-spiffe v2 SDK integration. A new spiffe.Provider per container owns one workloadapi.Client and exposes:

  • An in-memory X509Source consumed by mTLS listeners (no per-handshake file I/O).
  • An in-memory JWTSource consumed by the tokenexchange plugin via a new plugins.BuildWithSPIFFE dependency-injection mechanism.
  • An opt-in (default-on) file-mirror goroutine that writes /opt/svid.pem, /opt/svid_key.pem, /opt/svid_bundle.pem, and /opt/jwt_svid.token atomically 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-helper binary, helper.conf, and the helper-launch logic in all three entrypoint.sh files are gone.

Why

  • One process per container: the bundled spiffe-helper binary is removed from authbridge-proxy, authbridge-envoy, and authbridge-lite images.
  • No file I/O on the hot path — TLS handshakes and token-exchange JWT fetches read from in-memory SDK sources.
  • Cleaner end state for upcoming envoy-sidecar mTLS: Envoy's filesystem SDS can read the same /opt/svid*.pem paths the new mirror writes, no auth bridge change needed when that work lands.

Scope

  • In: authbridge Go code (authlib/spiffe/, config schema, tokenexchange plugin, plugin DI, all three cmd binaries, entrypoint scripts, Dockerfiles, authbridge/CLAUDE.md, demos/mtls/README.md).
  • Out (follow-ups): kagenti chart + backend (companion PR kagenti#1653 renders the spiffe: {} block and per-plugin tokenexchange.identity.jwt_audience), kagenti-operator webhook (spiffe-helper-config ConfigMap 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=spiffe is set, the plugin's Configure now requires tokenexchange.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-level spiffe: {} 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

Area Before After
SVID source for mTLS FileX509Source reading /opt/svid*.pem per handshake workloadapi.X509Source in memory
SVID source for token-exchange FileJWTSource reading /opt/jwt_svid.token per call workloadapi.JWTSource in memory, injected via BuildWithSPIFFE
SVID rotation spiffe-helper writes files asynchronously go-spiffe SDK push + in-process file mirror with atomic tmp+rename
Container layout authbridge + spiffe-helper bundled in same image authbridge only
Image size (compressed) proxy 44 MB, envoy 146 MB, lite 44 MB proxy 28 MB, envoy 130 MB, lite 28 MB (~16 MB saved each)

Testing

  • Full authlib/... test suite passes: 20+ packages green, including new authlib/spiffe/ tests (workload sources, atomic write, file mirror with rotation, Provider lifecycle), config cross-block validation, BuildWithSPIFFE DI, and the previously-skipped tokenexchange spiffe-identity test now running.
  • All three Docker images build clean and contain no spiffe-helper binary in /usr/local/bin/.
  • Tests run under -race to 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

  • Deploy via kind-full-test.sh; verify /opt/svid.pem, /opt/svid_key.pem, /opt/svid_bundle.pem, /opt/jwt_svid.token exist within ~10s of pod ready
  • Confirm container starts with no Phase 1 spiffe-helper entry in entrypoint logs
  • mTLS handshake between two authbridge-proxy pods succeeds
  • Token exchange against Keycloak returns a valid token
  • After ~3 min, /opt/svid.pem mtime updates (rotation works)
  • Run verify-spire-keycloak.sh

Assisted-By: Claude Code

huang195 added 25 commits May 22, 2026 15:04
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
huang195 force-pushed the feat/spiffe-go-sdk-replace-helper branch from 4db23e3 to cc8d722 Compare May 22, 2026 19:35
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]>
- 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]>

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@huang195
huang195 merged commit e541c2c into rossoctl:main May 23, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from New /:ToDo to Done in Rossoctl Issue Prioritization May 23, 2026
@huang195
huang195 deleted the feat/spiffe-go-sdk-replace-helper branch May 23, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Use SPIRE Workload API directly instead of spiffe-helper sidecar

2 participants