Add Settings -> Database viewer (Adminer) for local devs and any admin

Local dev gets an unauthenticated Adminer instance bound to loopback
only. In production, any account with is_admin=true can open it -
the app mints a short-lived token from a live admin session, which
Nginx's new db.ciagent.org block exchanges for a session cookie that
re-checks admin status on every request, instead of a shared static
password that wouldn't scale to multiple admins or revoke live.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
2026-08-05 22:18:16 -04:00
co-authored by Claude Sonnet 5
parent 6343ea19db
commit 3d6fe56991
17 changed files with 633 additions and 8 deletions
+13
View File
@@ -75,6 +75,11 @@ def verify_password(raw_password: str, password_hash: str) -> bool:
class TokenType(StrEnum):
ACCESS = "access"
REFRESH = "refresh"
# Settings -> Database viewer: a short-lived token minted from a live
# admin session, exchanged (via Nginx's db.ciagent.org /_auth route) for
# a longer-lived DB_VIEWER_SESSION cookie. See app/api/v1/db_viewer.py.
DB_VIEWER_BOOTSTRAP = "db_viewer_bootstrap"
DB_VIEWER_SESSION = "db_viewer_session"
@dataclass(frozen=True)
@@ -105,6 +110,14 @@ def create_refresh_token(user_id: uuid.UUID, settings: Settings) -> tuple[str, s
return token, jti, expires_at
def create_db_viewer_bootstrap_token(user_id: uuid.UUID, settings: Settings) -> str:
return _encode_token(user_id, TokenType.DB_VIEWER_BOOTSTRAP, timedelta(minutes=2), settings)
def create_db_viewer_session_token(user_id: uuid.UUID, settings: Settings) -> str:
return _encode_token(user_id, TokenType.DB_VIEWER_SESSION, timedelta(minutes=60), settings)
def _encode_token(
user_id: uuid.UUID,
token_type: TokenType,