Docs
Deployment
Hosted backend deployment (GovAI Audit Service)
This repo includes a Rust HTTP service (aigov_audit) that provides the audit ledger endpoints used by the Python terminal SDK and (optionally) the dashboard.
Goal for “hosted mode”: customers call your hosted URL and do not run Rust or Postgres locally.
HTTP startup and operational probes#
GovAI requires a reachable Postgres database (and valid DB configuration) before the HTTP listener binds. If Postgres is unavailable or misconfigured at startup, the process exits (fail-fast) instead of accepting traffic — operators should treat that as service startup failure, not as a “live but not ready” HTTP tier.
After successful startup:
GET /healthis liveness-only: the handler does not query Postgres, but/healthis only reachable once startup has succeeded. Do not interpret/healthas “the audit service is alive and useful while Postgres is down.”GET /readyis the authoritative operational readiness endpoint. Use/readyin CI, load balancers, and operator checks for Postgres + migrations + ledger writability. Responses may includeruntime_governance_enforcementdiagnostics (informational; readiness 200 is not gated on enforceability—see OpenAPI description for/ready).
Stripe: When billing is enabled, ensure ingress can reach POST /stripe/webhook (unauthenticated Stripe-signed path) and the gated /billing/* routes per billing.md and api/govai-http-v1.openapi.yaml.
Hosted deployment checklist (exact)#
Hosted deployment checklist
Operator steps for a production audit endpoint.
-
Build artifact
- Build the Rust service (
aigov_audit) into a container or host-native binary. - Ensure the runtime exposes an HTTP port and supports long-running processes.
- Build the Rust service (
-
Networking
- Public HTTPS URL provisioned (this is your audit base URL).
- Ingress routes allowed for:
-
POST /evidence -
GET /compliance-summary -
GET /bundle-hash(returnsbundle_sha256andevents_content_sha256for artefact-bound CI gates — schemaaigov.evidence_digest.v1) -
GET /api/export/:run_id(optional cross-check fromverify-evidence-pack:evidence_hashes.events_content_sha256) -
GET /status -
GET /usage
-
- Liveness probe:
GET /health(cheap liveness after successful startup; the handler does not query Postgres, but HTTP is not bound until DB-backed startup succeeds — see “HTTP startup and operational probes”). - Readiness probe (recommended behind a load balancer):
GET /ready— returns 503 unless Postgres responds,_sqlx_migrationsshows the expected number of successful applies, and the ledger directory is writable (see below).
-
Database (managed Postgres)
- Provision a Postgres database (managed).
- Run migrations / schema bootstrap as required by this repo’s SQLx usage (see “Verification commands” below).
- Set DB connection env var (see “Required env vars”).
-
Auth / API keys
- Set
GOVAI_API_KEYS(recommended for hosted mode). Without it, the audit endpoints are unauthenticated (legacy local behavior). - Hosted staging/prod MUST define
GOVAI_API_KEYS_JSON(JSON mapapi_key → tenant_id). Dev mode without API keys is not suitable for pilots. - Distribute one API key to each customer.
- Set
-
Base URL config
- Set
GOVAI_BASE_URLsoGET /statusreports the canonical public URL.
- Set
-
Smoke test
-
GET /statusreturnsok: true. -
POST /evidenceworks with a valid API key. -
GET /compliance-summary?run_id=...returns a verdict. -
GET /usagereturns usage for the same API key.
-
Required environment variables (hosted mode)#
Always required#
GOVAI_DATABASE_URL(preferred) orDATABASE_URL- Postgres connection string for the hosted service.
- If neither is set, the service fails fast on startup with an explicit error.
Required in staging / production (durable audit evidence)#
GOVAI_LEDGER_DIR- Example:
GOVAI_LEDGER_DIR=/var/lib/govai/ledger - This directory must be backed by persistent storage (durable volume / durable disk).
- The service will fail startup in staging/prod if this is missing, not creatable, or not writable.
- Warning: ephemeral container filesystems are unsafe for audit evidence; do not rely on the process working directory.
- Example:
Strongly recommended for hosted mode#
-
GOVAI_API_KEYS- Comma-separated bearer secrets.
- Format:
key1,key2orkey1:1000,key2:5000(per-key request caps). - If unset/empty, auth for
POST /evidence,GET /compliance-summary,GET /usageis disabled (local-friendly default).
-
GOVAI_BASE_URL- Canonical public base URL (e.g.
https://audit.govbase.dev). - Returned by
GET /statusasbase_urlfor ops/debugging.
- Canonical public base URL (e.g.
Optional (only if you use these features)#
-
AIGOV_BIND- Bind address for the server (default locally:
127.0.0.1:8088). - On Railway, Heroku-style platforms,
PORT, or other dynamic ports: useAIGOV_BIND="0.0.0.0:$PORT"(shell must expand$PORT; a plainENTRYPOINTwithout a shell often does not expand it — usesh -c '…'). - Do not assume a fixed 8088 on hosted platforms;
PORTmust come from the platform when applicable.
- Bind address for the server (default locally:
-
GOVAI_METERINGonenables team-scoped metering enforced onPOST /evidence.- When
GOVAI_METERING=on,GOVAI_API_KEYSmust be non-empty (service fails fast otherwise).
-
GOVAI_DEFAULT_PLANfree|team|growth|enterprise(used when metering is on; defaultfree).
-
GOVAI_API_USAGE_STOREmemory(default) orpostgres(persist per-key request counts).
-
Policy config
AIGOV_POLICY_FILE: explicit policy file path (JSON).AIGOV_POLICY_DIR: search dir forpolicy.<env>.jsonorpolicy.json.AIGOV_APPROVER_ALLOWLIST: CSV override for approver identities (when allowlist enforcement is enabled).
-
Supabase auth (only for dashboard-oriented endpoints under
/api/*)SUPABASE_URL(required for/api/me, assessments, workflow endpoints when they are used)SUPABASE_JWT_AUD(optional audience check)
Hosted-mode configuration path (for customers)#
Customers only need:
- Audit base URL: your hosted URL (example
https://audit.govbase.dev) - API key: one bearer token from you
In the Python terminal SDK, they configure:
- Base URL:
GOVAI_AUDIT_BASE_URL(or the CLI config file written bygovai init) - API key:
GOVAI_API_KEY
Endpoints (hosted service contract)#
POST /evidence: append one evidence event (requires bearer token whenGOVAI_API_KEYSis set)GET /compliance-summary?run_id=<id>: compute compliance verdict + missing evidence (requires bearer token whenGOVAI_API_KEYSis set)GET /status: lightweight JSON status (ok,policy_version,environment, optionalbase_url,runtime_governance_enforcementdiagnostics — Phase 3 env snapshot;enforceableis not a readiness indicator)GET /usage: usage counters (requires bearer token whenGOVAI_API_KEYSis set)GET /health: liveness — returnsok: truewithout querying Postgres or the ledger in that request, but only after startup has bound HTTP (Postgres must already have been reachable for startup). It does not substitute/readyfor DB, migrations, or disk checks.GET /ready: readiness — verifies Postgres, applied migrations marker, ledger writability, and tenant-scoped ledger probe. Success payloads includeruntime_governance_enforcement(GOVAI_RUNTIME_GOVERNANCE_ENFORCEMENT,GOVAI_RUNTIME_GOVERNANCE_ENFORCEMENT_TENANTSsnapshot): informational only (503readiness failures follow infra checks;enforceable=falsealone does not change HTTP status codes here).
Railway — production-shaped start command#
Use the aigov_audit binary (repo build output: ./aigov_audit). Typical Railway Start Command:
Mount GOVAI_LEDGER_DIR to a Railway volume or other durable filesystem. Do not use /tmp or any ephemeral-only path for real audit tiers: AIGOV_ENVIRONMENT=staging / prod requires a persistent ledger directory. Losing or wiping GOVAI_LEDGER_DIR invalidates append-only audit continuity guarantees.
Set at least:
GOVAI_DATABASE_URL(orDATABASE_URL) — managed Postgres URL.GOVAI_API_KEYS— comma-separated bearer secrets (must align with tenant mapping whenGOVAI_API_KEYS_JSONis used).GOVAI_API_KEYS_JSON— staging/production expect a JSON map ofapi_key → tenant_id(see Rustaudit_api_keymodule): required for isolated hosted tenants onAIGOV_ENVIRONMENT=staging/prod.GOVAI_BASE_URL— set tohttps://audit.govbase.devsoGET /statusreports the canonical public URL.AIGOV_ENVIRONMENT— useprodfor the production hosted tier (determines startup strictness).AIGOV_BIND— bind to a public interface for hosted. For Railway you typically want0.0.0.0:$PORT; if your platform uses a fixed port, use0.0.0.0:8080.GOVAI_AUTO_MIGRATE—truein simple Railway setups, or run SQLx migrations as a separate release step.PORT— provided by Railway; do not hardcode 8088 for this platform.
Local and Docker Compose examples may still use 127.0.0.1:8088 or 0.0.0.0:8088 explicitly; hosted examples should always follow the platform’s PORT.
Verification commands#
Run locally against hosted settings (bind to all interfaces)#
Health / status#
Evidence append (requires API key when enabled)#
Compliance summary#
Usage#
Operator-hosted quickstart (Docker Compose)#
This is a minimal operator-hosted path for running the GovAI Rust audit service plus Postgres on a single machine using Docker Compose. It is intended for evaluation, internal environments, and “boring” first deployments.
Non-goals (this quickstart does not claim):
- high availability / multi-region
- zero-downtime deploys
- secret management beyond environment variables
- backups/restore automation (you must configure this yourself)
Start#
From the repo root:
The service listens on http://127.0.0.1:8088.
Migrations#
In this Compose setup, migrations run automatically on startup because it sets:
GOVAI_AUTO_MIGRATE=true
Outside Compose, migrations are off by default.
- For local demos and controlled pilots,
GOVAI_AUTO_MIGRATE=trueis acceptable: it keeps startup simple while you validate the system end-to-end. - For production-like deployments, prefer an explicit migration step in your release process and run the service with
GOVAI_AUTO_MIGRATEdisabled (unset or explicitly set to false) so schema changes are applied intentionally and observably. - Auto-migrate remains supported for production-like environments if the operator intentionally opts into it (set
GOVAI_AUTO_MIGRATE=true), with the expectation that startup can fail fast if migrations cannot be applied.
Smoke tests#
Operator env vars (recommended)#
Edit docker-compose.yml and set:
GOVAI_API_KEYS(otherwise core audit endpoints are unauthenticated)GOVAI_BASE_URL(shown inGET /status)
CI and protected branches (downstream repositories)#
- Require
.github/workflows/compliance.ymland the artefact-bound hosted job (govai-compliance-gate:submit-evidence-pack+verify-evidence-pack) for merges that must mean “CI evidence was posted to the hosted ledger and evaluated VALID”. See github-action.md. - Do not treat
.github/workflows/govai-smoke.yml(manual synthetic smoke) orgovai checkalone as a production compliance gate. - In automation (CI wait loops, load balancers), use
GET /readyfor readiness;GET /statusandGET /healthare not substitutes for database, migrations, and ledger writability.
Notes / pending#
GET /usageis implemented already.- Staging/production deployments fail fast today when
GOVAI_API_KEYS_JSONis unset/invalid (tenant isolation), when loopback binds slip through (AIGOV_ENVIRONMENT=staging/prod), when migrations are incomplete withoutGOVAI_AUTO_MIGRATE, or whenGOVAI_LEDGER_DIRis not durable — see server startup logs andGET /readyfor live dependency status.