The platform is dropping Caddy: Atrium's backend becomes the front door and
forwards /counsel/* with the prefix stripped, so Counsel must answer for
everything Caddy did for it.
- app/edge.py: SecurityHeaders (pure ASGI, so every response is stamped,
404/405/413/500 included) with Caddy's exact set: nosniff, no-referrer,
the same CSP with frame-ancestors from FRAME_ANCESTORS, X-Frame-Options
DENY or SAMEORIGIN to match, HSTS only over https. BodySizeLimit caps a
request at 100 MB, by Content-Length and while reading a chunked body.
SpaStaticFiles is try_files {path} /index.html. ConsoleUnlessApi keeps
/api and /healthz from ever falling to the console (405 with Allow, or
404), comparing route paths, never the prefixed URL.
- FRAME_ANCESTORS: 'none' (default, unframable) or 'self' (Atrium's frame);
anything else refuses to start.
- GET/HEAD /healthz answers 200 without the database; GZipMiddleware.
- Dockerfile: the frontend comes in as a named build context; uvicorn runs
with --proxy-headers, --forwarded-allow-ips and --no-server-header.
- Standalone compose: no Caddy, the backend is published on :80; TLS is
the operator's own terminator in front. Caddyfile deleted.
- README, CLAUDE.md, SECURITY.md and .env.example follow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
148 lines
11 KiB
Bash
148 lines
11 KiB
Bash
# Copy to .env and replace every "change_me_*" value before running.
|
|
# .env is git-ignored. For the local postgres keep passwords alphanumeric (the DB init
|
|
# scripts interpolate them into SQL literals).
|
|
|
|
# ─── PostgreSQL ──────────────────────────────────────────────────────────────
|
|
POSTGRES_DB=scoring
|
|
DB_SUPERUSER_PASSWORD=change_me_super
|
|
DB_APP_PASSWORD=change_me_app
|
|
DB_MIGRATOR_PASSWORD=change_me_migrator
|
|
|
|
# Runtime (least-privilege "app" role: DML only) and migrations ("migrator": DDL).
|
|
# Inside docker the host is "postgres"; for a local run use "localhost".
|
|
DATABASE_URL=postgresql+pg8000://app:change_me_app@postgres:5432/scoring
|
|
MIGRATION_DATABASE_URL=postgresql+pg8000://migrator:change_me_migrator@postgres:5432/scoring
|
|
# The runtime role's name (the user in DATABASE_URL); the runtime-grants migration grants to it.
|
|
DB_APP_ROLE=app
|
|
# The backend's connection pool: at most DB_POOL_SIZE + DB_MAX_OVERFLOW connections per process.
|
|
DB_POOL_SIZE=5
|
|
DB_MAX_OVERFLOW=10
|
|
# The family's one TLS rule: a database host that is not local ("", localhost, 127.0.0.1, ::1 or the
|
|
# compose service "postgres") must carry sslmode=verify-full in its URL, or migrate and the backend
|
|
# refuse to start. DB_LOCAL_HOSTS (comma-separated, optional) adds hosts that need no TLS: a private
|
|
# database on a network you trust. DB_ALLOW_UNVERIFIED_TLS=true is the one escape hatch that lifts the
|
|
# rule for both URLs; never on a managed provider.
|
|
DB_LOCAL_HOSTS=
|
|
#DB_ALLOW_UNVERIFIED_TLS=false
|
|
|
|
# ─── PostgreSQL at a managed provider (the family's shared database; instead of the local postgres) ───
|
|
# Runbook: db/managed/README.md (its step 0 has the project-wide steps; the family runbook is Atrium's
|
|
# deploy/README.md). All four apps share ONE database; Counsel lives in schema counsel, as roles
|
|
# counsel_migrator and counsel_app. Provision Counsel once, then replace the URL / role / pool settings
|
|
# above with these, delete the three DB_*_PASSWORD lines (unused there), and start with BOTH compose files:
|
|
# DREDD_CORE_TOKEN=github_pat_... docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d --build
|
|
# - Host and port: from the provider's connection details. Through a pooler, use its SESSION mode
|
|
# (never transaction mode: no prepared statements). A provider's direct connection may be IPv6-only;
|
|
# from this compose stack (IPv4-only networks) that needs the provider's IPv4 option, or Docker IPv6
|
|
# (daemon ip6tables + enable_ipv6 and an IPv6 subnet on `internal` and `edge`); otherwise use the pooler.
|
|
# - User: <role>.<tenant> where the pooler wants the tenant in the user name, plain <role> otherwise.
|
|
# Never the platform admin (postgres). DB_APP_ROLE must be the DATABASE_URL user before .<tenant>, and
|
|
# the two URLs must log in as different users: start-up refuses anything else.
|
|
# - TLS: sslmode=verify-full against the provider's root CA (downloaded from its dashboard), which the
|
|
# override mounts at /run/certs/db-ca.crt from MANAGED_DB_CA_FILE; leave sslrootcert out when the
|
|
# server's certificate chains to a public CA (the system trust store is used). sslmode=prefer/allow/
|
|
# disable are refused, and so is a remote URL without sslmode=verify-full (DB_ALLOW_UNVERIFIED_TLS=true
|
|
# lifts that for a trusted private network: never here).
|
|
# - Passwords: the ones given at provisioning (16+ characters, different per role); in the URL
|
|
# percent-encode every character outside A-Z a-z 0-9 - . _ ~ (e.g. @ -> %40, % -> %25, $ -> %24).
|
|
# - Pool: keep the four apps' sum of (DB_POOL_SIZE + DB_MAX_OVERFLOW + 1) within ~80% of the database's
|
|
# connection limit. Limit 90: the defaults above fit (4 x 16 = 64 <= 72). Limit 60: set DB_POOL_SIZE=3
|
|
# and DB_MAX_OVERFLOW=2 in EVERY app (4 x 6 = 24). Through a pooler in session mode, its per-role pool
|
|
# size must be at least DB_POOL_SIZE + DB_MAX_OVERFLOW + 1 (16 with the defaults).
|
|
# MANAGED_DB_CA_FILE=./certs/db-ca.crt
|
|
# DATABASE_URL=postgresql+pg8000://counsel_app.<tenant>:<counsel-app-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
|
# MIGRATION_DATABASE_URL=postgresql+pg8000://counsel_migrator.<tenant>:<counsel-migrator-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
|
# DB_APP_ROLE=counsel_app
|
|
# DB_POOL_SIZE=5
|
|
# DB_MAX_OVERFLOW=10
|
|
|
|
# ─── Application ─────────────────────────────────────────────────────────────
|
|
APP_ENV=production
|
|
# Path prefix this deployment is mounted under. Empty = served at the origin root (this stack).
|
|
# ROOT_PATH=/counsel runs Counsel as a module of the platform (one origin, one module per path:
|
|
# /atrium, /galena, /sygna, /counsel). It is HALF of one decision: the proxy must STRIP the prefix
|
|
# (Atrium forwards `/counsel/*` without it) and this backend re-adds it via uvicorn --root-path. Set only one
|
|
# of the two and you get a doubled prefix (404s everywhere) or server-generated URLs that escape the
|
|
# prefix. No trailing slash. The console needs nothing — it derives its API base from the document.
|
|
ROOT_PATH=
|
|
# Which upstream IPs uvicorn trusts for X-Forwarded-For / X-Forwarded-Proto, so the real client IP
|
|
# lands in the audit INET columns. Empty = loopback only (the image's default), right for this stack,
|
|
# where nothing sits in front of the backend. Behind your own TLS terminator, set its address or
|
|
# subnet; never `*`. docker-compose.yml sets it empty, overriding this line.
|
|
FORWARDED_ALLOW_IPS=
|
|
# Who may frame Counsel: 'none' (default; X-Frame-Options DENY) or 'self' (SAMEORIGIN). Anything else
|
|
# refuses start-up.
|
|
FRAME_ANCESTORS='none'
|
|
# Leave empty in production (the console is served same-origin by the backend).
|
|
# For local dev where you open the page from another origin, list it here, e.g.:
|
|
# CORS_ALLOW_ORIGINS=http://localhost:5500,http://127.0.0.1:5500
|
|
CORS_ALLOW_ORIGINS=
|
|
|
|
# ─── One platform, one account ───────────────────────────────────────────────
|
|
# Empty (this line as it stands) = STANDALONE: Counsel owns its accounts, serves its own sign-in,
|
|
# and BOOTSTRAP_ADMIN_* below is its first administrator. That is the default and stays supported.
|
|
#
|
|
# IDENTITY_SCHEMA=dredd makes this a MODULE of the platform: app_user, session and the moderator
|
|
# table live in a neutral schema the hub owns and every module reads, so a person has ONE account
|
|
# and signs in once, at /atrium. Nothing is handed over — one origin means the same cookie reaches
|
|
# every module and this app resolves the same session row — so there is nothing else to configure:
|
|
# no assertion, no audience binding, no second password. What it changes here: no sign-in (the
|
|
# console offers the hub instead), no account writes (they are the hub's), and app tokens are minted
|
|
# in the hub while still being listed and revoked here.
|
|
#
|
|
# It is half of one change. The other half is db/managed/provision.sql, re-rendered with
|
|
# --identity-schema / --identity-owner and run by the platform admin: a migrator holds no CREATE on
|
|
# the database and cannot ALTER ROLE another role's search_path. Set this only after that has run
|
|
# and the hub's own migration has created the tables — otherwise `migrate` refuses, by name.
|
|
IDENTITY_SCHEMA=
|
|
# The session cookie's name. On the platform every module is set to the same one; that, plus one
|
|
# origin, IS the single sign-on. The old name keeps being read for one more request, so renaming it
|
|
# signs nobody out mid-change. Set it TOGETHER with IDENTITY_SCHEMA: the backend refuses to start
|
|
# with only one of the two (a schema without the hub's cookie is a dead module; the hub's cookie
|
|
# without the schema overwrites the platform session and signs everybody out of Atrium).
|
|
#SESSION_COOKIE_NAME=dredd_session
|
|
# This module's name ON THE PLATFORM — the one string the hub and this module have to agree on by
|
|
# hand. It is what a grant of access names (`module_permission.module_slug`), what the hub's module
|
|
# catalogue calls this app, and what the hub stamps a token it mints for this app with
|
|
# (`<slug>_pat_`). Written out rather than left to the default, unlike the two lines above, because
|
|
# a mismatch here is SILENT in both directions: this module only ever SELECTs `module_permission`
|
|
# WHERE module_slug = its own name, so a grant written against a different spelling simply never
|
|
# matches — the administrator sees a successful delegation and the person is refused at the door,
|
|
# with nothing anywhere raising an error to say why. An absent key that "obviously defaults right" is exactly the kind of
|
|
# thing nobody checks against the catalogue; a present one can be read off both sides in a second.
|
|
# It is `counsel` — the same word as the schema, both role names, the URL path and the cookie, and
|
|
# never `scorecard` or `counsel-scorecard`. Change it only if the module is renamed in every one of
|
|
# those places AND in the hub's catalogue, in the same change.
|
|
MODULE_SLUG=counsel
|
|
|
|
SESSION_TTL_HOURS=12
|
|
# Session cookie Secure flag. Unset (this line commented out) → AUTO: Secure only when the request
|
|
# actually arrived over HTTPS, which is right on both a TLS front door and a plain-HTTP LAN or
|
|
# platform deployment — a Secure cookie over http:// is dropped by the browser and the user is signed
|
|
# straight back out. Set true/false to force it. Never leave it assigned but EMPTY
|
|
# (SESSION_COOKIE_SECURE= with nothing after it): that is coerced back to auto rather than crashing
|
|
# start-up, but it reads as a decision nobody made.
|
|
#SESSION_COOKIE_SECURE=false
|
|
BASE_CURRENCY=EUR
|
|
# App-level brute-force lockout.
|
|
LOGIN_MAX_ATTEMPTS=5
|
|
LOGIN_LOCKOUT_MINUTES=15
|
|
|
|
# The first administrator, created idempotently by the seed step. STANDALONE ONLY: with
|
|
# IDENTITY_SCHEMA set, the account lives in the hub and the seed neither creates nor could create it
|
|
# (a module holds no INSERT on the shared app_user); it just says so and carries on.
|
|
BOOTSTRAP_ADMIN_EMAIL=admin@example.com
|
|
BOOTSTRAP_ADMIN_PASSWORD=change_me_admin
|
|
|
|
# ─── OpenTelemetry (backend → OTel Collector) ────────────────────────────────
|
|
# Leave disabled to run the backend alone. Set true to export OTLP traces/metrics/logs to a
|
|
# collector you run at OTEL_EXPORTER_OTLP_ENDPOINT (config in observability/otel-collector-config.yaml).
|
|
OTEL_ENABLED=false
|
|
OTEL_SERVICE_NAME=counsel-scorecard-backend
|
|
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
|
|
|
# ─── ClickHouse (observability store, used by OTel Collector + HyperDX) ───────
|
|
CLICKHOUSE_USER=otel
|
|
CLICKHOUSE_PASSWORD=change_me_clickhouse
|
|
CLICKHOUSE_DB=otel
|