Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Rust SPIFFE Library
This utility library enables interaction with the SPIFFE Workload API. It allows fetching of X.509 and JWT SVIDs, bundles and supports watch/stream updates. The types in the library are in compliance with SPIFFE standards. More about SPIFFE can be found at spiffe.io.
Getting Started
Include spiffe
in your Cargo.toml
dependencies to get both the SPIFFE types (spiffe-types
) and the Workload API
client (workload-api
) by default:
[]
= "0.6.5"
Examples of Usage
Creating a WorkloadApiClient
Create client using the endpoint socket path:
let mut client = new_from_path.await?;
Or by using the SPIFFE_ENDPOINT_SOCKET
environment variable:
let mut client = default.await?;
Fetching X.509 Materials
Fetch the default X.509 SVID, a set of X.509 bundles, all X.509 materials, or watch for updates on the X.509 context and bundles.
// fetch the default X.509 SVID
let x509_svid: X509Svid = client.fetch_x509_svid.await?;
// fetch a set of X.509 bundles (X.509 public key authorities)
let x509_bundles: X509BundleSet = client.fetch_x509_bundles.await?;
// fetch all the X.509 materials (SVIDs and bundles)
let x509_context: X509Context = client.fetch_x509_context.await?;
// get the X.509 chain of certificates from the SVID
let cert_chain: & = x509_svid.cert_chain;
// get the private key from the SVID
let private_key: &PrivateKey = x509_svid.private_key;
// parse a SPIFFE trust domain
let trust_domain = try_from?;
// get the X.509 bundle associated to the trust domain
let x509_bundle: &X509Bundle = x509_bundles.get_bundle?;
// get the X.509 authorities (public keys) in the bundle
let x509_authorities: & = x509_bundle.authorities;
// watch for updates on the X.509 context
let mut x509_context_stream = client.stream_x509_contexts.await?;
while let Some = x509_context_stream.next.await
// watch for updates on the X.509 bundles
let mut x509_bundle_stream = client.stream_x509_bundles.await?;
while let Some = x509_bundle_stream.next.await
Fetching X.509 Materials using X509Source
A convenient way to fetch X.509 materials is by using the X509Source
:
use X509Source;
use BundleSource;
use TrustDomain;
use X509Svid;
use SvidSource;
async
Fetching and Validating JWT Tokens and Bundles
Fetch JWT tokens, parse and validate them, fetch JWT bundles, or watch for updates on the JWT bundles.
// parse a SPIFFE ID to ask a token for
let spiffe_id = try_from?;
// fetch a jwt token for the provided SPIFFE-ID and with the target audience `service1.com`
let jwt_token = client.fetch_jwt_token.await?;
// fetch the jwt token and parses it as a `JwtSvid`
let jwt_svid = client.fetch_jwt_svid.await?;
// fetch a set of jwt bundles (public keys for validating jwt token)
let jwt_bundles = client.fetch_jwt_bundles.await?;
// parse a SPIFFE trust domain
let trust_domain = try_from?;
// get the JWT bundle associated to the trust domain
let jwt_bundle: &JwtBundle = jwt_bundles.get_bundle?;
// get the JWT authorities (public keys) in the bundle
let jwt_authority: &JwtAuthority = jwt_bundle.find_jwt_authority?;
// parse a `JwtSvid` validating the token signature with a JWT bundle source.
let validated_jwt_svid = parse_and_validate?;
// watch for updates on the JWT bundles
let mut jwt_bundle_stream = client.stream_jwt_bundles.await?;
while let Some = jwt_bundle_stream.next.await
For more detailed examples and additional features, refer to the documentation.
License
This library is licensed under the Apache License. See the LICENSE.md file for details.