Configuration
On this page
- Introduction
- Durations
- Guard and Users
- Features
- Registration
- Redirects
- Routes
- Pages
- WebAuthn
- Single Sign-On
- Account Changes and Enrollment
- Devices
- Sessions
- Impersonation
- Protected Attributes and Email Changes
- Passwords
- Risk
- Security Log
- Pending Logins, Timebox and Rate Limits
- Messages and Translations
- The Keyring Facade
Introduction
You configure Keyring in two places:
- The
KeyringConfigsection holds values: features, timeouts, limits, route options, factors, risk signals, pages and emails. Change it inwith_config. KeyringServiceProviderholds behaviour that runs your code: your actions, the policy closure, the pipeline, and who may sign in, enroll or impersonate. Chain these on the provider where you add it.
use laravel_keyring::{KeyringConfig, KeyringServiceProvider}; laravel::Application::configure() .with_providers(|providers| { providers.add(KeyringServiceProvider::<Users>::new().allow_sign_in_when(|user: &User| !user.banned)); }) .with_config(|config, _| { let keyring = config.section_mut::<KeyringConfig>(); keyring.home = "/home".to_owned(); keyring.sessions.idle = std::time::Duration::from_secs(60 * 60); });There's no config/keyring.php and nothing to publish. Every setting starts at the PHP package's default unless this page says otherwise, so you only set what you change. The crate reads four environment variables of its own: KEYRING_HOME, KEYRING_SESSION_USER_TYPE, KEYRING_SESSION_DRIVER and KEYRING_WEBAUTHN_RP_ID. It also reads APP_URL and DB_CONNECTION.
A setting the crate can't work with, such as a prune_at that isn't HH:MM or a password minimum under eight, stops the application booting rather than failing a request.
Durations
Durations are std::time::Duration values, such as Duration::from_secs(15 * 60). There are no strings like "15m". A duration that can be turned off is an Option<Duration>, with None for off.
Guard and Users
| Setting | Default | Notes |
|---|---|---|
guard |
web |
Recorded with each session. The guard is the session guard you register for your provider in with_auth. |
username |
email |
The field the login form sends the username in. Your provider's find_for_login() looks it up. |
email |
email |
The field registration and resets read the address from. |
authenticatable_type, session_user_type |
App\Models\User, DB_CONNECTION:users |
How a user's type is written in Keyring's tables. See The Two User Types. |
Keyring lowercases and trims input before it looks users up, as the PHP package does. normalize_usernames_using() on the provider changes that. See Finding the User.
Features
let features = &mut config.section_mut::<KeyringConfig>().features;features.registration = true;features.reset_passwords = true;features.email_verification = true;features.update_passwords = true;features.manage_authenticators = true;features.devices = true;features.email_changes = true;features.sso = true;features.impersonation = true;Signing in and out, challenges and step-up are always on. Everything else is a bool in features, which adds its routes only once it's on. Every feature starts off, unlike the PHP package, whose config turns on registration, password resets, email verification and password changes, since each of those runs code of yours. Turn one on and give the provider its action:
| Feature | Needs |
|---|---|
registration |
create_users_using(), a CreatesNewUsers. And email_verification unless registration.reveal_taken is on. |
reset_passwords |
reset_user_passwords_using(), a ResetsUserPasswords. |
update_passwords |
update_user_passwords_using(), an UpdatesUserPasswords. |
email_verification |
verify_emails(), for a user type that derives MustVerifyEmail, and http::verification_page::<User>(auth) in with_auth. |
email_changes |
change_emails_using(), a ChangesEmails. |
sso |
At least one provider in sso.providers. |
impersonation |
allow_impersonation_when(). Until then nobody may. |
A feature that's on without what it needs stops the application booting. The security log isn't a feature here: it's security_log.enabled, on by default. See Security Log.
Registration
| Setting | Default | Notes |
|---|---|---|
registration.reveal_taken |
false |
Say when an address is taken, and sign new users in straight away. |
registration.verified_before_sign_in |
true |
Keep a user whose address isn't verified from signing in, but from the browser that followed their link. |
The first is the PHP package's registration.reveal_taken. The second is a switch of its own, on by default as the PHP package's default config has it, so you can match the PHP side when the two share users, whether or not registration is on here. See Registration.
Redirects
| Setting | Default | Notes |
|---|---|---|
home (KEYRING_HOME) |
/dashboard |
Where users go after signing in or confirming, when there's no intended URL on this site. |
A signed-in browser at a guest page is sent to home too. The PHP package sends it where Laravel's RedirectIfAuthenticated does, / unless the application says otherwise, so set home to match when the two serve the same users. See Where They Go Next.
Routes
| Setting | Default | Notes |
|---|---|---|
routes |
true |
Whether the provider registers Keyring's routes. |
prefix |
Empty | A path Keyring's routes are under. A plain path: a {placeholder}, a query, a fragment or whitespace stops the application booting. |
domain |
None |
A host Keyring's routes are on. A plain host: a {placeholder} stops the application booting. |
Every URL Keyring makes to its routes (redirects, JSON and emailed links) follows prefix and domain. There's no middleware setting.
Keyring's responses get the PHP package's security headers from http::SecurityHeaders, which Keyring puts on its own routes: Cache-Control: no-store, private, X-Content-Type-Options: nosniff, X-Frame-Options: DENY and Cross-Origin-Opener-Policy: same-origin-allow-popups, with Referrer-Policy: same-origin, or no-referrer on pages that emailed links open.
To register nothing and place the routes yourself, set routes to false and call http::routes():
use laravel_keyring::KeyringConfig; laravel::Application::configure() .with_config(|config, _| { config.section_mut::<KeyringConfig>().routes = false; }) .with_routing(|routing, config| { let keyring = config.section::<KeyringConfig>().clone(); routing.web(move |route| { route.middleware(AuditTrail).group(|route| { laravel_keyring::http::routes::<Users>(route, &keyring); }); }); });AuditTrail is a middleware of your own. http::routes() registers under prefix and domain itself, so set those in the config rather than wrapping the routes in a group with a prefix: Keyring builds its URLs from the config, not from the group. A group of your own is for middleware. See Routes for what else differs.
Pages
| Setting | Default | Notes |
|---|---|---|
pages.enabled |
true |
Render Keyring's pages for a request that doesn't want JSON. Off, those are a 404. |
pages.page(name, component) |
Renders a page as another component or view, as Keyring::page() with a string. |
|
pages.render_using(name, closure) |
Answers a page your own way, as Keyring::page() with a closure. |
Keyring renders its pages as Inertia components with the inertia feature, or as views. Turn pages.enabled off when every page lives in a frontend Laravel for Rust doesn't serve. Pages given with render_using() still answer. See Headless Frontends.
WebAuthn
| Setting | Default | Notes |
|---|---|---|
webauthn.relying_party_id (KEYRING_WEBAUTHN_RP_ID) |
APP_URL's host |
|
webauthn.origins |
APP_URL's origin |
An origin that isn't a full URL, or a relying party ID that isn't each origin's host or a parent of it, stops the application booting. |
webauthn.timeout |
60 seconds | |
webauthn.login_options_for |
5 minutes | How long the options for a passkey sign in are kept for the answer, never less than the timeout. |
webauthn.require_user_verification |
true |
Whether a passkey on the challenge page has to verify the user. Signing in with a passkey alone always asks for it. |
webauthn.require_attestation, aaguids |
false, None |
Passkeys' attestation and the only models taken, as requireAttestation() and allowOnly(). |
webauthn.security_keys |
None |
Security keys, as a KeyProfile (KeyProfile::security_keys()), with require_user_verification, require_attestation and aaguids. None leaves the factor out. |
webauthn.keys |
Empty | More WebAuthn second factors under keys of their own, each a KeyFactor::new(key, KeyProfile), as WebAuthn::securityKeys()->as(). |
webauthn.attestation_roots |
Empty | The PEM root certificates attestation has to chain to, for every model. |
webauthn.trusts |
None |
Your own Arc<dyn TrustsAuthenticators>, the roots each model's attestation may chain to, in place of attestation_roots. |
webauthn.algorithms, minimum_rsa_bits |
ES256, 2048 |
The signatures keys may use. RS256 is taken when listed. EdDSA can't be checked here. |
A model list without attestation, an AAGUID that isn't a UUID, a root that can't be read, or no algorithm the crate can check stops the application booting. See Passkeys & Security Keys.
Single Sign-On
| Setting | Default | Notes |
|---|---|---|
sso.providers |
Empty | The identity providers, as SsoProvider values, in the order the login page lists them. |
sso.request_for |
10 minutes | How long a user sent to a provider has to come back. |
sso.cache_for, sso.store |
One hour, the default store | How long providers' discovery documents and keys are cached, and where. |
sso.extend(driver, resolver) |
Adds a driver of your own. |
See Single Sign-On.
Account Changes and Enrollment
| Setting | Default | Notes |
|---|---|---|
changes_fresh_for |
15 minutes | How recent a verification must be to change how the user is signed in on Keyring's routes (sessions, devices, authenticators, the password and the email address), the PHP package's changes_middleware. None lets those routes through on any signed-in session. It doesn't change RequireFreshVerification on your routes. |
authenticator_changes.established_after |
7 days | How long before a new authenticator raises what's asked, and how long the freeze lasts. Zero turns the freeze off. |
authenticator_changes.skip_with_totp |
false |
Whether an established authenticator app can prove a change to a frozen account. |
enrollments |
15 minutes | How long an enrollment can be confirmed for. |
enrollment_url |
None |
Where a user who has to set up another sign-in method first is sent: the redirect of the 403 enroll-first. |
enrollment_except |
Empty | Paths of your own a user who still has to enroll may reach past RequireEnrollment. A * matches anything. The PHP package's option names routes. password_change_url gets past it too while the user has to choose a new password. |
authenticators_url |
None |
Your page for sign-in methods, for the emails that link to it. A path goes after APP_URL (or the root from link_root_using()), never the request's host, and a full URL is used as it is. |
The PHP package's changes_middleware lists middleware. laravel-rust has no middleware names for a setting to list, so the crate's setting is the window alone. See Managing Authenticators.
Devices
| Setting | Default | Notes |
|---|---|---|
devices.cookie |
None |
The device cookie's name. None gives known_device over plain HTTP, and a __Host- or __Secure- prefixed name over HTTPS. |
devices.cookie_lifetime |
400 days | |
devices.limit |
50 | Devices per account. A new one takes the place of the one seen longest ago, and that device's sessions are signed out. |
devices.trust_for |
30 days | How long "don't ask again on this device" trusts a device. None never offers it. |
devices.report_link_for |
7 days | How long a "this wasn't me" link works. |
devices.keep_revoked_for, keep_unseen_for |
30 days, 365 days | How long keyring:prune keeps a signed-out device, and one nobody has signed in from. |
devices.locator |
None |
Works out where a request comes from: an Arc<dyn LocatesIps>, such as HeaderLocator::cloudflare(). |
devices.describe_using() |
Keyring's own | Names a browser from its user agent your own way. |
See Devices & Sessions.
Sessions
| Setting | Default | Notes |
|---|---|---|
sessions.idle, absolute |
2 hours, 30 days | The idle and absolute timeouts. |
sessions.levels |
AAL2 1 hour idle and 24 hours absolute, AAL3 15 minutes and 12 hours | Each level's own clock, as levels.aal2 and levels.aal3, each a LevelTimeouts with idle and absolute. |
sessions.end_on_lapse |
false |
Whether a session ends once the level it signed in at lapses. |
sessions.remember_idle |
14 days | How long a session that ticked "remember me" may go unused, in place of the idle timeout. |
sessions.remember_cookie |
None |
The name of the cookie that ties "remember me" to its session. None gives remembered_session, prefixed over HTTPS like the device cookie. |
sessions.remember_grace |
10 seconds | How long after "remember me" brings a session back the browser's other requests sent alongside join it. |
sessions.max |
100 | How many sessions an account has at once. None for no limit. |
sessions.driver (KEYRING_SESSION_DRIVER), connection, table, store |
database, the default, keyring_sessions, the default |
Where the session registry keeps sessions. sessions.extend() adds a driver of your own. |
sessions.middleware |
true |
Whether the provider adds AuthenticateSession and RequirePasswordChange to the web group. |
sessions.block |
Empty | Routes of your own that take the session lock, as ->block(): a method and the route's URI as registered, such as (Method::POST, "/admin/users/{user}/impersonate".to_owned()). |
sessions.continue_as_guest |
Empty | Paths of your own pages that also serve guests. A trailing * matches the rest. |
sessions.sweep_every |
None |
How often keyring:sweep runs. None or zero leaves it off. Under a minute is a minute, and over 12 hours is 12 hours. |
sessions.sweep_limit |
1000 | How many sessions one sweep ends, and how many it announces again, at most 10,000 of each. |
prune_at |
Some("03:00") |
When keyring:prune runs each day, in UTC. None leaves scheduling it to you. |
There's no sessions.overlapping_requests: see Requests That Overlap a Sign In. See Devices & Sessions.
Impersonation
| Setting | Default | Notes |
|---|---|---|
impersonation.lifetime |
One hour | How long an impersonation lasts. It can't be zero. |
impersonation.show_in_sessions, show_in_activity |
true, true |
Whether the user's sessions list shows the impersonated session, and security_log::activity() its start and end. |
impersonation.requires_aal2, fresh_for |
true, 15 minutes |
What starting asks, in place of the PHP package's impersonation.middleware. |
impersonation.redirect_url, return_url |
None |
Where starting goes, and where going back goes. None is home. |
See Impersonation.
Protected Attributes and Email Changes
| Setting | Default | Notes |
|---|---|---|
protected |
Empty | Attributes of your own besides the password and the address that only Keyring's flows may change, for protection::guard(). |
email_changes.confirmable_for |
24 hours | How long the new address has to confirm. |
email_changes.revertable_for |
7 days | How long the old address can undo a change, and stays reserved. |
email_changes.established_after |
7 days | How long a second factor has to be held before the session that proved it skips confirming from the current address. |
email_changes.sign_out_others |
true |
Whether applying a change signs out every other session. |
email_changes.keep_ended_for |
30 days | How long keyring:prune keeps a change that ended. |
See Protected Changes.
Passwords
| Setting | Default | Notes |
|---|---|---|
passwords.min_without_mfa |
15 | The shortest new password PasswordRules takes at registration and from a user without a second factor, and the shortest that can stand alone once the last second factor is removed. Under eight stops the application booting. |
passwords.min_with_mfa |
8 | The shortest new password PasswordRules takes from a user with a second factor. Under eight stops the application booting. |
passwords.max |
128 | The longest new password PasswordRules takes. |
passwords.uncompromised, refuse_unchecked |
None, false |
Whether PasswordRules asks Have I Been Pwned about a new password (None asks in production), and whether one it couldn't ask about is refused. |
passwords.context |
Empty | Words of your app's own, besides app.name, that a new password mustn't be made of. |
passwords.expire, throttle |
One hour, one minute | How long a reset link works, and how soon another can be sent, as Laravel's broker. |
verification_expire |
One hour | How long a verification link works, as auth.verification.expire. |
password_change_url |
None |
Where a held user changes their password: the redirect of the 403 change-password. A held user gets past RequireEnrollment there, so serve only the change-password page at this path. |
password_change_except |
Empty | Paths of your own a held user may still reach. A trailing * matches the rest. The PHP package's option names routes. |
See Password Rules.
Risk
| Setting | Default | Notes |
|---|---|---|
risk.signals |
Empty | The signals that run, as Arc<dyn Signal> values, as Keyring::risk()->signals(). |
risk.respond |
None |
What to do about a risk, a fn(&Risk, Checkpoint) -> Action, as Keyring::risk()->respond(). None is Keyring's own response. |
risk.levels |
30, 60, 90 | The scores at which risk is medium, high and critical (medium, high, critical). |
risk.recent_change |
7 days | How recently an email change counts for RecentlyChangedRecovery. |
There's no risk.store: risk locks are in the default cache store. See Risk.
Security Log
| Setting | Default | Notes |
|---|---|---|
security_log.enabled |
true |
Whether entries go to keyring_events, as Features::securityLog(). Off, each is a tracing event under keyring::security_log. |
security_log.context_key |
trace_id |
Where your application keeps a request's ID in laravel-rust's context. Without one, Keyring makes a UUID per request. |
security_log.refusals, refusals_per |
20, one hour | How many entries of one refused kind are written per account or address. |
security_log.alerts |
As the PHP package | The entry types a sign in answers as alerts. |
security_log.unlisted |
Empty | Your own types that security_log::activity() leaves out. |
security_log.keep_for |
180 days | How long keyring:prune keeps an entry. |
notifications |
All on but clone_suspected |
A switch for each security email, and closures for your own emails. See Security Emails. |
support_contact |
None |
Where to get help, which every security email ends with. |
record_ips_using |
None |
What's kept of a request's address in the log, the emails, the sessions and the devices, as Keyring::recordIpsUsing(): a plain fn(&Request) -> Option<String>. None keeps the address. Rate limits always use the real one. |
There's no security_log.channel. See Security Log & Emails.
Pending Logins, Timebox and Rate Limits
| Setting | Default | Notes |
|---|---|---|
pending_logins |
10 minutes | How long a password can wait for its second factor. |
timebox |
500 ms | The least time a refused sign in takes, so the response doesn't reveal whether an account exists. |
limits.per_account, per_ip |
5, 20 | Sign-in attempts a minute for an account and from an address. |
limits.consecutive, consecutive_elsewhere |
100, 80 | Failures in a row before a method is refused until cleared, and how many of them browsers the account hasn't signed in from may make. |
limits.longest_lock, longest_ip_lock |
One day, 15 minutes | The longest a doubling lock lasts, for an account and for an address. |
limits.lock_after |
None |
Failures after which an account is locked until a reset. |
limits.remember_names_for |
30 days | How long the names typed at a lock are remembered. |
limits.login_options |
60 | The keyring-login-options limiter: passkey options and single sign-on redirects a minute from an address. |
limits.session_changes, session_changes_per_user |
6, 30 | The keyring-session-changes limiter: a minute from one session, and from all the user's together. |
limits.codes, codes_per |
3, ten minutes | How many codes an account is sent for one factor in each of three buckets. |
limits.notices, notices_per |
5, one hour | How many security emails of one kind an account gets. |
limits.forms, guest_forms, pages |
6, 6, 60 | The keyring limiter on the form routes, a minute per signed-in user and per address, and keyring-pages on the pages emailed links open. |
The limiters are the PHP package's, under the same names in the security log and RateLimited, but they're settings rather than limiters you redefine, as laravel-rust has no named limiters. Rate limits are counted in the default cache store. See Rate Limiting.
Messages and Translations
laravel-rust has no translator or locale, so there are no translation files. Every message is the PHP package's English one, and http::status_message(status) gives a status slug's. Email wording lives in your own closures on notifications. See Your Own Templates.
The Keyring Facade
There's no facade. What you set in code goes on the provider or in the config, and the rest are functions in laravel_keyring:
| PHP | Rust |
|---|---|
Keyring::factors([...]) |
factors, email_codes, webauthn.security_keys and webauthn.keys in the config. See Factors. |
Keyring::extend($key, $resolver) |
The provider's primary_factor(), second_factor() or code_factor(). |
Keyring::require($requirement) |
policy in the config, or the provider's policy() for a closure. See Policies. |
Keyring::pipeline($callback) |
The provider's pipeline(). See The Verification Pipeline. |
Keyring::respondWith(...) |
responses.respond_with() in the config. See Responses. |
Keyring::page($name, $component) |
pages.page() and pages.render_using() in the config. |
Keyring::risk()->signals([...])->respond(...) |
risk.signals and risk.respond in the config. See Risk. |
Keyring::notifications([...]) |
notifications in the config: turn_on(), turn_off(), mail(), mail_using and the flow emails' methods. |
Keyring::createUsersUsing(), resetUserPasswordsUsing(), updateUserPasswordsUsing(), validateEmailChangesUsing() |
The provider's create_users_using(), reset_user_passwords_using(), update_user_passwords_using() and change_emails_using(). |
Keyring::routes() |
http::routes::<Users>(route, &config). |
Keyring::useAuthenticatorModel() and the rest |
Not available: there are no models. |
Keyring::attempt($request, $factor) |
sign_in::attempt(). See Starting a Sign In Yourself. |
Keyring::requirePasswordChange(), requiresPasswordChange(), cancelPasswordChange() |
require_password_change(), requires_password_change(), password_change_reason() and cancel_password_change(). |
Keyring::unlock($user, $factor = null) |
unlock(&user) and unlock_factor(&user, factor). clear_account(&user) starts the account's sign-in limits over. |
Keyring::allowSignInWhen(), allowEnrollmentWhen(), allowImpersonationWhen() |
The provider's allow_sign_in_when(), allow_enrollment_when() and allow_impersonation_when(). |
Keyring::impersonate(), stopImpersonating() |
impersonation::impersonate() and impersonation::stop_impersonating(). |
Keyring::linkRootUsing() |
The provider's link_root_using(). |
Keyring::sso() |
sso.extend() in the config, and sso::start(), sso::complete(), sso::providers(), sso::provider(), sso::has(), sso::names() and sso::freshness(). |
Keyring::recordIpsUsing() |
record_ips_using in the config. |
Keyring::describeDevicesUsing() |
devices.describe_using() in the config. |
Keyring::findUsersUsing() |
Your provider's find_for_login(). |
Keyring::normalizeUsernamesUsing() |
The provider's normalize_usernames_using(). |
Keyring::signInAfterRegistering() |
The provider's sign_in_after_registering(). |
Keyring::withoutProtection() |
protection::without_protection(). |
Keyring::activity(), unlistedActivityTypes() |
security_log::activity() and security_log::unlisted_activity_types(). |
Keyring::for($user) |
UserKeyring::of(&user). |
Keyring::fake() |
testing::fake(&app). See Testing. |
These answer questions about your setup:
| PHP | Rust |
|---|---|
Keyring::registered(), hasFactor() |
registered_factors() and has_factor(). There's no Keyring::factor(), as there's no public factor type. |
Keyring::normalizeUsername() |
normalize_username(). |
Keyring::requirementFor() |
policy::requirement_for(). |
Keyring::policy() |
policy::ask(). |
Keyring::statusMessage() |
http::status_message(). |
Keyring::render() |
http::render(). |
Keyring::result() |
http::result(&session, key). |
Keyring::protectedAttributes() |
protection::attributes(). |
Keyring::describeDevice() |
describe_device(), and describe_user_agent() for Keyring's own reading. |
Keyring::linkRoot() |
link_root(). |
Keyring::steps(), dangerouslyChangedSteps() |
pipeline::names() and pipeline::dangerously_changed_steps(). |
Keyring::hidesRegisteredAddresses() |
KeyringConfig::hides_registered_addresses(). |
Keyring::signsInAfterRegistering() |
signs_in_after_registering(). |
Keyring::recordedIp() |
KeyringConfig::recorded_ip(). |
Keyring::allowsSignIn(), allowsEnrollment() |
allows_sign_in() and allows_enrollment(). |
Keyring::allowsImpersonation(), impersonationRefusal() |
impersonation::allows() and impersonation::refusal(). |
Keyring::impersonating(), impersonator(), impersonation() |
impersonation::active(), impersonation::impersonator::<User>() and impersonation::banner(). |
Keyring::guard(), provider(), username(), email(), user() |
Your guard and provider, and username and email in the config. |
Keyring::response(), notification(), hasNotification(), findUser(), belongsToGuard() and the model getters |
Not available. notifications.enabled(kind) says whether a security email is sent. |