envoy-guide
Module 7 · Going Deeper·14 min·advanced

SDS — TLS cert rotation without restarts

Push certs into Envoy dynamically via xDS so rotation never requires a process restart.

Why static cert files don't cut it anymore

Modern PKI rotates fast:

  • SPIFFE / SPIRE workload identities: 1-hour TTL.
  • cert-manager + Let's Encrypt: 60-day rotation.
  • Vault PKI: cert minted on demand per workload.

Restarting Envoy every rotation drops long-lived gRPC streams and breaks zero-downtime promises. SDS — Secret Discovery Service — solves this by delivering certs and keys to Envoy dynamically, over xDS, with atomic in-memory swap. No restart, no dropped connections.

Minimal envoy.yaml — listener that fetches certs over SDS

YAML
static_resources:
  listeners:
  - address: { socket_address: { address: 0.0.0.0, port_value: 8443 }}
    filter_chains:
    - transport_socket:
        name: envoy.transport_sockets.tls
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
          common_tls_context:
            tls_certificate_sds_secret_configs:
            - name: server_cert
              sds_config:
                resource_api_version: V3
                api_config_source:
                  api_type: GRPC
                  transport_api_version: V3
                  grpc_services:
                  - envoy_grpc: { cluster_name: sds_server }
            validation_context_sds_secret_config:
              name: trusted_ca
              sds_config:
                resource_api_version: V3
                api_config_source:
                  api_type: GRPC
                  transport_api_version: V3
                  grpc_services:
                  - envoy_grpc: { cluster_name: sds_server }
      filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: ingress
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
          route_config:
            virtual_hosts:
            - name: vh
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                direct_response: { status: 200, body: { inline_string: "ok" }}

  clusters:
  - name: sds_server
    type: STATIC
    typed_extension_protocol_options:
      envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
        "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
        explicit_http_config: { http2_protocol_options: {} }
    load_assignment:
      cluster_name: sds_server
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              pipe: { path: "/var/run/sds/sds.sock" }   # UDS

Most production deployments use a Unix domain socket for SDS. The SDS channel itself doesn't need TLS — kernel locality enforces trust.

The chicken-and-egg problem

If SDS is delivered over an mTLS gRPC channel, Envoy needs a cert to fetch its certs. Two ways out:

  1. Unix domain socket — most common. SPIRE Agent and Istio's pilot-agent expose SDS over a UDS that only locally-running Envoy pods can reach.
  2. Bootstrap secret — a small, long-lived cert loaded statically from disk, used only for the SDS connection itself. Workload certs then arrive over that bootstrap-mTLS channel.

UDS is simpler and what every reference implementation uses.

Three pitfalls

Initial fetch timeout drops cold-start traffic

Listeners with tls_certificate_sds_secret_configs are not ready until the first SDS push lands. Clients connecting before that get TCP RST or hang. Tune initial_fetch_timeout and design clients to retry with backoff at startup.

CA-bundle swap can break in-flight mTLS

Replacing the trusted CA atomically seems safe — but any client whose chain validates only against the old CA starts failing the moment the swap lands. Always: add the new CA in push 1, let clients rotate over a window, then remove the old CA in push 2.

Long-lived gRPC streams keep the old cert

TLS sessions are pinned to the cert that established them. Rotating the SDS cert affects new connections; existing streams keep going with the previous identity until they end. This is usually what you want — but if you need to forcibly invalidate an identity, use connectionDraining on the listener or rely on short session-resumption tickets.

Hands-on: rotate a cert without dropping a connection

Hands-on · SPIRE + Envoy + SDS
  1. Run SPIRE Server and Agent locally with Docker (the SPIRE quickstart works fine).

  2. Register a workload selector that matches your Envoy container:

Shell
spire-server entry create \
  -spiffeID spiffe://example.org/envoy \
  -parentID spiffe://example.org/agent \
  -selector docker:label:app:envoy
  1. Configure Envoy with the listener above pointing at the agent's UDS (typically /tmp/spire-agent/public/api.sock).

  2. Curl https://localhost:8443 with the SPIRE-issued client cert.

  3. Force a rotation:

Shell
spire-server entry update -ttl 60 ...

Watch http://localhost:9901/stats?filter=secret.server_cert — update_success increments without a process restart.

  1. Hold an open nc -k TLS connection while the rotation happens. The session keeps going. New connections after the swap use the fresh cert.
Real-world example · Chronos Bank (zero-trust mesh)
Problem
Every workload gets an x509 SVID with a 1-hour TTL. Restarting Envoys every hour to pick up new certs would drop long-running gRPC streams used for trade orders. Static cert files were a non-starter.
Envoy solution
Every Envoy sidecar talks to its local SPIRE Agent over a Unix socket via SDS. When SPIRE rotates the SVID at the 30-minute mark, Envoy swaps the cert in memory. Long-running streams keep going on existing TLS sessions; new connections use the fresh cert. Zero restarts, zero dropped trades, audit team gets a clean rotation log from SPIRE.

Where SDS fits in the bigger picture

  • Static config (Modules 1-4) — fine for learning.
  • xDS (Lesson 16) — clusters and routes pushed dynamically.
  • SDS (this lesson) — the same xDS pipeline, but for TLS material.

In a real Istio mesh, all of CDS / RDS / EDS / LDS / SDS flow over one ADS stream. The Envoy you've been writing by hand is also the Envoy your mesh is generating — just with everything dynamic.

Quick check

What is the most common way to avoid the SDS-over-TLS bootstrap problem?

Practical task
Finish the quick check and tick off the task to unlock.
Quick checkTasks 0/3