pub struct EnvKeyProvider { /* private fields */ }Expand description
Key provider that reads from environment variables.
§Design Note
The environment variable is read on every call to
current_key() rather than being cached at
construction time. This is intentional: it allows key rotation by
updating the env var (e.g. via a sidecar or init-container) without
restarting the process. The overhead of std::env::var is negligible
compared to the AES-GCM operations that follow.
§Cached Fallback
If the environment variable is temporarily unset (e.g. during key
rotation), the provider falls back to the last successfully loaded
key for up to grace_period
(default 5 s). After the grace period expires, the
missing-variable error is propagated.
§Hardening
- Grace period reduced from 30 s → 5 s (configurable).
clear_cachelets operators explicitly discard the cached key once rotation is complete.- Every cache-fallback hit emits the
chronix_auth_env_key_grace_hitcounter so operators can detect prolonged rotation windows.
Implementations§
Source§impl EnvKeyProvider
impl EnvKeyProvider
Sourcepub fn new(env_var: &str, key_id: &str) -> Self
pub fn new(env_var: &str, key_id: &str) -> Self
Create a key provider from an environment variable name.
The environment variable should contain a hex-encoded 256-bit key. The default grace period is 5 seconds.
Sourcepub fn with_grace_period(self, duration: Duration) -> Self
pub fn with_grace_period(self, duration: Duration) -> Self
Override the grace period for cached key fallback.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Explicitly discard the cached key, e.g. after rotation is complete.
Trait Implementations§
Source§impl Debug for EnvKeyProvider
impl Debug for EnvKeyProvider
Auto Trait Implementations§
impl !Freeze for EnvKeyProvider
impl !RefUnwindSafe for EnvKeyProvider
impl Send for EnvKeyProvider
impl Sync for EnvKeyProvider
impl Unpin for EnvKeyProvider
impl UnsafeUnpin for EnvKeyProvider
impl UnwindSafe for EnvKeyProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more