Rust SPIFFE
A Rust library for interacting with the SPIFFE Workload API.
It provides idiomatic access to SPIFFE identities and trust material, including:
- X.509 SVIDs and bundles
- JWT SVIDs and bundles
- Streaming updates (watch semantics)
- Strongly typed SPIFFE primitives compliant with the SPIFFE standards
For background on SPIFFE, see https://spiffe.io.
For the Workload API specification, see the
SPIFFE Workload API standard.
Installation
Add spiffe to your Cargo.toml:
[]
= "0.7.2"
This includes both core SPIFFE types and a Workload API client.
Quick start
Create a Workload API client
Using an explicit socket path:
use WorkloadApiClient;
let client = new_from_path.await?;
Or via the SPIFFE_ENDPOINT_SOCKET environment variable:
use WorkloadApiClient;
let client = default.await?;
X.509 identities
The Workload API client provides direct, low-level access to X.509 materials.
use ;
let svid = client.fetch_x509_svid.await?;
let bundles = client.fetch_x509_bundles.await?;
let context: X509Context = client.fetch_x509_context.await?;
let trust_domain = try_from?;
let bundle = bundles.get_bundle?;
Watch for updates
use StreamExt;
let mut stream = client.stream_x509_contexts.await?;
while let Some = stream.next.await
X509Source (recommended)
X509Source provides a higher-level abstraction over the Workload API for
X.509-based workloads.
It maintains a locally cached, automatically refreshed view of SVIDs and bundles, and transparently handles reconnections and rotations.
use ;
let source = new.await?;
// Snapshot of the current X.509 materials
let context = source.x509_context;
// Default SVID
let svid = context.default_svid?;
// Bundle for a trust domain
let trust_domain = try_from?;
let bundle = context.bundles.get_bundle?;
For most applications that rely on X.509 identities, X509Source is the preferred API.
JWT identities
JWT-based identity is accessed via the Workload API client.
Fetch JWT SVIDs
use ;
let spiffe_id = try_from?;
let jwt = client
.fetch_jwt_svid
.await?;
Fetch JWT bundles
use TrustDomain;
let bundles = client.fetch_jwt_bundles.await?;
let trust_domain = try_from?;
let bundle = bundles.get_bundle?;
Watch JWT bundle updates
use StreamExt;
let mut stream = client.stream_jwt_bundles.await?;
while let Some = stream.next.await
Documentation
API documentation and additional examples are available on docs.rs.
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.