spiffe-rustls
spiffe-rustls integrates rustls with SPIFFE/SPIRE using the
spiffe crate’s X509Source (SPIFFE Workload API).
It provides builders for rustls::ClientConfig and rustls::ServerConfig backed by a live
X509Source. When the SPIRE agent rotates SVIDs or trust bundles, new TLS handshakes automatically
use the updated material, without restarting the application.
The crate focuses on TLS authentication and connection-level authorization via SPIFFE IDs, while
delegating all cryptography and TLS mechanics to rustls.
Quick start
1. Create an X509Source
The source is configured via SPIFFE_ENDPOINT_SOCKET:
let source = new.await?;
2. Build a rustls client configuration
use ;
use Arc;
let opts = ClientConfigOptions ;
let client_cfg = new
.build
.await?;
The resulting ClientConfig can be used directly with rustls, or integrated into
tokio-rustls, tonic-rustls, or similar libraries.
API overview
The public API is intentionally small and consists of two builders:
ClientConfigBuilderServerConfigBuilder
Each builder:
- retains an
Arc<X509Source> - builds a
rustls::{ClientConfig, ServerConfig} - always uses the latest SVIDs and trust bundles
- authorizes peers by SPIFFE ID (URI SAN)
ClientConfigBuilder
Builds a rustls::ClientConfig that:
- presents the current SPIFFE X.509 SVID as the client certificate
- validates the server certificate chain against the trust domain bundle
- authorizes the server by SPIFFE ID (URI SAN)
ServerConfigBuilder
Builds a rustls::ServerConfig that:
- presents the current SPIFFE X.509 SVID as the server certificate
- requires and validates client certificates (mTLS)
- authorizes the client by SPIFFE ID (URI SAN)
Options
ClientConfigOptions
trust_domain: trust domain whose bundle is used as the root of trustauthorize_server: authorization hook invoked with the server SPIFFE ID
Use ClientConfigOptions::allow_any(trust_domain) to disable authorization while retaining full
authentication.
ServerConfigOptions
trust_domain: trust domain whose bundle is used as the root of trustauthorize_client: authorization hook invoked with the client SPIFFE ID
Use ServerConfigOptions::allow_any(trust_domain) to disable authorization while retaining full
authentication.
Features
spiffe-rustls supports multiple rustls crypto providers:
[]
= ["ring"]
= ["rustls/ring"]
= ["rustls/aws_lc_rs"]
- Default:
ring - Optional:
aws-lc-rs
Exactly one provider must be enabled. Enabling more than one results in a compile-time error.
Example (AWS-LC):
Provider choice affects only cryptographic primitives; SPIFFE semantics and API behavior are identical across providers.
Examples
Prerequisites
All examples require:
- a running SPIRE agent
- a valid Workload API socket (
SPIFFE_ENDPOINT_SOCKET) - local DNS resolution for
example.org
For local testing, add to /etc/hosts:
127.0.0.1 example.org
Raw TLS (tokio-rustls)
Direct TLS integration using tokio-rustls.
Examples:
mtls_tcp_server.rsmtls_tcp_client.rs
gRPC (tonic + tonic-rustls)
gRPC examples live in a separate crate (spiffe-rustls-grpc-examples) to avoid pulling gRPC and
protobuf build dependencies into the library.
Notes
- Examples rely exclusively on the SPIFFE Workload API; they do not start or configure SPIRE.
- Standard TLS name (SNI) verification still applies; the DNS name must match the certificate SAN.
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.