Authentication and roles

Two ways to sign in, for two different situations:

Microsoft (Entra ID)

Break-glass (local)

Use

Every day

Microsoft 365 sign-in unavailable (outage, Conditional Access mistake, tenant recovery)

Who

Users assigned an app role in Entra

A few local admin accounts

Factors

Whatever Entra enforces (MFA, Conditional Access)

Password (14+ chars) and TOTP code or one-time recovery code

Role

From the roles claim at each sign-in

Always admin

Session

1 h idle, 12 h maximum

30 min idle, 4 h maximum

Alerting

Audit log

Audit log and a breakglass_login alert every time

Microsoft sign-in

OpenID Connect authorisation-code flow with PKCE, run through MSAL against the Mail Safehouse – Sign-in app registration (created by the setup wizard with a server-held certificate, or configured by hand with a client secret under Settings → Sign-in).

Roles come from app roles on that registration. Assign users or groups to them in Entra → Enterprise applications → Mail Safehouse – Sign-in → Users and groups:

App role value

Role

Can

S365B.Admin

admin

Everything, including settings, users, branding

S365B.Operator

operator

Run and manage backup jobs

S365B.RestoreOperator

restore_operator

Browse, restore and export

S365B.Auditor

auditor

Read-only, including the audit log

Users without a role are refused. The wizard sets Assignment required so unassigned users cannot even reach the consent screen. App roles are used rather than group claims because they are explicit, never overflow the token size limit, and are managed in one place.

The callback URL is https://<your host>/api/v1/auth/entra/callback (shown under Settings → Sign-in).

Break-glass accounts

For when Microsoft sign-in cannot work. Keep the password and recovery codes offline (a safe, a password vault that does not depend on Microsoft 365).

  • Creating the first one: the web UI asks for the one-time setup token from the log (docker compose logs api | grep setup_token), or run docker compose exec api s365b create-local-admin <name>.

  • More accounts: Users → New break-glass admin. Two are recommended, held by different people.

  • TOTP: any authenticator app. Codes cannot be reused, even within their 30-second window.

  • Recovery codes: ten single-use codes, shown once. Each use is reported in the alert, with the number left.

  • Lockout: 5 wrong attempts lock the account for 15 minutes and raise a login_lockout alert.

  • Network allow-list: Settings → Sign-in → Break-glass networks (e.g. your LAN only). The UI refuses a change that would lock out the admin making it.

  • Last account protection: the last working break-glass admin cannot be disabled, nor reset from the UI (until its new authenticator is confirmed there would be none). Both checks hold a database lock, so two admins disabling each other at once leave one working.

  • Lost authenticator, nobody can sign in: from a shell on the server, docker compose exec api s365b reset-local-admin <name>. Shell access to the host is the trust boundary.

Sessions and CSRF

  • The browser holds a random token in an HttpOnly, Secure, SameSite=Lax cookie; the database stores only its SHA-256.

  • Every state-changing request must send the session’s CSRF token in the X-CSRF-Token header (the UI does this automatically).

  • Disabling a user or resetting their credentials ends their sessions.

Audit

Sign-ins (successful and failed), sign-outs, bootstrap, user changes and settings changes are written to the audit log with user, IP and time.