rustls-spiffe
Dynamic rustls TLS configuration backed by the SPIFFE Workload API
and rustls-config-stream. Effortlessly hot-swap new X509-SVIDs and Trust
Bundles as they rotate, without restarting your service.
Provides SpiffeClientConfigStream and SpiffeServerConfigStream for
use with ClientConfigProvider and ServerConfigProvider.
Installation
The providers connect to the Workload API at the address in the
SPIFFE_ENDPOINT_SOCKET environment variable (e.g.
unix:///tmp/spire-agent/public/api.sock).
Example
An mTLS server that only accepts clients presenting an X509-SVID from the
example.org trust domain and greets them by SPIFFE ID, plus a client that
connects to it. In a real deployment these would be separate workloads; they
share a process here so the example runs as-is.
use ;
use ;
use ;
type Error = ;
async
/// Accept clients from `example.org` and greet them by SPIFFE ID.
async
/// Connect to a server from `example.org` and return its greeting.
async
The server verifies that client certificates chain to a configured trust
domain, but does not restrict which workloads in that trust domain may
connect. Use extract_spiffe_id to authorize individual SPIFFE IDs.
The client performs standard hostname verification, so the server's SVID
must carry a DNS SAN matching the name you connect to (with SPIRE, register
the server entry with -dns localhost, for example).
Rotation and Health
Both providers subscribe to the Workload API and atomically swap in a new config whenever SPIRE rotates the SVID or a trust bundle changes. Existing connections keep the config they were established with.
If the Workload API stream fails, the provider keeps serving the last good
config while it reconnects with exponential backoff. stream_healthy()
reports false until the stream is re-established, which is useful for
readiness checks.
Trust Domains and Federation
The list passed to builder selects which trust bundles are used as roots.
To accept peers from a federated trust domain (whose bundle SPIRE delivers
when the registration entry federates with it), include it alongside your
own:
let builder = builder;
Feature Flags
All features are enabled by default via the full feature.
| Feature | Description |
|---|---|
config-stream |
SpiffeClientConfigStream, SpiffeServerConfigStream, and the providers |
svid-extractor |
extract_leaf_cert and extract_spiffe_id for tokio-rustls servers |
tracing |
Logs workload identities, bundle loads, and stream reconnects via tracing |
Crypto Provider
This crate enables rustls's aws-lc-rs backend. If something else in your
dependency tree enables another backend (e.g. ring), install a process
default before starting a provider:
// Errs only if a default is already installed, which is safe to ignore.
let _ = default_provider.install_default;
License: Apache-2.0 WITH LLVM-exception