Files
UmbraTrans/umbratrans_web/__init__.py
umbra audio b474995414 Add phase-1 account management backend slice
Implements the account and user-management system behind the new web UI
against development repositories only. Nothing here connects to, reads, or
modifies the production umbracontrol database, and no account is created in
any approved environment.

Account service and API:
- Local temporary-password and OIDC enrollment, separated by type.
- Argon2id credentials, must-change enforcement, server-side sessions with
  hashed tokens, idle and absolute deadlines, rotation and revocation.
- Administrator account management: list, get, create, suspend, reactivate,
  deactivate, revoke sessions, org-scoped audit view.
- Hidden-prompt operator command for the first administrator, refusing
  production mode and refusing to run without a TTY.

Temporary passwords are never accepted from a client. The request schema has
no password field and refuses unknown fields; the administrator path generates
the one-time password in process, hashes it immediately, and returns it once in
the creation response. The account can reach no route, including
/api/auth/me, until it replaces that password, after which the one-time value
no longer authenticates.

Security posture: fail-closed configuration, Secure cookies in production,
double-submit CSRF, constant-time token comparison, generic authentication
errors, audit detail allow-listing, and logger-tree secret redaction.

Reviewed but unapplied: migrations/0001_phase1_identity.sql adds
users.username, a separate user_credentials table, and additive session
columns, with a rollback and open review questions. The PostgreSQL adapter is
deliberately absent, so the application refuses to start in production rather
than run against an unreviewed store.

Verification: 169 tests pass (148 new, 21 pre-existing); ruff check, ruff
format, compileall, and make web-check are clean.
2026-09-26 08:29:23 -07:00

97 lines
2.5 KiB
Python

"""UmbraTrans web account management: phase-1 identity slice.
This package implements the first backend slice described in
``docs/umbratrans-backend-design.md``: accounts, both enrollment modes, Argon2id
credentials, server-side sessions, administrator lifecycle actions, and
sanitized audit events, plus a FastAPI application factory.
It does not connect to PostgreSQL. The reviewed migration in
``umbratrans_web/migrations/`` is intentionally unapplied, and the production
repository adapter is not part of this slice, so the application fails closed
rather than starting without an audit-reviewed store.
"""
from __future__ import annotations
from .config import SERVICE_NAME, SERVICE_VERSION, Environment, Settings, load_settings, suite_settings
from .errors import (
AuthenticationRequiredError,
ConfigurationError,
ConflictError,
CsrfError,
EnrollmentRefusedError,
ForbiddenError,
InputError,
InvalidCredentialsError,
NotFoundError,
OperatorRefusalError,
PasswordChangeRequiredError,
PasswordPolicyError,
RepositoryError,
StateTransitionError,
UmbraWebError,
)
from .models import (
AccountStatus,
AccountView,
AuditEvent,
AuthenticationResult,
CredentialRecord,
CredentialType,
EnrollmentMode,
IssuedSession,
Principal,
RoleName,
SessionRecord,
User,
)
from .repository import AccountRepository, InMemoryAccountRepository
from .security import PasswordPolicy, PasswordService
from .service import AccountService, OperatorContext
__version__ = SERVICE_VERSION
__all__ = [
"SERVICE_NAME",
"SERVICE_VERSION",
"AccountRepository",
"AccountService",
"AccountStatus",
"AccountView",
"AuditEvent",
"AuthenticationRequiredError",
"AuthenticationResult",
"AuditEvent",
"ConfigurationError",
"ConflictError",
"CredentialRecord",
"CredentialType",
"CsrfError",
"EnrollmentMode",
"EnrollmentRefusedError",
"Environment",
"ForbiddenError",
"InputError",
"InMemoryAccountRepository",
"InvalidCredentialsError",
"IssuedSession",
"NotFoundError",
"OperatorContext",
"OperatorRefusalError",
"PasswordChangeRequiredError",
"PasswordPolicy",
"PasswordPolicyError",
"PasswordService",
"Principal",
"RepositoryError",
"RoleName",
"SessionRecord",
"Settings",
"StateTransitionError",
"UmbraWebError",
"User",
"__version__",
"load_settings",
"suite_settings",
]