Files
Galena/.env.example
adminandClaude Opus 5.5 a3c2cef583 feat: the contract archive in Galena (Atrium#53 step 6)
Versioned packages per contract card (card snapshot + the modules' evidence
over GET /evidence, sha256-verified; Galena-stored items read locally at
their commit), manifest + fingerprint, append-only tables (revision 0015),
automatic archiving after document.signed / workflow.signed_on_paper with
ARCHIVE_READER_TOKEN and a "Do zarchiwizowania" retry list, manual archiving
by a moderator, retention from the live card per contract type, legal holds,
two-moderator disposal with a permanent protocol, ZIP export sealed by
Parafa, 409 archived_contract on deleting an archived project, and the
console screens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:22:56 +01:00

219 lines
14 KiB
Bash

# Copy to .env and replace every change_me_* value before starting. .env is git-ignored.
# ── Postgres ──
POSTGRES_DB=galena
POSTGRES_PASSWORD=change_me_super
DB_APP_PASSWORD=change_me_app
DB_MIGRATOR_PASSWORD=change_me_migrator
# Runtime (app role, DML-only) and migrations (migrator role, DDL). Embed the matching passwords
# above — they are duplicated here, not auto-substituted. Host stays `postgres` for Docker.
DATABASE_URL=postgresql+pg8000://app:change_me_app@postgres:5432/galena
MIGRATION_DATABASE_URL=postgresql+pg8000://migrator:change_me_migrator@postgres:5432/galena
# The runtime connection pool per backend process (at most size + overflow connections). The runtime
# role's name, DB_APP_ROLE, is left unset here: it defaults to `app`, and docker-compose.managed-db.yml
# defaults it to galena_app. It must be the role DATABASE_URL logs in as; the backend and migrate
# refuse to start otherwise.
DB_POOL_SIZE=5
DB_MAX_OVERFLOW=10
# TLS rule: a database host that is not local ("", localhost, 127.0.0.1, ::1 or `postgres`) must say
# sslmode=verify-full in its URL, or the backend and migrate refuse to start. A private database on a
# trusted network that truly needs no TLS is listed here instead (comma-separated). No other opt-out.
DB_LOCAL_HOSTS=
# ── Managed PostgreSQL (optional; replaces the local postgres service) ──
# docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d --build
# Provision Galena in the database first, then follow db/managed/README.md. Galena lives in schema
# `galena` with the roles galena_migrator and galena_app. Take the host and port from the provider's
# connection details; through a pooler use its session mode (transaction mode breaks prepared
# statements), and where the pooler wants the tenant in the user name, write <role>.<tenant>.
# Percent-encode each password in the URL, e.g.
# python -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=''))" '<password>'
# TLS is verified against the provider's root CA, mounted at /run/certs/db-ca.crt from MANAGED_DB_CA_FILE
# (leave sslrootcert out to verify against the system trust store instead). A URL for a host that is
# not local is refused without sslmode=verify-full, before anything connects.
# The Postgres block above (POSTGRES_*, DB_*_PASSWORD) is then unused.
#
# DATABASE_URL=postgresql+pg8000://galena_app.<tenant>:<percent-encoded-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
# MIGRATION_DATABASE_URL=postgresql+pg8000://galena_migrator.<tenant>:<percent-encoded-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
# DB_APP_ROLE=galena_app
# MANAGED_DB_CA_FILE=./certs/db-ca.crt
# The family's apps share the database's connection limit: each backend process holds at most
# DB_POOL_SIZE + DB_MAX_OVERFLOW connections. db/managed/README.md has the budget (5 / 10 fits a
# 90-connection limit for four apps; use 3 / 2 for a 60-connection one).
# DB_POOL_SIZE=5
# DB_MAX_OVERFLOW=10
# Opt-in only: the migrator URL for the backend itself, which enables the in-app restore (the running
# backend then holds credentials that can rewrite the audit log). Default: one-shot `python -m app.restore`.
# BACKEND_MIGRATION_DATABASE_URL=
# ── App ──
APP_ENV=production
APP_BASE_URL=http://localhost:8021
# Path prefix this deployment is mounted under. Empty = served at the origin root (this stack).
# ROOT_PATH=/galena runs Galena 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's front door forwards /galena/* 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. The console needs nothing — it derives its API base from the document.
ROOT_PATH=
# ── One platform, one account ────────────────────────────────────────────────────────────────────
# The shared identity schema. Empty (this stack) is STANDALONE: Galena owns its own accounts, has its
# own sign-in screen and its own Users administration, and the three settings below do nothing.
#
# Set IDENTITY_SCHEMA=dredd and Galena becomes a MODULE of the platform: `app_user`, `session` and
# `module_permission` live in a neutral schema the hub owns and this app READS. A person then has ONE
# account for everything, signs in once at the hub, and the cookie they got there is the cookie this
# app accepts — one origin, one cookie, and nothing to hand over. This app's sign-in form disappears
# (there is no password here), account creation and password changes answer 409 pointing at the hub,
# and app tokens stay listable and revocable but are minted there.
#
# It also turns on default-deny: `module_permission` says who may use each module (`role` = `user`)
# and who administers it (`moderator`), and having NO ROW is no access at all. So an account that the
# hub has not admitted to Galena is refused here on its first request — where before it was let in
# and shown an empty drive. Rows are written in the hub, by an administrator; this app may only read
# them, which is why it cannot admit anyone, including itself.
#
# Switching it on is NOT just this line. In order: the platform admin re-runs db/managed/provision.sql
# rendered with --identity-schema/--identity-owner (the schema, USAGE, and a search_path of
# `galena, dredd, extensions` — none of which a migrator may do); the hub's own migration creates the
# tables and grants this app's two roles their tier; then `alembic upgrade head` here runs 0007, which
# merges this schema's accounts into the shared ones by e-mail address. Read
# backend/alembic/versions/0007_shared_identity.py before you run it on anything you care about —
# it drops this app's local identity tables, and every Galena session and app token with them.
IDENTITY_SCHEMA=
# This app's slug on the platform — the module a permission row is a permission FOR. Only meaningful
# with IDENTITY_SCHEMA set, and it must match the slug the hub uses for Galena: rows are keyed by it,
# so a slug that does not match means nobody's row resolves and nobody but a platform administrator
# may open this app.
MODULE_SLUG=galena
# Where people sign in when accounts are shared: the hub's address as a browser sees it. Leave it
# EMPTY on the platform — the hub is a sibling path at the same origin (/atrium next to /galena), so
# the console works its address out from its own and there is nothing here to keep in step. Set it
# only for a hub that really is somewhere else, e.g. https://accounts.example.com/.
IDENTITY_HUB_URL=
# The session cookie's name. One account means one cookie: at the cutover every app in the family is
# set to dredd_session. The old name is still read for a while, so renaming it does not sign
# everybody out the moment the container restarts.
SESSION_COOKIE_NAME=galena_session
DATA_DIR=/data
# Optional frontend plugins root (folder of plugin subfolders). Empty = none. Plugins are
# frontend-only (the backend never runs plugin code) and may carry their own license — e.g. the
# GPL-2.0 DjVu Viewer plugin, kept out of the permissive core. Docker: mount a volume here.
PLUGINS_DIR=
SESSION_TTL_HOURS=12
# Secure session cookie. Leave UNSET (recommended) to auto-detect per request scheme: Secure over
# HTTPS, not over plain HTTP — so login persists on a LAN/HTTP host without manual tweaking. Behind
# an HTTPS terminator (X-Forwarded-Proto, trusted from FORWARDED_ALLOW_IPS) you get Secure
# automatically. Uncomment to force true/false.
# SESSION_COOKIE_SECURE=true
# App tokens — named, revocable, scoped credentials for non-browser clients (e.g. the Word/Excel
# add-in), so those clients never have to store a password. Users see and revoke them under
# Settings → Connected apps. IDLE_DAYS is an inactivity window, not a fixed expiry: every use
# slides it forward, so a token in regular use keeps working while one that is exfiltrated and
# never used expires by itself. APP_TOKENS_ENABLED=false switches the feature off — the endpoints
# then 404 and clients fall back to ordinary login sessions.
APP_TOKENS_ENABLED=true
APP_TOKEN_IDLE_DAYS=30
APP_TOKEN_MAX_IDLE_DAYS=365
# Comma-separated origins for a separately-served console in dev (empty = same-origin only).
CORS_ALLOW_ORIGINS=
# Where the ReaderJS document viewer's built code is loaded from (Galena vendors only a tiny shell).
# Empty = the pinned default (jsDelivr, an immutable ReaderJS commit). Must be immutable (full commit
# SHA / exact version). Offline or self-hosted: serve a ReaderJS `dist-embed/` build yourself and
# point this at it, e.g. /readerjs-dist/ or https://assets.example.com/readerjs/<sha>/.
# Only code is fetched; documents never leave the box.
READERJS_BASE_URL=
# First admin account (created idempotently by the seed).
BOOTSTRAP_ADMIN_EMAIL=admin@example.com
BOOTSTRAP_ADMIN_PASSWORD=change_me_admin
# ── Approval workflows: moved to the Workflow module (Atrium#53) ──
# drain (default): no new run or template change here (409 moved_to_workflow); runs already in
# progress finish as before. Then `python -m app.export_workflows --out runs.json` for Workflow's
# import. `open` restores the old engine (its own tests use it until it is removed).
# LEGACY_WORKFLOWS=drain
# The database roles trusted to say a workflow was approved (the contract card follows them).
# WORKFLOW_EVENT_ROLES=workflow_app
# ── The contract card follows other modules' events ──
# The database roles trusted to say a document was signed (Parafa) and that the other side's
# negotiation round arrived (Agora). With a role prefix, use the prefixed names.
# SIGNING_EVENT_ROLES=parafa_app
# NEGOTIATION_EVENT_ROLES=agora_app
# The role trusted to say a lawyer accepted an analysis of a document (Arbiter): the contract card
# keeps the latest accepted analysis. With a role prefix, use the prefixed name.
# ANALYSIS_EVENT_ROLES=arbiter_app
# The contract archive (Archiwum, spec 2026-11-25 part B): the modules' public base URLs for the
# evidence a package collects (empty = noted as not configured), the hub's read-only technical
# account's token for archiving after a signature and for Parafa's manifest seal (a secret; empty =
# signed cards wait on "Do zarchiwizowania"), and the card field naming the contract type.
# PARAFA_BASE_URL=
# WORKFLOW_BASE_URL=
# AGORA_BASE_URL=
# ARBITER_BASE_URL=
# ARCHIVE_READER_TOKEN=
# ARCHIVE_TYPE_FIELD=typ_umowy
# ── Encryption (optional) ──
# Base64 of 32 random bytes — wraps per-item data keys (server-managed mode). Empty disables
# encryption features. Generate one with:
# python -c "import os,base64;print(base64.b64encode(os.urandom(32)).decode())"
ENCRYPTION_MASTER_KEY=
# ── Web push (optional) ── generate VAPID keys (e.g. `npx web-push generate-vapid-keys`).
VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
VAPID_SUBJECT=mailto:admin@example.com
# ── Email (optional) ── SMTP for email notifications. Empty host disables the email channel.
SMTP_HOST=
SMTP_PORT=587
SMTP_USER=
SMTP_PASSWORD=
SMTP_FROM=galena@example.com
SMTP_STARTTLS=true
# ── Backups (optional) ── Auto-backup is OFF by default and configured in Administration → Backups
# (enable, interval, retention, storage target). Local-disk backups live under DATA_DIR/backups and
# need nothing here. For the S3 target, set the bucket below and provide standard AWS credentials in
# the environment (AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY) plus the optional `boto3` dependency.
# Restore uses MIGRATION_DATABASE_URL (the migrator role) because it rewrites every table.
BACKUP_S3_BUCKET=
BACKUP_S3_PREFIX=galena-backups/
BACKUP_S3_REGION=
# S3-compatible endpoint (MinIO, Cloudflare R2, …); leave empty for AWS S3.
BACKUP_S3_ENDPOINT=
# ── Edge ── the backend is published directly on :8021 (the family's port for Galena); there is no reverse proxy in this stack.
# The proxy allowed to set X-Forwarded-For/-Proto. Empty = loopback only (nothing in front). Behind
# your own TLS terminator set its address or subnet — never `*`.
FORWARDED_ALLOW_IPS=
# Who may frame the console and the API: 'none' (default; X-Frame-Options DENY) or 'self'
# (SAMEORIGIN). Anything else refuses start-up. The ReaderJS viewer is always framable by 'self'.
# (Replaces GALENA_FRAME_ANCESTORS, whose origin list is no longer supported; setting it refuses start-up.)
FRAME_ANCESTORS='none'
# Public address used in the link-unfurl preview (Open Graph / Twitter) when you share the app's URL
# in WhatsApp/Slack/iMessage/etc. — e.g. GALENA_PUBLIC_URL=https://galena.example.com (NO trailing
# slash). Leave empty to derive it from the request scheme+host (correct for the usual single-domain
# deploy); set it explicitly if Galena sits behind another proxy or a CDN.
# With ROOT_PATH set, this MUST carry the prefix too (https://host/galena): the derived base already
# includes ROOT_PATH, but an explicit value is not rewritten.
GALENA_PUBLIC_URL=
# ── Observability (opt-in) ──
OTEL_ENABLED=false
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
# Scope the session cookie to a parent domain, so a sibling app on the same parent (e.g. Sygna
# at sygna.firma.pl beside galena.firma.pl) is authenticated inside an embedded frame. Empty =
# host-only, which is the tighter default and correct for a standalone deployment.
# Set ONLY a domain you control end to end: every host under it can read the session cookie.
# On the platform leave it EMPTY: one origin, one module per path, so the host-only cookie already
# reaches every module and a Domain attribute would only widen it beyond the platform.
SESSION_COOKIE_DOMAIN=