1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//! Client library for the [SPIFFE Workload API](https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE_Workload_API.md).
//!
//! Provides standards-compliant access to SPIFFE identities and trust material.
//! Supports fetching and watching X.509 and JWT SVIDs and trust bundles using
//! strongly typed APIs aligned with the SPIFFE specifications.
//!
//! ## Quick Start
//!
//! For X.509-based workloads, use [`X509Source`] (requires the `x509-source` feature):
//!
//! ```no_run
//! # #[cfg(feature = "x509-source")]
//! # async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! use spiffe::{bundle::BundleSource, TrustDomain, X509Source};
//!
//! let source = X509Source::new().await?;
//! let _svid = source.svid()?;
//! let trust_domain = TrustDomain::try_from("example.org")?;
//! let _bundle = source
//! .bundle_for_trust_domain(&trust_domain)?
//! .ok_or("missing bundle")?;
//! # Ok(())
//! # }
//! ```
//!
//! For JWT-based workloads, use [`JwtSource`] (requires the `jwt-source` feature):
//!
//! ```no_run
//! # #[cfg(feature = "jwt-source")]
//! # async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! use spiffe::{bundle::BundleSource, TrustDomain, JwtSource};
//!
//! let source = JwtSource::new().await?;
//! let _jwt_svid = source.get_jwt_svid(&["service-a", "service-b"]).await?;
//! let trust_domain = TrustDomain::try_from("example.org")?;
//! let _bundle = source
//! .bundle_for_trust_domain(&trust_domain)?
//! .ok_or("missing bundle")?;
//! # Ok(())
//! # }
//! ```
//!
//! For direct Workload API access, use [`WorkloadApiClient`] (requires a `workload-api-*` feature):
//!
//! ```no_run
//! # #[cfg(feature = "workload-api")]
//! # async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! use spiffe::WorkloadApiClient;
//!
//! let client = WorkloadApiClient::connect_env().await?;
//! let _jwt_svid = client.fetch_jwt_svid(&["audience"], None).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Feature Matrix
//!
//! The crate has **no default features** — everything is opt-in.
//!
//! Most users should enable `x509-source` (for X.509 workloads), `jwt-source` (for JWT workloads),
//! or a `workload-api-*` bundle (for direct Workload API access). The granular features exist to
//! let you minimize dependency surface when you only need X.509 or only need JWT.
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `x509` | X.509 SVID and bundle types + parsing (gates heavy ASN.1/X.509 deps) |
//! | `transport` | Endpoint parsing (no runtime deps) |
//! | `transport-grpc` | gRPC connector |
//! | `jwt` | JWT SVID and bundle types + parsing |
//! | `jwt-verify-rust-crypto` | Offline JWT verification (rust-crypto backend) |
//! | `jwt-verify-aws-lc-rs` | Offline JWT verification (aws-lc-rs backend) |
//! | `logging` | Log-based observability |
//! | `tracing` | Tracing-based observability |
//!
//! ### Workload API bundles
//!
//! These features enable the async Workload API client (`WorkloadApiClient`). Choose the smallest
//! bundle that matches your use case:
//!
//! | Feature | Includes |
//! |---------|----------|
//! | `workload-api-x509` | Workload API client + X.509 support (no JWT) |
//! | `workload-api-jwt` | Workload API client + JWT support (no X.509) |
//! | `workload-api` | Workload API client with both X.509 + JWT support |
//! | `workload-api-full` | Alias/bundle for both X.509 + JWT support (same capability as `workload-api`) |
//!
//! ### Advanced / compositional
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `workload-api-core` | Workload API infrastructure only (transport/proto/client plumbing; no X.509/JWT parsing/types) |
//! | `x509-source` | High-level X.509 watcher/caching built on the Workload API |
//! | `jwt-source` | High-level JWT watcher/caching built on the Workload API |
//!
//! **Notes:**
//!
//! - The `x509` feature gates heavy X.509 parsing dependencies.
//! - For direct Workload API usage, use `workload-api-x509` or `workload-api-jwt` when you only need one,
//! and `workload-api` (or `workload-api-full`) when you need both.
//!
//! ## X.509
//!
//! ```no_run
//! # #[cfg(feature = "x509-source")]
//! # async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! use spiffe::{TrustDomain, X509Source};
//! use spiffe::bundle::BundleSource;
//!
//! let source = X509Source::new().await?;
//! let _svid = source.svid()?;
//! let trust_domain = TrustDomain::try_from("example.org")?;
//! let _bundle = source
//! .bundle_for_trust_domain(&trust_domain)?
//! .ok_or("missing bundle")?;
//!
//! # Ok(())
//! # }
//! ```
//!
//! For JWT-based workloads, use [`JwtSource`] (requires the `jwt-source` feature):
//!
//! ```no_run
//! # #[cfg(feature = "jwt-source")]
//! # async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! use spiffe::{bundle::BundleSource, TrustDomain, JwtSource};
//!
//! let source = JwtSource::new().await?;
//! let _jwt_svid = source.get_jwt_svid(&["service-a", "service-b"]).await?;
//! let trust_domain = TrustDomain::try_from("example.org")?;
//! let _bundle = source
//! .bundle_for_trust_domain(&trust_domain)?
//! .ok_or("missing bundle")?;
//! # Ok(())
//! # }
//! ```
//!
//! For advanced configuration, see the [`x509_source`] and [`jwt_source`] modules.
// "logging" and "tracing" can both be enabled, causing logging to be unused.
//
// "workload-api" can be enabled without "x509-source" or "jwt-source", causing
// arc-swap, fastrand, and tokio-util to be unused.
//
// There are probably others.
/// Transport primitives (endpoint parsing, optional gRPC connector).
///
/// Enabled with `transport` (parsing only) or `transport-grpc` (parsing + gRPC connector).
// Compile-time guards for feature combinations
compile_error!;
// Core identifiers
pub use crate;
// SVIDs
pub use crate;
pub use crate;
// Bundles
pub use crate;
pub use crate;
// Workload API - Common types
//
// WorkloadApiClient and X509Context. Available with `workload-api` feature.
pub use crateX509Context;
pub use crate;
// X.509 Source
//
// High-level watcher/caching abstraction. Available with `x509-source` feature.
// Primary types are re-exported at the crate root.
// For advanced configuration types, see the [`x509_source`] module.
pub use crate;
// JWT Source
//
// High-level watcher/caching abstraction for JWT bundles. Available with `jwt-source` feature.
// Primary types are re-exported at the crate root.
// For advanced configuration types, see the [`jwt_source`] module.
pub use crate;