Governance + hardening contract¶
Schema: schema/011_governance.sql. Turns the platform from a dashboard into a governable system of record: real auth, RBAC+ABAC with classification, a tamper-evident audit log, provenance, and ops hardening. Three streams.
| Stream | Owns |
|---|---|
| A. orchestrator security+governance | orchestrator auth/authz/audit/provenance + endpoints |
| B. dashboard auth + governance UI | login, role-aware nav, classification banners, audit viewer, provenance |
| C. ops hardening + real-run/FP harness | docker-compose hardening, SECURITY.md, threat model, real-target scan + FP runbook/script |
Everything defensive. Auth gates access; it adds no offensive capability.
A. Orchestrator security + governance¶
AuthN¶
- Two credential types: API key (header
Authorization: Bearer <key>orX-API-Key) and JWT (login → short-lived access token). Keys: on create, generatepak_<prefix>_<secret>, store onlysha256(full), return the raw once. Verify by hashing the presented key and matchingapi_keys.key_hashwhere not revoked/expired; bumplast_used. POST /v1/auth/login {username,password}→{access_token, role, clearance, expires_in}(argon2/bcrypt verify againstapp_users.pw_hash).POST /v1/auth/apikeys(admin) issues keys;GET /v1/auth/apikeys;DELETE /v1/auth/apikeys/{id}(revoke).GET /v1/auth/me.- Bootstrap: on startup, if the seeded
adminhas no pw_hash, set it from envADMIN_BOOTSTRAP_PASSWORD(or generate one and log it ONCE). Never ship a known credential. Replace theALLOW_NO_AUTHstub: keep a dev escape hatchAUTH_MODE=devthat injects a synthetic admin (loudly logged) so local dev + the existing tests still work, but defaultAUTH_MODE=enforce.
AuthZ — RBAC + ABAC¶
- Roles:
viewer(read non-restricted),analyst(read + triage: patch findings/tickets/anomalies, ask, scan),admin(everything incl. scope/owners/alerts/keys),auditor(read + audit log + integrity verify, no mutate). - A dependency
require(role)/require_scope(scope)on every router. Map the existingrequire_scope_adminontorequire('admin'). - ABAC/classification: every asset/finding carries
classification(public<internal<confidential<restricted). Reads filter out rows above the caller'sclearance; the filter is applied in SQL (aWHERE classification <= caller_clearancerank check) so over-classified data never leaves the DB. Document the rank order.
Tamper-evident audit log¶
app/audit.py:record(action, resource_type, resource_id, actor, ...)appends toaudit_logcomputingentry_hash = sha256(prev_hash || canonical_json(row_without_hash)),prev_hash= previous row'sentry_hash(genesis = 64 zeros). Serialize appends (advisory lock or single-writer) so the chain is linear.- Middleware records every mutating request (and denied requests) with actor, role, method, path, status, classification touched, request_id, ip, and optional
X-Justificationheader (purpose-based access). Reads of restricted data are also logged. GET /v1/audit?actor=&action=&from=&to=&limit=&offset=(auditor/admin) paged.GET /v1/audit/verify→ walks the chain, returns{ok, checked, first_broken_id?}— proves tamper-evidence.- Harden at the DB layer where possible: on startup try
REVOKE UPDATE, DELETE ON audit_log FROM <app_role>(best-effort; log if lacking privilege).
Provenance¶
- A
provenancerow per produced fact. Add a bulk helper + wire the existing bulk endpoints (assets/findings) to accept optionalprovenanceand record it (source_service, source_detail, method, evidence, confidence).GET /v1/provenance?subject_type=&subject_id=returns lineage for an item. Back-fill from existingsourcecolumns in a one-time pass endpointPOST /v1/provenance/backfill(admin).
Rules¶
- Additive; existing endpoints keep working under
AUTH_MODE=dev(so the 141 tests + the other services, which call the API as services, keep working — give services a service API key or the dev mode). Document how services authenticate (a per-service API key injected via env, scopewrite). - Tests
tests/test_governance.py(≥20): key hashing + verify + revoke; login + JWT; role gates (viewer can't mutate, auditor can't mutate, analyst can triage, admin all); classification filtering (a confidential finding hidden from an internal-clearance key); audit chain append + verify detects a tampered row; provenance record + fetch.make testmust pass (adjust existing tests to run under AUTH_MODE=dev or with a seeded admin key). Paste counts.
B. Dashboard auth + governance UI¶
- Login screen (username/password → store JWT; or paste an API key). Unauthenticated → redirect to login. Show current user + role + clearance in the top bar; logout.
- Role-aware UI: hide/disable mutate controls for
viewer/auditor; show everything foradmin. Read the role from/v1/auth/me. - Classification banners/badges: a top banner reflecting the highest classification on screen; a small classification chip on finding/asset rows (color-coded public→restricted).
- Audit Log page (
/audit, auditor/admin): the hash-chained log (actor, action, resource, time, classification, justification) + a "Verify integrity" button hitting/v1/audit/verifyshowing the chain-intact result. - Provenance: in the finding/asset detail drawer, a "Provenance" section (source service, method, evidence, confidence, recorded time).
- api module
src/api/auth.ts,src/api/audit.ts; an auth store (token, user) with the fetch client attachingAuthorization. Nav entry for Audit. Match the dark/dense system.npx tsc -bclean + 2 smoke tests.
C. Ops hardening + real-run / FP harness (/home/user/paddock/hardening/ + docs)¶
- Compose hardening (edit docker-compose.yml carefully, additively): default
AUTH_MODE=enforceon the orchestrator; move secrets (DB password, NEO4J_AUTH, ADMIN_BOOTSTRAP_PASSWORD, ANTHROPIC_API_KEY) to a.envfile read by compose (ship.env.example, gitignore.env); addread_only: true+cap_drop: [ALL]+security_opt: [no-new-privileges]where services allow; ensure non-root users; add healthchecks for every service; put workers on an internal network with no inbound. Document every change. - SECURITY.md — a real threat model: trust boundaries, the scope-enforcement invariant, authz model, audit guarantees, the "detection not exploitation" posture, secret handling, the known gaps (no FIPS/FedRAMP, single-tenant, cold-start ML), and responsible-use/authorized-scope statement.
- Real-run + FP harness
hardening/realrun.py+hardening/RUNBOOK.md: a script that (1) adds an AUTHORIZED target to scope (defaultscanme.nmap.org— nmap's official legal target — and127.0.0.1), (2) runs the active worker's modules against it, (3) collects findings, (4) prints a triage table and computes a crude false-positive rate given a small hand-labeled truth set for scanme.nmap.org, (5) writes a report. It MUST refuse any target not in scope and print the authorization reminder. If the ProjectDiscovery binaries or network egress are unavailable, it degrades to a clear "could not run live — here's the exact command to run on a real deployment" message (honest, no fake results). - A
make harden-checktarget running a quick self-audit (no default creds, AUTH_MODE enforce, no secrets in compose, audit chain verifies).
Safety¶
This pass adds governance + hardening only. No offensive capability. The real-run harness only ever touches explicitly authorized scope (scanme.nmap.org / localhost) and refuses anything else, with the authorization reminder.