Skip to content

Add SPIFFE mTLS and an artifact server endpoint - #533

Merged
stefanprodan merged 5 commits into
masterfrom
spiffe-mtls
Oct 26, 2026
Merged

stefanprodan merged 5 commits into
masterfrom
spiffe-mtls

Conversation

@stefanprodan

Copy link
Copy Markdown
Owner

This makes podinfo a SPIFFE workload and a minimal Flux artifact server, so the Flux and Flux Operator SPIFFE mTLS e2e tests can replace their purpose-built test apps with a pinned podinfo release.

Changes

SPIFFE mTLS on the secure port

  • New flags --spiffe-endpoint-socket and --spiffe-authorized-ids. When the socket is set, the HTTPS server gets its X.509 SVID from the SPIFFE Workload API (go-spiffe v2) instead of --cert-path, and requires a client SVID. Clients are authorized by ID, or by podinfo's trust domain when no IDs are given.
  • The HTTP port and liveness start right away. podinfo retries the Workload API until the SVID is issued and turns ready only once the TLS listener is up, so a missing SPIRE registration never restarts the pod. Retries are logged at info.
  • Shutdown aborts a pending SVID wait and closes the source. Invalid IDs or a missing --secure-port fail at startup.
  • The request log adds spiffe_id, and /headers returns X-Spiffe-Id for SPIFFE clients. A client-supplied X-Spiffe-Id header is never echoed.

GET/HEAD /artifact

  • Serves --artifact-path (default ./kustomize, now copied into the image) as a deterministic tar.gz, with the sha256 digest in X-Artifact-Digest. Every replica and restart of an image serves the same bytes. An empty path disables the route; a missing dir returns 404.

Payload logging

  • /api/echo without backends logs the request body at debug level, embedding JSON bodies as objects so tests can filter with jq '.payload.reportingController'.

Helm chart

  • New spiffe.* values (requires tls.enabled): mounts the Workload API socket from the SPIFFE CSI driver instead of the tls secret. Renders are unchanged when spiffe.enabled is false.
  • New Helm test, rendered only with spiffe.enabled: fetches a client SVID with spire-agent and checks that podinfo accepts it and rejects a client without one. The tls test is skipped in SPIFFE mode.

Other

  • Go dependencies updated to latest (govulncheck clean).
  • Fixed a data race on a shared context in /echo with multiple backends (found with go test -race, already on master).
  • Swagger docs regenerated, README documents SPIFFE mTLS and /artifact.

Testing

  • Unit tests run against a fake Workload API over a unix socket, so they exercise the real go-spiffe client: authorized, unauthorized, foreign trust domain and no client cert; readiness before and after the SVID, --unready, shutdown while waiting; artifact determinism, HEAD, symlinks, missing dir; payload logging. All pass with -race.
  • New test/e2e-spiffe.sh and kind-spiffe CI job on kind with SPIRE: podinfo stays live but not ready until registered, then turns ready without a restart; /artifact is served from the image; the Helm tests pass; an SVID not in authorizedIDs is rejected. Passed locally.

Note for the SPIRE Helm chart: its controller manager ignores ClusterSPIFFEIDs without spec.className (<namespace>-<release>, e.g. spire-system-spire); the e2e and README example set it.

- OpenTelemetry v1.47.0 (contrib v0.72.0)
- gRPC v1.84.0
- Prometheus client_golang v1.25.0
- golang.org/x/net v0.61.0

govulncheck: no vulnerabilities found.
Each backend goroutine reassigned the handler's ctx variable, so with
more than one backend the goroutines raced on it and stacked each
other's client trace hooks. Use a goroutine-local context instead.

Found with go test -race (TestEchoHandler_MultipleBackends).
SPIFFE mTLS on the secure port:
- New flags --spiffe-endpoint-socket and --spiffe-authorized-ids.
  When the socket is set, the HTTPS server gets its X.509 SVID from the
  SPIFFE Workload API (go-spiffe v2) instead of --cert-path and requires
  a client SVID. Clients are authorized by ID, or by the server's trust
  domain when no IDs are given.
- The plain HTTP server and liveness start right away. The server
  retries until the SVID is issued and becomes ready only once the TLS
  listener is up, so a missing registration never restarts the pod.
- Shutdown aborts a pending SVID wait and closes the source.
- Invalid IDs or a missing --secure-port fail at startup.
- The request log adds spiffe_id and /headers returns X-Spiffe-Id
  for clients with an SVID.

Artifact route:
- GET/HEAD /artifact serves --artifact-path (default ./kustomize,
  now copied into the image) as a deterministic tar.gz with its
  sha256 digest in X-Artifact-Digest, so podinfo can act as a Flux
  artifact server.

Payload logging:
- /api/echo without backends logs the request body at debug level,
  embedding JSON bodies as objects in the log line.
- New spiffe.* values: when enabled (requires tls.enabled), the TLS port
  gets its SVID from the SPIFFE Workload API mounted by the SPIFFE CSI
  driver instead of the tls secret, and spiffe.authorizedIDs sets the
  allowed client IDs. Renders are unchanged when spiffe is disabled.
- New Helm test, rendered only with spiffe.enabled: fetches a client
  SVID with spire-agent and checks that podinfo accepts it and rejects
  a client without one. The tls test is skipped in SPIFFE mode.
- New test/e2e-spiffe.sh and kind-spiffe CI job: installs SPIRE, checks
  podinfo stays live but not ready until it is registered, then becomes
  ready without a restart, serves /artifact from the image, passes the
  Helm tests and rejects an SVID not in authorizedIDs.
@stefanprodan
stefanprodan merged commit 53238f7 into master Oct 26, 2026
5 checks passed
@stefanprodan
stefanprodan deleted the spiffe-mtls branch October 26, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant