Skip to main content

AuthPolicy

Enum AuthPolicy 

Source
pub enum AuthPolicy {
    Public,
    Require(ScopeSet),
}
Expand description

What a deployment has decided about this endpoint’s exposure.

Separate from Anonymous because “we have not configured anything yet” and “this endpoint is deliberately public” are different states, and conflating them is how a default becomes a decision nobody made. A deployment that means “public” writes AuthPolicy::Public; a deployment that means “authenticated” writes AuthPolicy::Require and names the scopes.

Variants§

§

Public

Every request is served under an anonymous context.

Correct for a loopback stdio-equivalent and for a conformance runner, and wrong for anything reachable from another host. It is the default because a Router that cannot be constructed until authentication is wired is a router nobody constructs while T16 is unimplemented.

§

Require(ScopeSet)

Every request must hold these scopes.

Note what an empty ScopeSet does here: it requires nothing, so refuse answers None and the policy behaves exactly like Public. That is a footgun — “I require authentication” followed by nothing to require is a configuration mistake — and it is the kind that is best made visible by a test rather than by a runtime check, because there is no error to return from a const builder on a value that is otherwise perfectly well-formed. an_empty_requirement_is_public_and_says_so pins the behaviour so it cannot change silently: if a future dispatch wants Require to reject an empty set, that test is the thing that has to be updated on purpose.

The same applies to ServerConfig::with_required_scopes: it stores what it is given and does not validate it.

Implementations§

Source§

impl AuthPolicy

Source

pub const fn required(self) -> ScopeSet

The scopes a request must hold under this policy.

Source

pub const fn refuse(&self, context: &AuthContext) -> Option<Refusal>

The refusal this policy produces for context, if any.

The 401-before-403 order is the point. A caller that holds nothing is told to authenticate; a caller that holds a principal but lacks a scope is told its credential is insufficient. Answering 403 to a caller holding nothing tells the client to retry with more permission, which it cannot do — it has nothing to add.

The test for “holds nothing” is AuthContext::scopes, not AuthContext::principal. The domain’s AuthContext::anonymous is a named principal — it is called anonymous rather than being the empty string, deliberately, so a trace can distinguish a peer that presented no credential from a named principal whose credential granted nothing. So a check on the principal being empty is not merely inelegant here, it is unreachable: it would classify the anonymous caller as authenticated-but-insufficient and answer 403 to a client that has no credential at all. The scopes are the thing the policy is actually about, and a caller holding none of them is the caller that needs to authenticate first.

Trait Implementations§

Source§

impl Clone for AuthPolicy

Source§

fn clone(&self) -> Self

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
Source§

impl Copy for AuthPolicy

Source§

impl Debug for AuthPolicy

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AuthPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for AuthPolicy

Source§

impl PartialEq for AuthPolicy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AuthPolicy

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

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

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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