Skip to main content

Authenticator

Struct Authenticator 

Source
pub struct Authenticator { /* private fields */ }
Expand description

Turns an Authorization header into a Principal, or into nothing.

Nothing is the default: a caller with no credential is a principal only when the deployment configured an anonymous client and opted in with allow_anonymous. Two switches, because one of them is the kind that gets flipped in a hurry.

Implementations§

Source§

impl Authenticator

Source

pub fn new( clients: impl IntoIterator<Item = (Token, Principal)>, anonymous: Option<Principal>, ) -> Self

An authenticator over clients, with an optional anonymous principal for callers that present no credential.

Source

pub fn with_kubernetes(self, verifier: KubernetesVerifier) -> Self

Available on crate feature kubernetes-auth only.

Adds the TokenReview fallback for bearers no configured token matched.

Source

pub fn allows_anonymous(&self) -> bool

Whether an unauthenticated caller is somebody here.

Source

pub fn authenticate(&self, authorization: Option<&str>) -> Option<Principal>

Who is calling, given the raw Authorization header.

Three answers, and the middle one is the one worth stating: a header that is present but unusable — a wrong scheme, an unknown token — is not downgraded to anonymous. A caller that presented a credential meant to present that credential, and silently serving it the anonymous grants instead is how an expired token becomes a deployment that appears to work.

Trait Implementations§

Source§

impl Debug for Authenticator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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, 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.