s365b.auth.local¶
Local break-glass accounts.
These exist for one purpose: administering the backup server when Microsoft 365 sign-in is not available (an Entra outage, a misconfigured Conditional Access policy, or a full tenant recovery). Rules:
Password (14+ characters) and a TOTP code or one-time recovery code, always. TOTP codes cannot be replayed.
5 failed attempts lock the account for 15 minutes.
Optional allow-list of networks the sign-in is accepted from.
Every sign-in is audited and raises a notification event.
The first local admin is created during setup with a one-time setup token
printed in the API container log (or by s365b create-local-admin inside
the container), so nobody who merely reaches the page first can claim a new
installation.
Attributes¶
Exceptions¶
Sign-in refused. The message is safe to show (it never says which part was wrong). |
|
The change would leave no usable break-glass admin. |
Classes¶
Break-glass sign-in settings. |
|
What a new break-glass admin must save, shown once. |
Functions¶
|
Create a new one-time setup token (replacing any earlier one). |
|
Return whether a setup token is the current one. |
|
Invalidate the setup token once the first admin exists. |
|
Return whether a usable local admin exists (TOTP enrolled, not disabled). |
|
Create a break-glass admin. TOTP must be confirmed before it can sign in. |
|
Activate TOTP for a new account by checking a first code. |
|
Activate a new or reset account: password and a first authenticator code. |
|
Check break-glass credentials. |
|
Lock break-glass changes, then check one usable admin stays besides a user. |
|
Reset a break-glass account: new TOTP secret and recovery codes, optionally a new password. |
Module Contents¶
- exception s365b.auth.local.LoginError(message: str, *, locked_now: bool = False)[source]¶
Bases:
ExceptionSign-in refused. The message is safe to show (it never says which part was wrong).
- Variables:
locked_now – True if this failure just locked the account.
- class s365b.auth.local.LocalAuthSettings[source]¶
Bases:
s365b.core.settings_store.SettingsGroupBreak-glass sign-in settings.
- Variables:
allowed_networks – CIDR ranges local sign-in is accepted from; empty means any network. Useful to restrict break-glass access to the LAN or a management VLAN.
- class s365b.auth.local.Enrolment[source]¶
What a new break-glass admin must save, shown once.
- Variables:
user_id – New user’s ID.
totp_secret – Base32 secret (for manual entry).
totp_uri –
otpauth://URI (for the QR code).recovery_codes – One-time codes for when the authenticator is lost.
- async s365b.auth.local.issue_setup_token(s: sqlalchemy.ext.asyncio.AsyncSession) str[source]¶
Create a new one-time setup token (replacing any earlier one).
- Parameters:
s – Open session; the caller commits.
- Returns:
The token, to print in the log. Only its hash is stored.
- async s365b.auth.local.check_setup_token(s: sqlalchemy.ext.asyncio.AsyncSession, token: str) bool[source]¶
Return whether a setup token is the current one.
- Parameters:
s – Open session.
token – Token entered by the user.
- Returns:
True if valid.
- async s365b.auth.local.clear_setup_token(s: sqlalchemy.ext.asyncio.AsyncSession) None[source]¶
Invalidate the setup token once the first admin exists.
- Parameters:
s – Open session; the caller commits.
- async s365b.auth.local.has_local_admin(s: sqlalchemy.ext.asyncio.AsyncSession) bool[source]¶
Return whether a usable local admin exists (TOTP enrolled, not disabled).
- Parameters:
s – Open session.
- Returns:
True if one exists.
- async s365b.auth.local.create_local_admin(s: sqlalchemy.ext.asyncio.AsyncSession, box: s365b.core.secrets.SecretBox, username: str, password: str, *, issuer: str, display_name: str = '') Enrolment[source]¶
Create a break-glass admin. TOTP must be confirmed before it can sign in.
- Parameters:
s – Open session; the caller commits.
box – Secret box for the TOTP secret.
username – Lowercase username.
password – Password (checked against the policy).
issuer – Name shown in the authenticator app.
display_name – Optional display name.
- Returns:
Enrolment details to show once.
- Raises:
passwords.PasswordPolicyError – If the password is too weak.
ValueError – If the username is invalid or taken.
- async s365b.auth.local.confirm_totp(s: sqlalchemy.ext.asyncio.AsyncSession, box: s365b.core.secrets.SecretBox, user: s365b.db.models.UserAccount, code: str) bool[source]¶
Activate TOTP for a new account by checking a first code.
- Parameters:
s – Open session; the caller commits.
box – Secret box.
user – The local user.
code – Code from the authenticator app.
- Returns:
True if the code was right and TOTP is now active.
- async s365b.auth.local.confirm_enrolment(s: sqlalchemy.ext.asyncio.AsyncSession, box: s365b.core.secrets.SecretBox, settings: LocalAuthSettings, *, username: str, password: str, code: str, ip: str | None) bool[source]¶
Activate a new or reset account: password and a first authenticator code.
Held to the same rules as sign-in: the network allow-list, and the failed-attempt counter and lockout.
- Parameters:
s – Open session; the caller commits (also on failure).
box – Secret box.
settings – Local sign-in settings.
username – Username.
password – Password.
code – Code from the authenticator app.
ip – Client IP address.
- Returns:
True if the account is now active.
- Raises:
LoginError – If not allowed from this network or the account is locked.
- async s365b.auth.local.authenticate(s: sqlalchemy.ext.asyncio.AsyncSession, box: s365b.core.secrets.SecretBox, settings: LocalAuthSettings, *, username: str, password: str, code: str, ip: str | None) tuple[s365b.db.models.UserAccount, bool][source]¶
Check break-glass credentials.
- Parameters:
s – Open session; the caller commits (also on failure, to keep the failed-attempt counter).
box – Secret box.
settings – Local sign-in settings.
username – Username.
password – Password.
code – TOTP code, or a recovery code (
xxxxxx-xxxxxx).ip – Client IP address.
- Returns:
(user, used_recovery_code).- Raises:
LoginError – For any failure, with a generic message.
- exception s365b.auth.local.LastBreakGlassError[source]¶
Bases:
ExceptionThe change would leave no usable break-glass admin.
- async s365b.auth.local.keep_a_break_glass_admin(s: sqlalchemy.ext.asyncio.AsyncSession, user_id: int) s365b.db.models.UserAccount | None[source]¶
Lock break-glass changes, then check one usable admin stays besides a user.
Call before disabling or resetting a local account; the lock is held until the session’s transaction ends.
- Parameters:
s – Open session; the caller commits.
user_id – The account about to stop being usable.
- Returns:
The account, read after the lock;
Noneif it does not exist.- Raises:
LastBreakGlassError – If it is the last usable break-glass admin.
- async s365b.auth.local.reset_credentials(s: sqlalchemy.ext.asyncio.AsyncSession, box: s365b.core.secrets.SecretBox, user: s365b.db.models.UserAccount, *, password: str | None, issuer: str) Enrolment[source]¶
Reset a break-glass account: new TOTP secret and recovery codes, optionally a new password.
- Parameters:
s – Open session; the caller commits.
box – Secret box.
user – The local user.
password – New password, or
Noneto keep the current one.issuer – Name shown in the authenticator app.
- Returns:
New enrolment details; TOTP must be confirmed again.