Skip to main content

BearerPolicy

Struct BearerPolicy 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub async fn current(&self) -> Option<Arc<str>>

The token a request must present right now, or None while this endpoint is unauthenticated.

Source

pub async fn admits(&self, presented: Option<&str>) -> bool

Whether presented gets in.

An endpoint with no token configured admits everyone, which is the loopback default and the behaviour this had before authentication existed.

Trait Implementations§

Source§

impl Clone for BearerPolicy

Source§

fn clone(&self) -> BearerPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more