pub struct TenantKeys { /* private fields */ }Expand description
Argon2id-hashed per-tenant API keys, keyed by tenant id.
A presented key has the form <tenant_id>.<secret>: the (non-secret) tenant id names which
hash to check, so verification is O(1) — exactly one Argon2 verify — rather than one per tenant.
Debug deliberately redacts every hash — they are password-equivalent secrets — revealing
only the configured tenant ids so a ProxyConfig dump can never leak credential material.
Implementations§
Source§impl TenantKeys
impl TenantKeys
Sourcepub fn from_json(s: &str) -> Result<Self, AuthConfigError>
pub fn from_json(s: &str) -> Result<Self, AuthConfigError>
Parse from a JSON object { "<tenant_id>": "<argon2id-phc-hash>", ... }.
Every hash is validated up front so a malformed roster fails at startup rather than silently rejecting every request at runtime.
§Errors
AuthConfigError::Json if the JSON is malformed; AuthConfigError::BadHash if any
value is not a valid Argon2 PHC hash string.
Sourcepub fn verify(&self, presented_key: &str) -> Option<TenantId>
pub fn verify(&self, presented_key: &str) -> Option<TenantId>
Verify a presented <tenant_id>.<secret> key, returning the owning tenant on a match. The
tenant id (before the first ., not itself secret) names which hash to check, so this does
exactly one Argon2 verify — O(1), not O(tenants) — using the crate’s constant-time
PasswordVerifier, never a plain ==.
An unknown tenant id (or a malformed key) still performs one Argon2 verify against a decoy
hash, so an invalid key takes the same time whether or not the named tenant exists — this
closes both the CPU-amplification DoS and the tenant-existence timing oracle. Tenant ids must
not contain . (they are simple identifiers; the first . splits id from secret).
Sourcepub fn hash_key(secret: &str) -> Result<String, AuthConfigError>
pub fn hash_key(secret: &str) -> Result<String, AuthConfigError>
Hash a fresh secret into a PHC-encoded Argon2id string for provisioning a tenant key. Operators store the returned hash; the plaintext key is shown to the tenant once and is never persisted here.
§Errors
AuthConfigError::Hash if the Argon2 hasher fails.
Trait Implementations§
Source§impl Clone for TenantKeys
impl Clone for TenantKeys
Source§fn clone(&self) -> TenantKeys
fn clone(&self) -> TenantKeys
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TenantKeys
impl Debug for TenantKeys
Source§impl Default for TenantKeys
impl Default for TenantKeys
Source§fn default() -> TenantKeys
fn default() -> TenantKeys
Auto Trait Implementations§
impl Freeze for TenantKeys
impl RefUnwindSafe for TenantKeys
impl Send for TenantKeys
impl Sync for TenantKeys
impl Unpin for TenantKeys
impl UnsafeUnpin for TenantKeys
impl UnwindSafe for TenantKeys
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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