# Admin authentication The dashboard is **public read-only**: anyone can open the map and the news brief. One admin (the operator) additionally gets API-key management, settings and every state-changing route. There is no user table, no RBAC and no OAuth — one admin, one signed cookie (`app/auth.py`). ## Surface | Route | Anonymous | Admin | | --- | --- | --- | | `GET /`, `GET /login`, `GET /static/*`, `WS /ws/live` | ✅ | ✅ | | Read allowlist (`GET /api/news`, `/api/map/*`, feeds, analytics, cameras, `POST /api/search`, …) | ✅ | ✅ | | `GET/POST/DELETE /api/keys*` | 401 | ✅ | | `GET/PUT /api/settings`, `GET /api/news/models` | 401 | ✅ | | Every other `POST/PUT/PATCH/DELETE` (`/api/ingest/*`, `/api/sources`, events, entities, alerts, geofences, `/api/vessels/subscribe`) | 401 | ✅ | | `GET /api/auth/me` | 200 `{"authenticated": false, "admin": false}` | 200, both `true` | | `POST /api/auth/login` | — | 200 + `Set-Cookie` | | `POST /api/auth/logout` | 200 (clears cookie) | 200 | Enforcement is **deny-by-default on `/api/*`** in `AdminAuthMiddleware` (`app/auth.py`); the public list is an explicit allowlist (`PUBLIC_GET_EXACT`, `PUBLIC_GET_PATTERNS`, `PUBLIC_POST_EXACT`). Naming a path there is the only way to make it public — never a per-route decorator in `app/main.py`. ## Configuration Three environment variables (cluster: Secret `osint-admin`): | Variable | Meaning | | --- | --- | | `ADMIN_USER` | Admin username. | | `ADMIN_PASSWORD_HASH` | `pbkdf2_sha256$$$`. | | `ADMIN_SESSION_SECRET` | HMAC-SHA256 key for the session token. | ```bash python app/auth.py hash 'your password' # password hash python -c 'import secrets; print(secrets.token_urlsafe(48))' # session secret ``` Put the values into a Secret and reference them from the deployment; never commit them. ### Fail closed If `ADMIN_PASSWORD_HASH` **or** `ADMIN_SESSION_SECRET` is unset/empty: * every admin endpoint answers `403 {"detail": "admin auth not configured"}`, * `/login` renders that message instead of the form, * `/api/auth/login` also answers 403, * public pages and the read allowlist still work. There is no default password and no bypass. ## Session cookie `osint_session`, HMAC-SHA256 signed base64url JSON payload `{v,sub,iat,exp}`, `HttpOnly`, `SameSite=Lax`, `Path=/`, 7-day lifetime, `Secure` when the request arrived over https (`X-Forwarded-Proto`, i.e. behind Cloudflare). Signature and expiry are checked with `hmac.compare_digest`; a token for another username, or one signed with a different secret, is rejected. Set `ADMIN_COOKIE_SECURE=1` (`true`/`yes` also work) whenever the deployment is TLS-only but the app itself is reached over plain HTTP. In the cluster the Cloudflare tunnel originates at the Cilium Gateway on plain HTTP and Envoy normalizes `X-Forwarded-Proto` to `http`, so the header inference never fires there — the flag is what makes the cookie `Secure` in the cluster. Leave it unset for local development, where the cookie has to work over `http://localhost`. ## Abuse controls * **Login rate limit:** 5 failed attempts per client IP (first hop of `X-Forwarded-For`, else the socket peer) per 15 minutes, then `429`. In-memory — fine for the single replica. * **CSRF:** state-changing admin requests that carry `Origin`/`Referer` must match the request host, else `403`. Header-less clients (curl, service-to-service) rely on the signed SameSite=Lax cookie. ## HUD `app/static/index.html` hides admin chrome with `body:not(.is-admin) [data-admin]` and adds the class only when `GET /api/auth/me` reports `admin: true`. The menu's Ingest / API Keys / Settings entries, the summarizer panel and the geofence draw/rename/delete controls are admin-only; anonymous visitors see a discreet `SIGN IN` link to `/login`. This is UX only — the API gate is what actually protects the data.