pub struct BearerPolicy {
pinned: Option<Arc<str>>,
floor: Option<Arc<str>>,
settings: Option<Arc<SettingsCache>>,
}Expand description
Which token a running endpoint currently requires.
§Why this is not just a string
The expected token used to be resolved once, at bind, and baked into the middleware — so a key rotated afterwards was never honoured and a key set afterwards was never enforced. Worse, the guard was only installed when a token existed at bind, so an endpoint that started open could not be closed without a restart.
The fix cannot be an in-process notification. gglib config settings set
writes the database from a separate process, so nothing the daemon
subscribes to would ever see it — the same reasoning
SettingsCache already records for every
other setting. Reading through that cache is what makes a rotation take
effect here at all.
The staleness is bounded, not zero. A revoked key keeps working for up
to SETTINGS_CACHE_TTL. That is the
accepted trade, and it is strictly better than what it replaces, where a
rotation performed through the CLI never took effect at all.
Fields§
§pinned: Option<Arc<str>>A token supplied by flag or environment. It does not live in settings, so nothing in settings may override it.
floor: Option<Arc<str>>The token in force at bind, kept as a floor.
settings: Option<Arc<SettingsCache>>The live view of the stored token.
Implementations§
Source§impl BearerPolicy
impl BearerPolicy
Sourcepub fn pinned(key: &str) -> Self
pub fn pinned(key: &str) -> Self
A token the operator supplied directly, which never tracks settings.
--api-key and GGLIB_API_KEY outrank the stored value by design, so
letting a settings write replace one would both invert that precedence
and lock out the operator who passed it.
Sourcepub fn tracking(bind_key: Option<&str>, settings: Arc<SettingsCache>) -> Self
pub fn tracking(bind_key: Option<&str>, settings: Arc<SettingsCache>) -> Self
A token read from settings — or absent — which tracks later writes.
bind_key is whatever was in force when the endpoint bound, and is
kept as a floor: if the stored value later disappears, this endpoint
keeps demanding the token it started with rather than falling open.
Authentication can be switched on at runtime and never off, which
is the asymmetry a listener bound off loopback needs — clearing the
setting must not silently expose it.
Sourcepub fn fixed(key: Option<&str>) -> Self
pub fn fixed(key: Option<&str>) -> Self
A token that can never change and is never required. For hosts with no settings to read, such as tests and embedded servers.
Trait Implementations§
Source§impl Clone for BearerPolicy
impl Clone for BearerPolicy
Source§fn clone(&self) -> BearerPolicy
fn clone(&self) -> BearerPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more