spiffe/
error.rs

1//! Defines errors related to interactions with the GRPC client, including handling of X.509 and JWT materials,
2//! SPIFFE endpoint socket path validation, and other potential failure points within the Rust-Spiffe library.
3//! This encompasses errors related to endpoint configuration, response handling, data processing, and specific
4//! errors for various SPIFFE components.
5
6use crate::{JwtBundleError, JwtSvidError, SpiffeIdError, X509BundleError, X509SvidError};
7use thiserror::Error;
8use url::ParseError;
9
10/// Errors that may arise while interacting with and fetching materials from a GRPC client.
11/// Includes errors related to endpoint configuration, response handling, and data processing.
12#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum GrpcClientError {
15    /// Missing environment variable for the endpoint socket address.
16    #[error("missing endpoint socket address environment variable (SPIFFE_ENDPOINT_SOCKET)")]
17    MissingEndpointSocketPath,
18
19    /// The GRPC client received an empty response.
20    #[error("received an empty response from the GRPC client")]
21    EmptyResponse,
22
23    /// Invalid endpoint socket path configuration.
24    #[error("invalid endpoint socket path")]
25    InvalidEndpointSocketPath(#[from] SocketPathError),
26
27    /// Failed to parse the X509Svid response from the client.
28    #[error("failed to process X509Svid response")]
29    InvalidX509Svid(#[from] X509SvidError),
30
31    /// Failed to parse the JwtSvid response from the client.
32    #[error("failed to process JwtSvid response")]
33    InvalidJwtSvid(#[from] JwtSvidError),
34
35    /// Failed to parse the X509Bundle response from the client.
36    #[error("failed to process X509Bundle response")]
37    InvalidX509Bundle(#[from] X509BundleError),
38
39    /// Failed to parse the JwtBundle response from the client.
40    #[error("failed to process JwtBundle response")]
41    InvalidJwtBundle(#[from] JwtBundleError),
42
43    /// Invalid trust domain in the bundles response.
44    #[error("invalid trust domain in bundles response")]
45    InvalidTrustDomain(#[from] SpiffeIdError),
46
47    /// Error returned by the GRPC library for error responses from the client.
48    #[error("error response from the GRPC client")]
49    Grpc(#[from] tonic::Status),
50
51    /// Error returned by the GRPC library when creating a transport channel.
52    #[error("error creating transport channel to the GRPC client")]
53    Transport(#[from] tonic::transport::Error),
54}
55
56/// Errors related to the validation of a SPIFFE endpoint socket path.
57/// These cover scenarios such as invalid URI schemes, missing components, and unexpected URI structure.
58#[derive(Debug, Error, PartialEq, Copy, Clone)]
59#[non_exhaustive]
60pub enum SocketPathError {
61    /// The SPIFFE endpoint socket URI has a scheme other than 'unix' or 'tcp'.
62    #[error("workload endpoint socket URI must have a tcp:// or unix:// scheme")]
63    InvalidScheme,
64
65    /// The SPIFFE endpoint unix socket URI does not include a path.
66    #[error("workload endpoint unix socket URI must include a path")]
67    UnixAddressEmptyPath,
68
69    /// The SPIFFE endpoint tcp socket URI include a path.
70    #[error("workload endpoint tcp socket URI must not include a path")]
71    TcpAddressNonEmptyPath,
72
73    /// The SPIFFE endpoint socket URI has query values.
74    #[error("workload endpoint socket URI must not include query values")]
75    HasQueryValues,
76
77    /// The SPIFFE endpoint socket URI has a fragment.
78    #[error("workload endpoint socket URI must not include a fragment")]
79    HasFragment,
80
81    /// The SPIFFE endpoint socket URI has query user info.
82    #[error("workload endpoint socket URI must not include user info")]
83    HasUserInfo,
84
85    /// The SPIFFE endpoint tcp socket URI has misses a host.
86    #[error("workload endpoint tcp socket URI must include a host")]
87    TcpEmptyHost,
88
89    /// The SPIFFE endpoint tcp socket URI has misses a port.
90    #[error("workload endpoint tcp socket URI host component must be an IP:port")]
91    TcpAddressNoIpPort,
92
93    /// Error returned by the URI parsing library.
94    #[error("workload endpoint socket is not a valid URI")]
95    Parse(#[from] ParseError),
96}