pub struct IdentitySource { /* private fields */ }Expand description
Where an identity comes from, and the identity of the moment.
Cloning shares the source. Equality is what the connection pool keys on: two static sources holding the same identity are equal, every other source is equal only to itself.
Implementations§
Source§impl IdentitySource
impl IdentitySource
Sourcepub fn from_identity(identity: Identity) -> Result<IdentitySource, Error>
pub fn from_identity(identity: Identity) -> Result<IdentitySource, Error>
A source that holds identity and never changes.
Fails when the material cannot be read or parsed, which is where a wrong path is caught: before a binding or a dial, not during a handshake.
Sourcepub fn ephemeral(
names: impl IntoIterator<Item = impl Into<String>>,
) -> Result<IdentitySource, Error>
pub fn ephemeral( names: impl IntoIterator<Item = impl Into<String>>, ) -> Result<IdentitySource, Error>
A self-signed identity generated in memory for names, gone with the
process: the default, and what a peer that pins by address needs.
Sourcepub fn external(initial: Identity) -> Result<IdentitySource, Error>
pub fn external(initial: Identity) -> Result<IdentitySource, Error>
A source driven from outside: starts as initial and changes on
IdentitySource::update. What an issuing client uses.
Sourcepub fn files(
dir: impl Into<PathBuf>,
options: FilesOptions,
) -> Result<IdentitySource, Error>
pub fn files( dir: impl Into<PathBuf>, options: FilesOptions, ) -> Result<IdentitySource, Error>
A directory holding cert.pem and key.pem, reloaded when either
changes.
When neither file exists and the generate feature is on, a
self-signed identity for options.names is written there first —
the directory 0700, both files 0600 on Unix — so a second start
finds the same key and the same fingerprint. Without the feature an
empty directory is an error. A directory with one of the two files
is an error in either case: half an identity is not one to bootstrap
over.
This is also how every external issuer that writes files plugs in —
a Vault Agent template, cert-manager, certbot --reuse-key, a SPIRE
agent: replace the files and the next use of the identity picks them
up (0032 §4.2). Replace both atomically, or the certificate first and
the key second, so no check sees a chain that does not match its key.
Sourcepub fn current(&self) -> Identity
pub fn current(&self) -> Identity
The identity of the moment.
On a file source this is also where a due modification-time check runs, so a caller pays it at most once per poll interval.
Sourcepub fn fingerprint(&self) -> Result<Fingerprint, Error>
pub fn fingerprint(&self) -> Result<Fingerprint, Error>
The fingerprint of the current key.
Fails only on a static value whose material cannot be read; every other source checked it when it loaded.
Sourcepub fn update(&self, identity: Identity) -> Result<(), Error>
pub fn update(&self, identity: Identity) -> Result<(), Error>
Replaces the identity. Renewed when the key is unchanged,
KeyChanged when it is not.
Fails, and changes nothing, when the material cannot be read: a
renewal that delivered garbage leaves the previous identity in
service and reports RenewalFailed.
Sourcepub fn report_failure(&self, reason: impl Into<String>)
pub fn report_failure(&self, reason: impl Into<String>)
Reports a failed renewal that never produced material, from an external source. The identity in service is unchanged.
Sourcepub fn report_handoff_stolen(&self)
pub fn report_handoff_stolen(&self)
Reports that this process’s hand-off credential had already been redeemed (0032 §2). The identity in service is unchanged; the caller is expected not to continue.
Sourcepub fn reload(&self) -> Result<bool, Error>
pub fn reload(&self) -> Result<bool, Error>
Reloads a file source now, regardless of the poll interval.
Ok(true) when the files had changed and were loaded, Ok(false)
when nothing changed, and an error — also reported as
RenewalFailed — when they changed and could not be loaded. Not a
file source: Ok(false).
Sourcepub fn events(&self) -> IdentityEvents
pub fn events(&self) -> IdentityEvents
The event stream of this source; each call is an independent reader.
Sourcepub fn downgrade(&self) -> WeakIdentitySource
pub fn downgrade(&self) -> WeakIdentitySource
A weak handle to this source, for a background task that must end
when the application drops its last strong handle.
See WeakIdentitySource.
Trait Implementations§
Source§impl Clone for IdentitySource
impl Clone for IdentitySource
Source§impl Debug for IdentitySource
impl Debug for IdentitySource
impl Eq for IdentitySource
Source§impl From<Identity> for IdentitySource
impl From<Identity> for IdentitySource
Source§fn from(identity: Identity) -> IdentitySource
fn from(identity: Identity) -> IdentitySource
A static source. The material is read at first use rather than here:
From cannot fail, and a wrong path is still caught before any
handshake, by the bind or the dial that first needs the key.