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
impl Authenticator
Sourcepub fn new(
clients: impl IntoIterator<Item = (Token, Principal)>,
anonymous: Option<Principal>,
) -> Self
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.
Sourcepub fn with_kubernetes(self, verifier: KubernetesVerifier) -> Self
Available on crate feature kubernetes-auth only.
pub fn with_kubernetes(self, verifier: KubernetesVerifier) -> Self
kubernetes-auth only.Adds the TokenReview fallback for bearers no configured token matched.
Sourcepub fn allows_anonymous(&self) -> bool
pub fn allows_anonymous(&self) -> bool
Whether an unauthenticated caller is somebody here.
Sourcepub fn authenticate(&self, authorization: Option<&str>) -> Option<Principal>
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.