Skip to main content

GuardConfigBuilder

Struct GuardConfigBuilder 

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

Builder for GuardConfig.

Implementations§

Source§

impl GuardConfigBuilder

Source

pub fn cookie(self, cookie: CookieConfig) -> Self

Cookie attributes. See CookieConfig.

Source

pub fn cookie_name(self, name: impl Into<String>) -> Self

Shorthand for changing only the cookie name.

Source

pub fn session_lifetime(self, lifetime: Duration) -> Self

Absolute session lifetime, counted from login. Activity, rotation and step-up never extend it; the subject must log in again. Default 30 days.

Source

pub fn idle_timeout(self, timeout: Duration) -> Self

Inactivity timeout. Default 7 days.

Source

pub fn trusted_proxies<I, T>(self, proxies: I) -> Result<Self, ConfigError>
where I: IntoIterator<Item = T>, T: AsRef<str>,

Reverse proxies (IP addresses or CIDR ranges) whose X-Forwarded-For is honoured. Without any, the TCP peer address is the client address.

§Errors

ConfigError::InvalidProxy for an entry that is not an IP or CIDR range.

Source

pub fn tls_fingerprint_header(self, header: impl Into<String>) -> Self

Header with a TLS fingerprint (e.g. JA4) set by your proxy. Enables Check::TlsChanged. Only use a header your proxy overwrites on every request.

Source

pub fn rotation(self, rotation: RotationConfig) -> Self

Token rotation settings.

Source

pub fn checks(self, checks: Checks) -> Self

Checks and weights. Default: all checks at default weights.

Source

pub fn thresholds(self, thresholds: Thresholds) -> Self

Score thresholds. Default: step-up at 40, revoke at 80.

Source

pub fn mode(self, mode: Mode) -> Self

Enforce or shadow mode. Default enforce.

Source

pub fn step_up_policy(self, policy: StepUpPolicy) -> Self

What a step-up decision does. Default StepUpPolicy::Require.

Source

pub fn orphan_reissue_window(self, window: Duration) -> Self

How long after being superseded an orphaned token (its successor never presented) is still reissued. Past it the token is rejected as unknown and the session is left to whoever holds the successor. Default off: orphans are reissued until rotation.reuse_detection prunes them.

Zero never reissues: a client that loses a single rotation response is signed out.

Source

pub fn ping_pong_window(self, window: Duration) -> Self

Ping-pong window. Default 5 minutes. Zero disables ping-pong detection.

Source

pub fn last_seen_write_interval(self, interval: Duration) -> Self

How stale last_seen may get before an unchanged request writes it. Default 60 seconds. Zero writes on every request.

Source

pub fn event_retention(self, retention: Duration) -> Self

Event retention. Default 90 days.

Source

pub fn minimize_stored_events(self, minimize: bool) -> Self

Write a reduced copy of each event to the store: the IP’s /24 (IPv4) or /48 (IPv6) network instead of the address, no raw User-Agent (the browser and OS families stay in ClientSummary) and no city. Default on. The on_event hook always gets the full event.

Source

pub fn keep_origin_client(self, keep: bool) -> Self

Keep the full IP, raw User-Agent and city in each session’s SessionOrigin. Default off: the origin holds only the IP’s /24 (IPv4) or /48 (IPv6) network and the ClientSummary without city, which is enough for a “your devices” page.

Source

pub fn shadow_dedup_window(self, window: Duration) -> Self

Shadow event dedup window. Default 10 minutes. Zero records every shadow event.

Source

pub fn alert_dedup_window(self, window: Duration) -> Self

Per-subject alert dedup window. Default zero (off).

When set, the hook sees at most one enforced security-relevant event per subject and kind per window, across processes through SessionStore::claim_event with ClaimScope::Subject. Use it so an attacker hammering many sessions of one subject pages its owner once instead of once per session. Every event is still logged and stored; login, logout and step-up completion always reach the hook.

Source

pub fn max_header_len(self, len: usize) -> Self

Maximum header value length considered. Longer values are truncated. Default 512.

Source

pub fn token_prefix(self, prefix: impl Into<String>) -> Self

Prefix for issued tokens, such as "sess_". Default none.

The cookie value becomes the prefix followed by the usual 43 characters, and any presented token without the prefix is rejected before the store is consulted. Use it to tell browser sessions apart from other credentials at a glance (for example pat_ and svc_ API keys handled elsewhere), and to let secret scanners recognise leaked tokens. The prefix is not secret and is not part of the stored hash.

Source

pub fn build(self) -> Result<GuardConfig, ConfigError>

Validates and builds.

§Errors

ConfigError for invalid cookie attributes, zero or oversized durations, a grace not shorter than the rotation interval, invalid thresholds, header names or token prefix.

Trait Implementations§

Source§

impl Clone for GuardConfigBuilder

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 Debug for GuardConfigBuilder

Source§

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

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

impl Default for GuardConfigBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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<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> IntoApi for T

Source§

fn into_api<A>(self) -> UseApi<T, A>
where T: Sized,

into UseApi
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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<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