chore: rename the skeleton from Parafa to Workflow
Slug, schema, roles (workflow_app / workflow_migrator), session cookie, token prefix workflow_pat_, WORKFLOW_* env vars (WORKFLOW_RUN_INTEGRATION, WORKFLOW_FRONTEND_DIR, WORKFLOW_PORT), UI name, ROOT_PATH examples. - Standalone port 8141: the family's ports step by 20 (8021..8121), Scribe holds 8125, 8141 is unused by every sibling compose file. - dredd-core pinned at v0.24.0. - db/managed/provision.sql re-rendered with the plan's B1 command, which adds --extension pgcrypto; CI's --check-file and provision steps and the managed runbook pass the same flag so the live path matches the file. - CREDITS: one "skeleton from Parafa" entry; pyHanko-era rows removed. - README domain section is a stub until the console and API exist (7.5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ad0c7ad81b
commit
a10b0d5be7
+18
-18
@@ -1,5 +1,5 @@
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Parafa — copy to .env and edit. On Windows write it WITHOUT a BOM:
|
||||
# Workflow — copy to .env and edit. On Windows write it WITHOUT a BOM:
|
||||
# [System.IO.File]::WriteAllText("$PWD\.env", (Get-Content .env.example -Raw))
|
||||
# (PowerShell's Out-File -Encoding utf8 adds a BOM, which pydantic-settings then
|
||||
# folds into the first key name and you get a baffling "field required" error.)
|
||||
@@ -10,8 +10,8 @@
|
||||
APP_ENV=production
|
||||
APP_BASE_URL=http://localhost
|
||||
# Path prefix this deployment is mounted under. Empty = served at the origin root (this stack).
|
||||
# ROOT_PATH=/parafa runs it as a module of a platform (one origin, one module per path). It is
|
||||
# HALF of one decision: the front door must STRIP the prefix (Atrium forwards `/parafa/*` without it) and
|
||||
# ROOT_PATH=/workflow runs it as a module of a platform (one origin, one module per path). It is
|
||||
# HALF of one decision: the front door must STRIP the prefix (Atrium forwards `/workflow/*` 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 it. The console needs nothing — it
|
||||
# derives its API base from the document.
|
||||
@@ -19,13 +19,13 @@ ROOT_PATH=
|
||||
|
||||
# ── Database ─────────────────────────────────────────────────────────────────
|
||||
# Runtime uses the least-privilege `app` role; Alembic uses `migrator`.
|
||||
POSTGRES_DB=parafa
|
||||
POSTGRES_DB=workflow
|
||||
POSTGRES_PASSWORD=change_me_super
|
||||
DB_APP_PASSWORD=change_me_app
|
||||
DB_MIGRATOR_PASSWORD=change_me_migrator
|
||||
|
||||
DATABASE_URL=postgresql+pg8000://app:change_me_app@postgres:5432/parafa
|
||||
MIGRATION_DATABASE_URL=postgresql+pg8000://migrator:change_me_migrator@postgres:5432/parafa
|
||||
DATABASE_URL=postgresql+pg8000://app:change_me_app@postgres:5432/workflow
|
||||
MIGRATION_DATABASE_URL=postgresql+pg8000://migrator:change_me_migrator@postgres:5432/workflow
|
||||
# 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.
|
||||
@@ -38,8 +38,8 @@ DB_MAX_OVERFLOW=10
|
||||
DB_LOCAL_HOSTS=
|
||||
|
||||
# ── Managed PostgreSQL (the family's shared database; replaces the local postgres) ──
|
||||
# Runbook: db/managed/README.md. Every app of the family shares ONE managed database; Parafa
|
||||
# lives in schema parafa, as roles parafa_migrator and parafa_app. Provision it
|
||||
# Runbook: db/managed/README.md. Every app of the family shares ONE managed database; Workflow
|
||||
# lives in schema workflow, as roles workflow_migrator and workflow_app. Provision it
|
||||
# once, then replace the Database settings above with these, delete the POSTGRES_PASSWORD and
|
||||
# DB_*_PASSWORD lines (unused there), and start with BOTH compose files:
|
||||
# docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d --build
|
||||
@@ -63,9 +63,9 @@ DB_LOCAL_HOSTS=
|
||||
# session mode, its own pool size must be at least DB_POOL_SIZE + DB_MAX_OVERFLOW + 1.
|
||||
# DB_POOL_SIZE >= 1 and DB_MAX_OVERFLOW >= 0 (0 / -1 would mean no limit, so they are refused).
|
||||
# MANAGED_DB_CA_FILE=./certs/db-ca.crt
|
||||
# DATABASE_URL=postgresql+pg8000://parafa_app.<tenant>:<app-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
# MIGRATION_DATABASE_URL=postgresql+pg8000://parafa_migrator.<tenant>:<migrator-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
# DB_APP_ROLE=parafa_app
|
||||
# DATABASE_URL=postgresql+pg8000://workflow_app.<tenant>:<app-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
# MIGRATION_DATABASE_URL=postgresql+pg8000://workflow_migrator.<tenant>:<migrator-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
# DB_APP_ROLE=workflow_app
|
||||
# DB_POOL_SIZE=4
|
||||
# DB_MAX_OVERFLOW=8
|
||||
|
||||
@@ -78,7 +78,7 @@ DATA_DIR=/data
|
||||
GALENA_BASE_URL=
|
||||
|
||||
# ── One platform, one account ────────────────────────────────────────────────
|
||||
# The shared identity schema. Empty — this stack — is STANDALONE: Parafa owns its own
|
||||
# The shared identity schema. Empty — this stack — is STANDALONE: Workflow owns its own
|
||||
# accounts, has its own sign-in screen and its own Users administration, and the three settings
|
||||
# below do nothing. That is a supported deployment for ever, not a stage to grow out of.
|
||||
#
|
||||
@@ -97,7 +97,7 @@ GALENA_BASE_URL=
|
||||
#
|
||||
# Switching it on is NOT just this line. In order: the platform admin re-renders
|
||||
# db/managed/provision.sql with --identity-schema / --identity-owner and runs it (the schema, USAGE
|
||||
# and a search_path of `parafa, dredd, extensions` — none of which a migrator may
|
||||
# and a search_path of `workflow, 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 0003, which merges this schema's accounts into the shared ones by
|
||||
# e-mail address. Read backend/alembic/versions/0003_shared_identity.py before running it on
|
||||
@@ -107,10 +107,10 @@ IDENTITY_SCHEMA=
|
||||
# This app's slug on the platform — the module a permission row admits somebody to. Only meaningful
|
||||
# with IDENTITY_SCHEMA set, and it must match the slug the hub uses for this app, or nobody's row
|
||||
# resolves and nobody but a platform administrator can open it. Note it is NOT always the same
|
||||
# string as the Postgres schema (`parafa`): a module slug is a URL path segment, so the hub's
|
||||
# string as the Postgres schema (`workflow`): a module slug is a URL path segment, so the hub's
|
||||
# module_permission table allows hyphens and refuses underscores, while a schema name is the other
|
||||
# way round. The scaffolder derived this one from that one; change both or neither.
|
||||
MODULE_SLUG=parafa
|
||||
MODULE_SLUG=workflow
|
||||
# Where people sign in when accounts are shared: the hub's address as a browser sees it, e.g.
|
||||
# /atrium/. Empty is allowed — the console then says accounts live elsewhere without offering a
|
||||
# link that goes nowhere.
|
||||
@@ -118,7 +118,7 @@ IDENTITY_HUB_URL=
|
||||
# The session cookie's name. One account means one cookie: at a 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=parafa_session
|
||||
SESSION_COOKIE_NAME=workflow_session
|
||||
|
||||
# ── Auth / sessions ──────────────────────────────────────────────────────────
|
||||
SESSION_TTL_HOURS=12
|
||||
@@ -132,7 +132,7 @@ SESSION_COOKIE_SECURE=
|
||||
# separately-served console in dev.
|
||||
CORS_ALLOW_ORIGINS=
|
||||
|
||||
# Who may frame Parafa: 'none' (default; X-Frame-Options DENY) or 'self' (SAMEORIGIN, what the
|
||||
# Who may frame Workflow: 'none' (default; X-Frame-Options DENY) or 'self' (SAMEORIGIN, what the
|
||||
# platform's kit sets). Anything else refuses start-up.
|
||||
FRAME_ANCESTORS='none'
|
||||
|
||||
@@ -159,5 +159,5 @@ FORWARDED_ALLOW_IPS=127.0.0.1
|
||||
|
||||
# ── OpenTelemetry (opt-in) ───────────────────────────────────────────────────
|
||||
OTEL_ENABLED=false
|
||||
OTEL_SERVICE_NAME=parafa-backend
|
||||
OTEL_SERVICE_NAME=workflow-backend
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
||||
|
||||
+38
-38
@@ -13,20 +13,20 @@ jobs:
|
||||
postgres:
|
||||
image: postgres:${{ matrix.postgres }}
|
||||
env:
|
||||
POSTGRES_DB: parafa
|
||||
POSTGRES_DB: workflow
|
||||
POSTGRES_PASSWORD: superpw
|
||||
ports: ["5432:5432"]
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U postgres" --health-interval 5s
|
||||
--health-timeout 5s --health-retries 20
|
||||
env:
|
||||
DATABASE_URL: postgresql+pg8000://app:apppw@localhost:5432/parafa
|
||||
MIGRATION_DATABASE_URL: postgresql+pg8000://migrator:migpw@localhost:5432/parafa
|
||||
DATA_DIR: ${{ github.workspace }}/parafa-data
|
||||
DATABASE_URL: postgresql+pg8000://app:apppw@localhost:5432/workflow
|
||||
MIGRATION_DATABASE_URL: postgresql+pg8000://migrator:migpw@localhost:5432/workflow
|
||||
DATA_DIR: ${{ github.workspace }}/workflow-data
|
||||
BOOTSTRAP_ADMIN_EMAIL: admin@example.com
|
||||
BOOTSTRAP_ADMIN_PASSWORD: adminpass1
|
||||
SEED_DEMO: "true"
|
||||
PARAFA_RUN_INTEGRATION: "1"
|
||||
WORKFLOW_RUN_INTEGRATION: "1"
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-python@v6
|
||||
@@ -35,10 +35,10 @@ jobs:
|
||||
# The suite then runs as the DML-only `app` role, which is the only way the grants get
|
||||
# tested at all — a suite run as the superuser proves nothing about least privilege.
|
||||
run: |
|
||||
PGPASSWORD=superpw psql -h localhost -U postgres -d parafa -v ON_ERROR_STOP=1 <<'SQL'
|
||||
PGPASSWORD=superpw psql -h localhost -U postgres -d workflow -v ON_ERROR_STOP=1 <<'SQL'
|
||||
CREATE ROLE migrator LOGIN PASSWORD 'migpw';
|
||||
CREATE ROLE app LOGIN PASSWORD 'apppw';
|
||||
GRANT CONNECT ON DATABASE parafa TO migrator, app;
|
||||
GRANT CONNECT ON DATABASE workflow TO migrator, app;
|
||||
ALTER SCHEMA public OWNER TO migrator;
|
||||
GRANT USAGE ON SCHEMA public TO app;
|
||||
-- Pre-create the extension as the superuser; the migration's CREATE EXTENSION IF NOT
|
||||
@@ -81,7 +81,7 @@ jobs:
|
||||
|
||||
# ── the family's shared managed database, emulated ──────────────────────────
|
||||
# The backend job runs on a superuser-made `app`/`migrator` pair in `public`. In the shared managed
|
||||
# database, Parafa lives in schema `parafa` as `parafa_migrator` / `parafa_app`,
|
||||
# database, Workflow lives in schema `workflow` as `workflow_migrator` / `workflow_app`,
|
||||
# provisioned by a platform admin that is NOT a superuser, next to the other apps' schemas.
|
||||
# `dredd_core.managed emulate` (TEST-ONLY) turns this plain Postgres 17 into a managed-Postgres
|
||||
# lookalike: a CREATEROLE admin `postgres_managed` standing in for a provider's `postgres`, the API
|
||||
@@ -108,18 +108,18 @@ jobs:
|
||||
SUPERUSER_URL: postgresql+pg8000://postgres:superpw@localhost:5432/postgres
|
||||
ADMIN_PASSWORD: ci-managed-admin-4f9c2e71
|
||||
ADMIN_URL: postgresql+pg8000://postgres_managed:ci-managed-admin-4f9c2e71@localhost:5432/postgres
|
||||
PARAFA_MIGRATOR_PASSWORD: ci-app-migrator-8d3b5a06
|
||||
PARAFA_APP_PASSWORD: ci-app-runtime-2e7f9c14
|
||||
WORKFLOW_MIGRATOR_PASSWORD: ci-app-migrator-8d3b5a06
|
||||
WORKFLOW_APP_PASSWORD: ci-app-runtime-2e7f9c14
|
||||
SIBLING_MIGRATOR_PASSWORD: ci-sibling-migrator-61a0d9
|
||||
SIBLING_APP_PASSWORD: ci-sibling-runtime-c47e22
|
||||
DATABASE_URL: postgresql+pg8000://parafa_app:ci-app-runtime-2e7f9c14@localhost:5432/postgres
|
||||
MIGRATION_DATABASE_URL: postgresql+pg8000://parafa_migrator:ci-app-migrator-8d3b5a06@localhost:5432/postgres
|
||||
DB_APP_ROLE: parafa_app
|
||||
DATA_DIR: ${{ github.workspace }}/parafa-data
|
||||
DATABASE_URL: postgresql+pg8000://workflow_app:ci-app-runtime-2e7f9c14@localhost:5432/postgres
|
||||
MIGRATION_DATABASE_URL: postgresql+pg8000://workflow_migrator:ci-app-migrator-8d3b5a06@localhost:5432/postgres
|
||||
DB_APP_ROLE: workflow_app
|
||||
DATA_DIR: ${{ github.workspace }}/workflow-data
|
||||
BOOTSTRAP_ADMIN_EMAIL: admin@example.com
|
||||
BOOTSTRAP_ADMIN_PASSWORD: adminpass1
|
||||
SEED_DEMO: "true"
|
||||
PARAFA_RUN_INTEGRATION: "1"
|
||||
WORKFLOW_RUN_INTEGRATION: "1"
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-python@v6
|
||||
@@ -138,8 +138,8 @@ jobs:
|
||||
# (--identity-schema / --identity-owner): the rendering Atrium's push.sh compares, as Agora.
|
||||
run: |
|
||||
python -m dredd_core.managed provision --sql-only \
|
||||
--schema parafa --app-role parafa_app --migrator-role parafa_migrator \
|
||||
--identity-schema dredd --identity-owner atrium_migrator \
|
||||
--schema workflow --app-role workflow_app --migrator-role workflow_migrator \
|
||||
--extension pgcrypto --identity-schema dredd --identity-owner atrium_migrator \
|
||||
--check-file db/managed/provision.sql
|
||||
- name: Emulate a managed Postgres (TEST-ONLY)
|
||||
# The service is on localhost, so no --allow-remote (emulate refuses a non-local host without it).
|
||||
@@ -157,16 +157,16 @@ jobs:
|
||||
CREATE TABLE sibling.app_user (id bigint PRIMARY KEY);
|
||||
CREATE TYPE sibling.node_role AS ENUM ('sibling_only');
|
||||
SQL
|
||||
- name: Provision Parafa as the platform admin
|
||||
- name: Provision Workflow as the platform admin
|
||||
run: |
|
||||
python -m dredd_core.managed provision --admin-url ADMIN_URL \
|
||||
--schema parafa --app-role parafa_app --migrator-role parafa_migrator \
|
||||
--migrator-password-env PARAFA_MIGRATOR_PASSWORD --app-password-env PARAFA_APP_PASSWORD
|
||||
- name: Migrate (as parafa_migrator) + seed (as parafa_app)
|
||||
--schema workflow --app-role workflow_app --migrator-role workflow_migrator \
|
||||
--extension pgcrypto --migrator-password-env WORKFLOW_MIGRATOR_PASSWORD --app-password-env WORKFLOW_APP_PASSWORD
|
||||
- name: Migrate (as workflow_migrator) + seed (as workflow_app)
|
||||
# As the compose migrate service does: alembic uses MIGRATION_DATABASE_URL, the seed DATABASE_URL.
|
||||
working-directory: backend
|
||||
run: alembic upgrade head && python -m app.seed
|
||||
- name: Tests (as parafa_app, DB_APP_ROLE=parafa_app)
|
||||
- name: Tests (as workflow_app, DB_APP_ROLE=workflow_app)
|
||||
working-directory: backend
|
||||
run: pytest -q
|
||||
- name: Managed check, as the runtime role and as the migrator (isolation included)
|
||||
@@ -177,11 +177,11 @@ jobs:
|
||||
append_only=$(python -c "from app.models import APPEND_ONLY_TABLES as t; print(*t)")
|
||||
no_delete=$(python -c "from app.models import NO_DELETE_TABLES as t; print(*t)")
|
||||
for url in DATABASE_URL MIGRATION_DATABASE_URL; do
|
||||
python -m dredd_core.managed check --url "$url" --expect-schema parafa \
|
||||
--app-role parafa_app --migrator-role parafa_migrator \
|
||||
python -m dredd_core.managed check --url "$url" --expect-schema workflow \
|
||||
--app-role workflow_app --migrator-role workflow_migrator \
|
||||
--append-only $append_only --no-delete $no_delete
|
||||
done
|
||||
- name: Everything is in schema parafa, nothing in public, nothing shared with the sibling
|
||||
- name: Everything is in schema workflow, nothing in public, nothing shared with the sibling
|
||||
run: |
|
||||
PGPASSWORD=superpw psql -h localhost -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
|
||||
DO $$
|
||||
@@ -190,16 +190,16 @@ jobs:
|
||||
WHERE n.nspname = 'public' AND c.relkind IN ('r', 'p', 'v', 'm', 'S')) THEN
|
||||
RAISE EXCEPTION 'a relation was created in schema public';
|
||||
END IF;
|
||||
IF (SELECT count(*) FROM pg_tables WHERE schemaname = 'parafa'
|
||||
IF (SELECT count(*) FROM pg_tables WHERE schemaname = 'workflow'
|
||||
AND tablename IN ('alembic_version', 'audit_log', 'app_user')) <> 3
|
||||
OR NOT EXISTS (SELECT 1 FROM pg_type t JOIN pg_namespace n ON n.oid = t.typnamespace
|
||||
WHERE n.nspname = 'parafa' AND t.typname = 'node_role') THEN
|
||||
RAISE EXCEPTION 'alembic_version / audit_log / app_user / node_role are not in schema parafa';
|
||||
WHERE n.nspname = 'workflow' AND t.typname = 'node_role') THEN
|
||||
RAISE EXCEPTION 'alembic_version / audit_log / app_user / node_role are not in schema workflow';
|
||||
END IF;
|
||||
IF has_schema_privilege('parafa_app', 'sibling', 'USAGE')
|
||||
OR has_schema_privilege('parafa_migrator', 'sibling', 'USAGE')
|
||||
OR has_schema_privilege('sibling_app', 'parafa', 'USAGE')
|
||||
OR has_schema_privilege('sibling_migrator', 'parafa', 'USAGE') THEN
|
||||
IF has_schema_privilege('workflow_app', 'sibling', 'USAGE')
|
||||
OR has_schema_privilege('workflow_migrator', 'sibling', 'USAGE')
|
||||
OR has_schema_privilege('sibling_app', 'workflow', 'USAGE')
|
||||
OR has_schema_privilege('sibling_migrator', 'workflow', 'USAGE') THEN
|
||||
RAISE EXCEPTION 'an app role can use the other app''s schema';
|
||||
END IF;
|
||||
END $$;
|
||||
@@ -214,22 +214,22 @@ jobs:
|
||||
PGPASSWORD=superpw psql -h localhost -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
|
||||
DO $$
|
||||
BEGIN
|
||||
IF (SELECT count(*) FROM pg_tables WHERE schemaname = 'parafa'
|
||||
IF (SELECT count(*) FROM pg_tables WHERE schemaname = 'workflow'
|
||||
AND tablename IN ('app_user', 'session', 'module_permission')) <> 3 THEN
|
||||
RAISE EXCEPTION 'a standalone app must keep its own identity tables in its own schema';
|
||||
END IF;
|
||||
-- And 0004 left nothing of the pre-v0.11.0 shape behind. Here rather than in a unit
|
||||
-- test because the whole point of that revision is what a real database already holds.
|
||||
IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname = 'parafa'
|
||||
IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname = 'workflow'
|
||||
AND tablename = 'module_moderator') THEN
|
||||
RAISE EXCEPTION 'the pre-v0.11.0 permission table is still here';
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM parafa.app_user) THEN
|
||||
IF NOT EXISTS (SELECT 1 FROM workflow.app_user) THEN
|
||||
RAISE EXCEPTION 'the seed created no bootstrap administrator';
|
||||
END IF;
|
||||
END $$;
|
||||
SQL
|
||||
- name: Downgrade to base and upgrade again (as parafa_migrator)
|
||||
- name: Downgrade to base and upgrade again (as workflow_migrator)
|
||||
working-directory: backend
|
||||
run: alembic downgrade base && alembic upgrade head
|
||||
|
||||
@@ -281,7 +281,7 @@ jobs:
|
||||
headers=$(curl -fsSI http://localhost/)
|
||||
echo "$headers" | grep -qi "content-security-policy" || { echo "::error::no CSP on the console"; exit 1; }
|
||||
echo "$headers" | grep -qi "x-frame-options" || { echo "::error::no frame policy on the console"; exit 1; }
|
||||
curl -fsS http://localhost/ | grep -q "<title>Parafa" || { echo "::error::console did not render"; exit 1; }
|
||||
curl -fsS http://localhost/ | grep -q "<title>Workflow" || { echo "::error::console did not render"; exit 1; }
|
||||
token=$(curl -fsS -X POST http://localhost/api/v1/auth/login \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"email":"admin@example.com","password":"ci-admin-password-1"}' | jq -r .token)
|
||||
@@ -295,7 +295,7 @@ jobs:
|
||||
# a refusal is the SUCCESS case — without it `bash -e` aborts on the correct answer.
|
||||
run: |
|
||||
set -uo pipefail
|
||||
out=$(docker compose exec -T postgres psql -U app -d parafa -c "UPDATE audit_log SET action = 'tampered'" 2>&1 || true)
|
||||
out=$(docker compose exec -T postgres psql -U app -d workflow -c "UPDATE audit_log SET action = 'tampered'" 2>&1 || true)
|
||||
echo "$out"
|
||||
echo "$out" | grep -q "permission denied" || { echo "::error::the app role can rewrite the audit log"; exit 1; }
|
||||
|
||||
|
||||
+4
-6
@@ -1,6 +1,6 @@
|
||||
# Credits
|
||||
|
||||
Parafa is Apache-2.0. Every shipped dependency is permissively licensed — the CI license
|
||||
Workflow is Apache-2.0. Every shipped dependency is permissively licensed — the CI license
|
||||
gate (`backend/scripts/license_gate.py`) fails the build on GPL, AGPL or SSPL.
|
||||
|
||||
## Runtime dependencies
|
||||
@@ -18,11 +18,6 @@ gate (`backend/scripts/license_gate.py`) fails the build on GPL, AGPL or SSPL.
|
||||
| [argon2-cffi](https://github.com/hynek/argon2-cffi) | MIT | Argon2id password hashing |
|
||||
| [httpx](https://www.python-httpx.org) | BSD-3-Clause | the one outbound HTTP client |
|
||||
| [OpenTelemetry Python](https://opentelemetry.io) | Apache-2.0 | optional tracing, off by default |
|
||||
| [pyHanko](https://github.com/MatthiasValvekens/pyHanko) + pyhanko-certvalidator | MIT | PAdES signing and signature validation |
|
||||
| [asn1crypto](https://github.com/wbond/asn1crypto) | MIT | ASN.1 / X.509 (via pyHanko) |
|
||||
| [cryptography](https://cryptography.io) | Apache-2.0 OR BSD-3-Clause | keys, PKCS#12, signatures (via pyHanko; tests make throwaway certificates with it) |
|
||||
| [lxml](https://lxml.de) | BSD-3-Clause | XML (via pyHanko) |
|
||||
| [aiohttp](https://github.com/aio-libs/aiohttp) | Apache-2.0 | pyHanko's HTTP client (no fetching is enabled here) |
|
||||
| [PostgreSQL](https://www.postgresql.org) | PostgreSQL License | the database |
|
||||
|
||||
## Console
|
||||
@@ -36,6 +31,9 @@ No framework, no bundler, no CDN: the console is `index.html` + `app.css` + `app
|
||||
|
||||
## Design credit
|
||||
|
||||
The skeleton — app layout, shims over dredd-core, migrations `0001`-`0004`, deployment files and
|
||||
the console shell — is taken from **Parafa** (szkielet z Parafy), the family's signing module.
|
||||
|
||||
The console's shape — grouped sidebar navigation, data tables with row actions, full-page create
|
||||
forms with edit modals, dashboard tiles, a command palette — is **inspired by
|
||||
[Open Mercato](https://github.com/open-mercato/open-mercato)**. It is an homage, not a copy or a
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Parafa
|
||||
# Workflow
|
||||
|
||||
A self-hosted management console.
|
||||
|
||||
@@ -7,18 +7,12 @@ installs as a dependency rather than copies.
|
||||
|
||||
## What it does
|
||||
|
||||
Parafa is the signing module of the platform (the Compass split, work package M6):
|
||||
Workflow is the platform's approval-workflow module: an *obieg akceptacji* (approval run) on a
|
||||
document from Galena, an uploaded file or a request (*wniosek*), passing through configurable stages
|
||||
until it is approved, signed on paper, rejected or cancelled. The domain is being built; routes,
|
||||
screens and the e2e run are documented once they exist.
|
||||
|
||||
- **Wniosek o podpis** — a signing request on a PDF: either a document in Galena (pinned at a
|
||||
version, read with your own session) or an uploaded file. Only PDF is accepted.
|
||||
- **Podpis PAdES** — a module moderator signs it with the operator's certificate (pyHanko, MIT).
|
||||
The signed PDF is kept as a new file and, for a Galena document, written back to Galena as a new
|
||||
version of the same document. The event `document.signed` is emitted for other modules.
|
||||
- **Do podpisu / Podpisane** — the two lists, and the same two numbers on `GET /api/v1/stats`.
|
||||
- **Weryfikacja** — upload any PDF and see, per signature, whether it is intact, valid and trusted.
|
||||
|
||||
The signer is configuration only: `SIGNING_PKCS12_PATH` and a passphrase file, mounted read-only.
|
||||
No key ever lives in this repository. Standalone, the stack is published on port **8121**.
|
||||
Standalone, the stack is published on port **8141**.
|
||||
|
||||
## Stack
|
||||
|
||||
@@ -35,13 +29,13 @@ writer, the security primitives, the shared enums and error types, and the engin
|
||||
factories all come from one installed package. `backend/requirements.txt` pins it by tag:
|
||||
|
||||
```
|
||||
dredd-core @ git+https://github.com/Alpaq92/dredd-core@v0.23.0
|
||||
dredd-core @ git+https://github.com/Alpaq92/dredd-core@v0.24.0
|
||||
```
|
||||
|
||||
The app-side files that used to hold that code (`services/auth.py`, `models/__init__.py`,
|
||||
`security.py`, `errors.py`, … and, in `nodes` tenancy, `services/authz.py`) are now **thin shims**:
|
||||
they re-export from `dredd_core` so every call site keeps its import path, and they hold only what
|
||||
is genuinely this app's — the `parafa_pat_` token prefix, the `parafa_session` cookie,
|
||||
is genuinely this app's — the `workflow_pat_` token prefix, the `workflow_session` cookie,
|
||||
the settings fed into core's auth policy. Fixing shared behaviour means changing dredd-core, tagging
|
||||
a release and moving the pin here — never patching a shim.
|
||||
|
||||
@@ -116,7 +110,7 @@ DREDD_CORE_TOKEN=github_pat_... docker compose up -d --build # postgres -> migr
|
||||
> never lands in an image layer. Don't put it in `.env`: every container loads that file at runtime.
|
||||
> CI's `compose-smoke` job runs exactly this stack on every push.
|
||||
|
||||
Open <http://localhost:8121> and sign in with `BOOTSTRAP_ADMIN_EMAIL` / `BOOTSTRAP_ADMIN_PASSWORD`.
|
||||
Open <http://localhost:8141> and sign in with `BOOTSTRAP_ADMIN_EMAIL` / `BOOTSTRAP_ADMIN_PASSWORD`.
|
||||
|
||||
> **Windows:** write `.env` without a BOM —
|
||||
> `[System.IO.File]::WriteAllText("$PWD\.env", (Get-Content .env.example -Raw))`.
|
||||
@@ -142,8 +136,8 @@ The API is served under `/api/v1`, with OpenAPI docs at `/api/v1/docs`.
|
||||
## Deploying on a managed PostgreSQL
|
||||
|
||||
The Dredd family can run in **one shared managed database** (one PostgreSQL 16/17 database at a managed
|
||||
provider), with Atrium as the hub; Parafa joins it as schema `parafa` with its own roles
|
||||
`parafa_migrator` and `parafa_app`. The provider hosts only the database — the backend still
|
||||
provider), with Atrium as the hub; Workflow joins it as schema `workflow` with its own roles
|
||||
`workflow_migrator` and `workflow_app`. The provider hosts only the database — the backend still
|
||||
runs on your server, with `docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d
|
||||
--build`. The same path works against any PostgreSQL 16/17 whose admin may create roles and schemas.
|
||||
|
||||
@@ -152,7 +146,7 @@ runs on your server, with `docker compose -f docker-compose.yml -f docker-compos
|
||||
point-in-time restore): step 0 of [`db/managed/README.md`](db/managed/README.md), and in more depth
|
||||
the family runbook in Atrium,
|
||||
[`deploy/README.md`](https://github.com/Alpaq92/Atrium/blob/main/deploy/README.md).
|
||||
- **Parafa's steps** (provisioning with `python -m dredd_core.managed provision` or the rendered
|
||||
- **Workflow's steps** (provisioning with `python -m dredd_core.managed provision` or the rendered
|
||||
[`db/managed/provision.sql`](db/managed/provision.sql), `.env` with `DB_APP_ROLE` and the pool knobs,
|
||||
migrate + seed, `python -m dredd_core.managed check`, restore specifics):
|
||||
[`db/managed/README.md`](db/managed/README.md).
|
||||
@@ -164,7 +158,7 @@ runs on your server, with `docker compose -f docker-compose.yml -f docker-compos
|
||||
|
||||
CI's `managed-db` job rehearses this path on PostgreSQL 17 without a superuser: it emulates a managed
|
||||
Postgres (`python -m dredd_core.managed emulate`), provisions the app next to a sibling, migrates, runs
|
||||
the integration suite as `parafa_app` and runs the managed check.
|
||||
the integration suite as `workflow_app` and runs the managed check.
|
||||
|
||||
## Security model
|
||||
|
||||
@@ -178,7 +172,7 @@ The runtime role's name is configuration (`DB_APP_ROLE`, `app` by default): the
|
||||
when it runs as a superuser or the platform admin, or when a grant did not take. Migrations run as the
|
||||
migrator and nothing else.
|
||||
|
||||
Only the backend is published to the host (:8121) — it serves the console and sets every security
|
||||
Only the backend is published to the host (:8141) — it serves the console and sets every security
|
||||
header itself (`backend/app/edge.py`); Postgres is `expose`-only. There is no reverse proxy.
|
||||
|
||||
Access control lives in exactly one module, `backend/app/services/authz.py` — a re-export of
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ COPY . .
|
||||
# NAMED build context: compose passes `additional_contexts: { frontend: ./frontend }`, and a bare
|
||||
# build from backend/ needs `docker build --build-context frontend=../frontend .`.
|
||||
COPY --from=frontend . /frontend
|
||||
ENV PARAFA_FRONTEND_DIR=/frontend
|
||||
ENV WORKFLOW_FRONTEND_DIR=/frontend
|
||||
|
||||
RUN useradd -m app && mkdir -p /data && chown -R app /data /app
|
||||
ENV DATA_DIR=/data
|
||||
@@ -58,9 +58,9 @@ HEALTHCHECK --interval=15s --timeout=5s --retries=10 \
|
||||
# the audit log records the peer address. On the Dredd platform set FORWARDED_ALLOW_IPS to the
|
||||
# front door's (Atrium backend's) address, never `*`.
|
||||
# The path prefix the platform's front door strips before the request reaches us. Empty (the
|
||||
# default) is the standalone stack, served at the origin root; ROOT_PATH=/parafa mounts this app
|
||||
# default) is the standalone stack, served at the origin root; ROOT_PATH=/workflow mounts this app
|
||||
# under a path prefix of a shared origin. uvicorn PREPENDS it to the incoming path, so it pairs with
|
||||
# the front door forwarding `/parafa/*` with the prefix stripped: set one without the other and you get either a doubled
|
||||
# the front door forwarding `/workflow/*` with the prefix stripped: set one without the other and you get either a doubled
|
||||
# prefix (404 everywhere) or server-generated URLs that escape the prefix. app/config.py reads the
|
||||
# same variable, so FastAPI's root_path agrees. The healthcheck below needs no prefix — uvicorn
|
||||
# prepends, Starlette strips, so the un-prefixed path still matches the route either way.
|
||||
|
||||
@@ -9,7 +9,7 @@ file they name does not have to exist on the machine rendering the SQL.
|
||||
|
||||
Where the tables land is the migrator's business, not this file's: nothing is schema-qualified, so
|
||||
`alembic_version`, the enum types and every table go to the first schema on the role's search_path —
|
||||
`public` locally, `parafa` in the shared database, where provisioning sets that path.
|
||||
`public` locally, `workflow` in the shared database, where provisioning sets that path.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -67,7 +67,7 @@ def _runtime_role_is_the_login() -> None:
|
||||
raise RuntimeError(
|
||||
f"refusing to migrate: DB_APP_ROLE is {settings.db_app_role!r}, but DATABASE_URL logs in as "
|
||||
f"{login!r}. 0002 grants the runtime privileges to DB_APP_ROLE, so both must name this app's "
|
||||
"runtime role (parafa_app in the shared database, app locally).")
|
||||
"runtime role (workflow_app in the shared database, app locally).")
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
|
||||
@@ -6,7 +6,7 @@ Tables come from the ORM metadata. `from app.models import Base` imports this ap
|
||||
halves and the migration cannot drift from the models.
|
||||
|
||||
**dredd-core ships models, not migrations.** Every app in the family owns its own `0001` and its own
|
||||
schema — its own database locally, its own schema `parafa` in the family's shared managed
|
||||
schema — its own database locally, its own schema `workflow` in the family's shared managed
|
||||
database: the core tables are created *here*, in this app's schema, from a shared model definition.
|
||||
No other app's roles can reach that schema, so a standalone install keeps its own accounts and its own
|
||||
`session` rows here. That is the starting point, not a ban on sharing: the family's shape is one
|
||||
@@ -25,14 +25,14 @@ them in whatever schema comes FIRST on the migrator's search_path, which is this
|
||||
lifespan's `assert_identity_schema` is what proves `0003` then took them away again.
|
||||
|
||||
Nothing here is schema-qualified. Tables, enum types and `alembic_version` land in the first schema on
|
||||
the migrator's search_path (`public` locally; `parafa, extensions` on the shared project, set by
|
||||
the migrator's search_path (`public` locally; `workflow, extensions` on the shared project, set by
|
||||
provisioning), and `create_all`'s checkfirst and `create_enum_types` only look there — so a sibling
|
||||
app's `audit_log` or `node_role` in *its* schema never makes a table or type here get skipped.
|
||||
|
||||
Bumping the dredd-core pin can change what `Base.metadata` holds. That is an ordinary schema change
|
||||
for this app and belongs in a **new** revision — never in an edit to this one.
|
||||
|
||||
Parafa is flat (single-tenant) and never uses the org tree — but importing `dredd_core`
|
||||
Workflow is flat (single-tenant) and never uses the org tree — but importing `dredd_core`
|
||||
registers those models too, so `node`, `permission_grant` and `favorite` are created here as well.
|
||||
They stay empty and unused. That is expected: three idle tables cost nothing, and trying to suppress
|
||||
them means fighting the metadata that the rest of core is built on. Leave them — a later move to
|
||||
@@ -48,7 +48,7 @@ that still uses it. The cost of that flag is that `create_all` on a fresh databa
|
||||
`type "node_role" does not exist` unless the types are already there. Hence the order in
|
||||
`upgrade()`:
|
||||
|
||||
create_enum_types(bind) # CREATE TYPE … — core's enums and Parafa's own
|
||||
create_enum_types(bind) # CREATE TYPE … — core's enums and Workflow's own
|
||||
Base.metadata.create_all(bind) # then the tables that reference them
|
||||
|
||||
`create_enum_types` reads the types straight off `Base.metadata`, so **adding an enum needs no edit
|
||||
@@ -81,7 +81,7 @@ depends_on = None
|
||||
|
||||
|
||||
def _enum_type_names() -> list[str]:
|
||||
"""Every native enum type the metadata references — core's and Parafa's own.
|
||||
"""Every native enum type the metadata references — core's and Workflow's own.
|
||||
|
||||
`create_enum_types` creates them; nothing drops them, because `create_type=False` suppresses
|
||||
SQLAlchemy's `DROP TYPE` just as it suppresses the `CREATE`. So `downgrade()` needs this list to
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"""Runtime grants: what the least-privilege runtime role may do in Parafa's schema.
|
||||
"""Runtime grants: what the least-privilege runtime role may do in Workflow's schema.
|
||||
|
||||
One call to `dredd_core.schema.runtime_grants_sql`, which renders a single idempotent `DO` block that
|
||||
acts on `current_schema()` — `public` on the local stack (db/init/01-roles.sh makes `migrator` own it),
|
||||
`parafa` in the family's shared managed database (provisioning puts it first on the migrator's
|
||||
`workflow` in the family's shared managed database (provisioning puts it first on the migrator's
|
||||
search_path) — for the role DB_APP_ROLE names (`get_settings().db_app_role`: `app` locally and in CI,
|
||||
`parafa_app` in the shared database, where role names are cluster-wide). Both setups end up with
|
||||
`workflow_app` in the shared database, where role names are cluster-wide). Both setups end up with
|
||||
the same least-privilege shape:
|
||||
|
||||
- the runtime role may use the schema, SELECT / INSERT / UPDATE / DELETE every table and use its
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
"""Parafa joins the platform: its accounts become THE platform's accounts.
|
||||
"""Workflow joins the platform: its accounts become THE platform's accounts.
|
||||
|
||||
Before this, Parafa keeps its own `app_user`, and the `admin@example.com` in it is a different
|
||||
Before this, Workflow keeps its own `app_user`, and the `admin@example.com` in it is a different
|
||||
person from the `admin@example.com` in every sibling who happens to share an email address — four
|
||||
people, four passwords. After it, identity lives in a neutral schema the hub owns, this module reads
|
||||
it, and the cookie somebody got by signing in at the hub is the cookie this app accepts. One origin,
|
||||
one cookie, one `session` row: there is no handoff here and there must never be one.
|
||||
|
||||
**It does nothing at all unless IDENTITY_SCHEMA is set.** A standalone Parafa — its own
|
||||
**It does nothing at all unless IDENTITY_SCHEMA is set.** A standalone Workflow — its own
|
||||
database, its own people, no hub — keeps every table exactly where `0001` put it and never runs a
|
||||
statement from this file. That is a hard rule, not a convenience: the two deployments must stay one
|
||||
codebase, or local development forks from production and the fork is discovered in production.
|
||||
@@ -60,7 +60,7 @@ Two reasons, and the first is sufficient on its own:
|
||||
A fresh install behaves identically, by construction rather than by a second code path: `0001` still
|
||||
builds the three identity tables in this app's own schema, and this revision still moves them. There
|
||||
are simply no rows to move. The lifespan's `assert_identity_schema` then proves the local copies are
|
||||
really gone — with `search_path = parafa, <identity>, extensions` an unqualified `app_user`
|
||||
really gone — with `search_path = workflow, <identity>, extensions` an unqualified `app_user`
|
||||
resolves to a local one if it exists and everything keeps working, silently back to two rows per
|
||||
human, which is the failure mode with no other symptom.
|
||||
|
||||
|
||||
+14
-14
@@ -33,11 +33,11 @@ class Settings(BaseSettings):
|
||||
app_base_url: str = "http://localhost"
|
||||
|
||||
# The path prefix this deployment is mounted under. Empty (the default) = served at the origin
|
||||
# root, which is the standalone stack this repo ships. ROOT_PATH=/parafa runs it as a module
|
||||
# root, which is the standalone stack this repo ships. ROOT_PATH=/workflow runs it as a module
|
||||
# of a platform: one origin, one module per path.
|
||||
#
|
||||
# It is HALF of one decision, never set alone: the platform's front door must STRIP the
|
||||
# prefix (Atrium's backend forwards `/parafa/*` without it) and this backend must re-add it. uvicorn PREPENDS root_path to
|
||||
# prefix (Atrium's backend forwards `/workflow/*` without it) and this backend must re-add it. uvicorn PREPENDS root_path to
|
||||
# the incoming path, so forwarding without the strip doubles the prefix and 404s every route, while
|
||||
# stripping without ROOT_PATH makes every server-generated URL (redirects, StaticFiles' own
|
||||
# directory redirect, the OpenAPI `servers` entry) escape the prefix. The same value reaches
|
||||
@@ -51,20 +51,20 @@ class Settings(BaseSettings):
|
||||
def _mounted_path(cls, v: str) -> str:
|
||||
# Refused rather than normalised, because uvicorn reads the RAW environment variable off
|
||||
# the command line while everything in-process reads this one. Silently fixing it here
|
||||
# would leave the two disagreeing: `--root-path /parafa/` prepends `/parafa/` and FastAPI
|
||||
# then overwrites scope["root_path"] with its own normalised `/parafa`, so the two differ
|
||||
# would leave the two disagreeing: `--root-path /workflow/` prepends `/workflow/` and FastAPI
|
||||
# then overwrites scope["root_path"] with its own normalised `/workflow`, so the two differ
|
||||
# by one character and every route 404s with nothing in the logs to say why.
|
||||
v = v.strip()
|
||||
if v and (not v.startswith("/") or v.endswith("/")):
|
||||
raise ValueError("ROOT_PATH must be empty or a path like /parafa - leading slash, no "
|
||||
raise ValueError("ROOT_PATH must be empty or a path like /workflow - leading slash, no "
|
||||
"trailing slash")
|
||||
return v
|
||||
|
||||
# Database (runtime = least-privilege "app" role; migrator = DDL). A managed database's URL
|
||||
# carries ?sslmode=verify-full&sslrootcert=..., which dredd_core.db.make_engine turns into TLS.
|
||||
database_url: str = "postgresql+pg8000://app:app@localhost:5432/parafa"
|
||||
database_url: str = "postgresql+pg8000://app:app@localhost:5432/workflow"
|
||||
migration_database_url: str = (
|
||||
"postgresql+pg8000://migrator:migrator@localhost:5432/parafa"
|
||||
"postgresql+pg8000://migrator:migrator@localhost:5432/workflow"
|
||||
)
|
||||
# The family's one TLS rule (dredd_core.db.require_verified_tls, applied below): a database host
|
||||
# that is not local must carry sslmode=verify-full, or the app refuses to start. Local is "",
|
||||
@@ -75,7 +75,7 @@ class Settings(BaseSettings):
|
||||
# The runtime role's NAME: the user DATABASE_URL logs in as, without a pooler's `.<tenant>`
|
||||
# suffix. The runtime-grants migration (0002) grants to it. `app` locally and in CI; in the
|
||||
# family's shared managed database role names are cluster-wide, so there it is
|
||||
# `parafa_app` (db/managed/README.md). Nothing else in the app needs a role name.
|
||||
# `workflow_app` (db/managed/README.md). Nothing else in the app needs a role name.
|
||||
db_app_role: str = "app"
|
||||
# The backend's pool: at most db_pool_size + db_max_overflow connections. Every app of the family
|
||||
# draws on one shared database's connection limit, so size these there (db/managed/README.md).
|
||||
@@ -115,7 +115,7 @@ class Settings(BaseSettings):
|
||||
|
||||
# ── One platform, one account ────────────────────────────────────────────────
|
||||
# The shared identity schema. Empty — the default, and what this repo's own compose stack runs —
|
||||
# is the STANDALONE deployment: Parafa owns `app_user` / `session` / `module_permission` in
|
||||
# is the STANDALONE deployment: Workflow owns `app_user` / `session` / `module_permission` in
|
||||
# its own schema, has its own sign-in screen and its own Users administration, and nothing that
|
||||
# follows changes. Set it (IDENTITY_SCHEMA=dredd) and this app becomes a MODULE of
|
||||
# the platform: those three tables live in a neutral schema the hub owns and every module READS,
|
||||
@@ -137,13 +137,13 @@ class Settings(BaseSettings):
|
||||
# the only thing this app tells dredd-core about the platform: core is handed data (a slug),
|
||||
# never a predicate, which is what keeps the rule and its enforcement inside core.
|
||||
#
|
||||
# It is a SEPARATE name from `parafa`, this app's Postgres schema and role prefix, and the
|
||||
# It is a SEPARATE name from `workflow`, this app's Postgres schema and role prefix, and the
|
||||
# two are allowed to differ because their judges differ. A schema name may hold underscores and
|
||||
# must not hold hyphens; a module slug is the platform's public vocabulary — it appears in a URL
|
||||
# path — and `dredd.module_permission` holds it to `^[a-z0-9][a-z0-9-]{0,39}$`: hyphens yes,
|
||||
# underscores no. A two-word app therefore has a schema `my_app` and a module slug `my-app`, and
|
||||
# the scaffolder derives the second from the first so the default is already legal.
|
||||
module_slug: str = "parafa"
|
||||
module_slug: str = "workflow"
|
||||
# Where people sign in when identity is shared — the hub's address as a BROWSER sees it, e.g.
|
||||
# /atrium/ on the platform. Empty standalone (there is no hub), and empty is survivable on the
|
||||
# platform too: the console then says where accounts live without linking to them. It is
|
||||
@@ -221,7 +221,7 @@ class Settings(BaseSettings):
|
||||
# reproduce it. Standalone the slug is irrelevant and may be anything, empty included.
|
||||
if self.shares_identity and not self.module_slug:
|
||||
raise ValueError("MODULE_SLUG must name this app's module on the platform (e.g. "
|
||||
"parafa) whenever IDENTITY_SCHEMA is set — permission "
|
||||
"workflow) whenever IDENTITY_SCHEMA is set — permission "
|
||||
"rows are keyed by it")
|
||||
return self
|
||||
|
||||
@@ -231,7 +231,7 @@ class Settings(BaseSettings):
|
||||
# entire single-sign-on mechanism — no Domain attribute, no signed assertion, no audience
|
||||
# binding. The default keeps a standalone app on its own name; `deps.LEGACY_SESSION_COOKIES`
|
||||
# keeps reading the old one, so renaming it does not sign everybody out on the next restart.
|
||||
session_cookie_name: str = "parafa_session"
|
||||
session_cookie_name: str = "workflow_session"
|
||||
|
||||
@field_validator("session_cookie_name")
|
||||
@classmethod
|
||||
@@ -287,7 +287,7 @@ class Settings(BaseSettings):
|
||||
|
||||
# OpenTelemetry (opt-in)
|
||||
otel_enabled: bool = False
|
||||
otel_service_name: str = "parafa-backend"
|
||||
otel_service_name: str = "workflow-backend"
|
||||
otel_exporter_otlp_endpoint: str = "http://otel-collector:4317"
|
||||
|
||||
@field_validator("frame_ancestors")
|
||||
|
||||
+2
-2
@@ -34,11 +34,11 @@ from .services import moderation as moderation_service
|
||||
SESSION_COOKIE = get_settings().session_cookie_name
|
||||
|
||||
#: Cookie names this app has issued before and still accepts. Renaming the cookie at a cutover
|
||||
#: (`parafa_session` → `dredd_session`, one name for the whole platform) would otherwise
|
||||
#: (`workflow_session` → `dredd_session`, one name for the whole platform) would otherwise
|
||||
#: sign everybody out the moment the new container starts — the row behind the token is the same row
|
||||
#: either way, only the label on the jar changed. `routers/auth.py` deletes every legacy name on the
|
||||
#: next login or logout, so this clears itself rather than accumulating.
|
||||
LEGACY_SESSION_COOKIES = tuple(n for n in ("parafa_session",) if n != SESSION_COOKIE)
|
||||
LEGACY_SESSION_COOKIES = tuple(n for n in ("workflow_session",) if n != SESSION_COOKIE)
|
||||
|
||||
|
||||
def _bearer_token(request: Request) -> str | None:
|
||||
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
"""This backend's own edge: security headers, the body cap, the console.
|
||||
|
||||
There is no reverse proxy. Standalone, docker-compose.yml publishes uvicorn directly; on the Dredd
|
||||
platform Atrium's backend is the front door (its `app/frontdoor.py`) and forwards `/parafa/*`
|
||||
platform Atrium's backend is the front door (its `app/frontdoor.py`) and forwards `/workflow/*`
|
||||
here with the prefix stripped, and uvicorn's `--root-path "$ROOT_PATH"` puts it back. Either way this
|
||||
process answers for everything a browser gets. Same shape as the family modules' `app/edge.py`.
|
||||
|
||||
**Every path comparison reads the ROUTE path** (`starlette._utils.get_route_path`), never
|
||||
`request.url.path` / `scope["path"]`: with ROOT_PATH=/parafa uvicorn re-prepends the prefix, so
|
||||
the raw path reads `/parafa/api/v1/...` and an `/api` match would silently miss, handing the API
|
||||
`request.url.path` / `scope["path"]`: with ROOT_PATH=/workflow uvicorn re-prepends the prefix, so
|
||||
the raw path reads `/workflow/api/v1/...` and an `/api` match would silently miss, handing the API
|
||||
the console's CSP and Cache-Control, and handing unknown API paths to the console.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Enum labels: the shared ones re-exported from dredd-core, Parafa's own below the divider.
|
||||
"""Enum labels: the shared ones re-exported from dredd-core, Workflow's own below the divider.
|
||||
|
||||
`SessionKind` and `TokenScope` describe the credentials core's auth service issues; they are
|
||||
declared in **dredd-core** and re-exported here so every call site keeps importing
|
||||
@@ -20,7 +20,7 @@ from dredd_core.enums import SessionKind, TokenScope
|
||||
# type surgery on a live database.
|
||||
|
||||
|
||||
# ── Parafa's own ────────────────────────────────────────────────────────
|
||||
# ── Workflow's own ────────────────────────────────────────────────────────
|
||||
# None yet.
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from .config import get_settings
|
||||
|
||||
log = logging.getLogger("parafa.errors")
|
||||
log = logging.getLogger("workflow.errors")
|
||||
settings = get_settings()
|
||||
_PROBLEM = "application/problem+json"
|
||||
|
||||
|
||||
+7
-7
@@ -28,7 +28,7 @@ API_PREFIX = "/api/v1"
|
||||
|
||||
settings = get_settings()
|
||||
configure_logging()
|
||||
log = logging.getLogger("parafa")
|
||||
log = logging.getLogger("workflow")
|
||||
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
@@ -39,8 +39,8 @@ async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
||||
`search_path`, never schema qualification, and this app's own schema has to come FIRST —
|
||||
otherwise `alembic_version`, the enum types and every new table would land in a schema its
|
||||
migrator does not own. The entire cost of that correct choice is this: with
|
||||
`search_path = parafa, dredd, extensions`, an unqualified `app_user` resolves
|
||||
to **`parafa.app_user` if one exists**, and everything keeps working. You are simply back
|
||||
`search_path = workflow, dredd, extensions`, an unqualified `app_user` resolves
|
||||
to **`workflow.app_user` if one exists**, and everything keeps working. You are simply back
|
||||
to two rows per human, silently — which is the exact defect sharing identity exists to end.
|
||||
|
||||
A stray `create_all`, a restored single-schema dump, or a fresh install whose cutover revision
|
||||
@@ -81,14 +81,14 @@ async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Parafa API",
|
||||
title="Workflow API",
|
||||
version=__version__,
|
||||
description="Obiegi akceptacji dokumentów i wniosków.",
|
||||
docs_url=f"{API_PREFIX}/docs",
|
||||
redoc_url=None,
|
||||
openapi_url=f"{API_PREFIX}/openapi.json",
|
||||
# The path prefix the platform's front door strips before the request reaches us. Empty (the
|
||||
# default) = served at the origin root; ROOT_PATH=/parafa mounts this app under a path
|
||||
# default) = served at the origin root; ROOT_PATH=/workflow mounts this app under a path
|
||||
# prefix of a shared origin. Routes stay un-prefixed either way — FastAPI needs it only to emit correct
|
||||
# absolute URLs (the OpenAPI `servers` entry, the /docs asset links). uvicorn gets the same value
|
||||
# on its command line (backend/Dockerfile), so scope["root_path"] agrees however the app is run.
|
||||
@@ -136,10 +136,10 @@ app.add_middleware(SecurityHeaders, frame_ancestors=settings.frame_ancestors)
|
||||
|
||||
# The static console — this backend serves it itself; there is no reverse proxy. Mounted at "/"
|
||||
# LAST so every API route wins, behind ConsoleUnlessApi so /api/* and /healthz never fall through
|
||||
# to it (see its docstring), with the index.html SPA fallback. PARAFA_FRONTEND_DIR
|
||||
# to it (see its docstring), with the index.html SPA fallback. WORKFLOW_FRONTEND_DIR
|
||||
# overrides the location; the default is the repo's ../frontend, which is also where
|
||||
# backend/Dockerfile copies it (/frontend in the image).
|
||||
_FRONTEND = Path(os.environ.get("PARAFA_FRONTEND_DIR")
|
||||
_FRONTEND = Path(os.environ.get("WORKFLOW_FRONTEND_DIR")
|
||||
or Path(__file__).resolve().parents[2] / "frontend")
|
||||
if _FRONTEND.is_dir():
|
||||
app.mount("/", ConsoleUnlessApi(SpaStaticFiles(directory=str(_FRONTEND), html=True),
|
||||
|
||||
@@ -9,7 +9,7 @@ import logging
|
||||
|
||||
from .config import get_settings
|
||||
|
||||
log = logging.getLogger("parafa.observability")
|
||||
log = logging.getLogger("workflow.observability")
|
||||
|
||||
|
||||
def setup_observability(app, engine) -> None:
|
||||
|
||||
@@ -41,7 +41,7 @@ def meta() -> dict:
|
||||
a link that goes nowhere.
|
||||
"""
|
||||
return {
|
||||
"product": "parafa",
|
||||
"product": "workflow",
|
||||
"version": __version__,
|
||||
"local_login": not settings.shares_identity,
|
||||
"app_tokens": settings.app_tokens_enabled,
|
||||
|
||||
@@ -142,7 +142,7 @@ def list_tokens(db: Session = Depends(get_db),
|
||||
def create_token(body: AppTokenIn, request: Request, db: Session = Depends(get_db),
|
||||
user: AppUser = Depends(get_current_user)) -> dict:
|
||||
if settings.shares_identity:
|
||||
# The hub stamps the token `parafa_pat_` on this module's behalf, so the prefix still
|
||||
# The hub stamps the token `workflow_pat_` on this module's behalf, so the prefix still
|
||||
# says where a leaked credential came from and whose audit log to read first.
|
||||
raise ConflictError(
|
||||
f"App tokens are created at {settings.identity_hub_url or 'the hub'}, once, for every "
|
||||
|
||||
@@ -26,7 +26,7 @@ from dredd_core.security import token_display_prefix as _token_display_prefix
|
||||
# is a module of one, where every module's tokens sit side by side. Either way the prefix is the only
|
||||
# thing saying which app minted the leaked credential, and so which audit log to read first. That
|
||||
# matters more under one platform, not less. Keep it distinct per app.
|
||||
APP_TOKEN_PREFIX = "parafa_pat_"
|
||||
APP_TOKEN_PREFIX = "workflow_pat_"
|
||||
|
||||
|
||||
def generate_app_token() -> str:
|
||||
@@ -35,7 +35,7 @@ def generate_app_token() -> str:
|
||||
|
||||
|
||||
def token_display_prefix(token: str) -> str:
|
||||
"""The non-secret fragment safe to store and show, e.g. `parafa_pat_a1b2c3`.
|
||||
"""The non-secret fragment safe to store and show, e.g. `workflow_pat_a1b2c3`.
|
||||
|
||||
A few characters of a high-entropy token identify it among a user's handful of tokens while
|
||||
leaving it computationally useless — but it is still stored in the clear, so keep it short.
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ from .config import get_settings
|
||||
from .db import SessionLocal
|
||||
from .services import auth as auth_service
|
||||
|
||||
log = logging.getLogger("parafa.seed")
|
||||
log = logging.getLogger("workflow.seed")
|
||||
|
||||
|
||||
def run(session_factory: sessionmaker | None = None) -> None:
|
||||
|
||||
@@ -6,7 +6,7 @@ server-side sessions backed by the `session` table (so revocation is an instant
|
||||
named app tokens whose *idle* expiry slides forward on use — an exfiltrated token that is never
|
||||
used dies on its own, which a password never does.
|
||||
|
||||
This module binds Parafa's settings and its own app-token prefix onto one `AuthService`
|
||||
This module binds Workflow's settings and its own app-token prefix onto one `AuthService`
|
||||
and re-exports each operation as a module-level function, so every `auth_service.<fn>(db, ...)`
|
||||
call site (`deps.py`, `routers/auth.py`, `routers/users.py`, `seed.py`) reads exactly as before.
|
||||
|
||||
@@ -58,7 +58,7 @@ _POLICY = AuthPolicy(
|
||||
# exactly right here: a module holds no INSERT on `session`, so it cannot create a credential —
|
||||
# a role that could insert a session row could mint a working cookie for the administrator — but
|
||||
# it holds SELECT and UPDATE (revoked_at), so a person can still see and kill the tokens they
|
||||
# have. Minting moves to the hub, which stamps them `parafa_pat_` on this module's behalf.
|
||||
# have. Minting moves to the hub, which stamps them `workflow_pat_` on this module's behalf.
|
||||
app_tokens_enabled=settings.app_tokens_enabled and not settings.shares_identity,
|
||||
app_token_idle_days=settings.app_token_idle_days,
|
||||
app_token_max_idle_days=settings.app_token_max_idle_days,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""What a person may do in Parafa, bound to Parafa — a thin shim.
|
||||
"""What a person may do in Workflow, bound to Workflow — a thin shim.
|
||||
|
||||
The model lives in `dredd_core.moderation` (shared across the family); this binds this app's slug and
|
||||
mode onto a `ModerationService` and re-exports its operations, exactly as `services/auth.py` does for
|
||||
@@ -8,7 +8,7 @@ mode onto a `ModerationService` and re-exports its operations, exactly as `servi
|
||||
MODERATOR administers exactly one module a `module_permission` row
|
||||
USER may use exactly one module a `module_permission` row
|
||||
|
||||
The module in question is always this one — `MODULE_SLUG` in the settings (`parafa`).
|
||||
The module in question is always this one — `MODULE_SLUG` in the settings (`workflow`).
|
||||
|
||||
The fourth answer is **no row**, and it is the default for everybody: no access to this module at
|
||||
all. That is what `assert_may_use` below is for, and `deps.get_current_user` is where it is asked.
|
||||
|
||||
@@ -33,7 +33,7 @@ class Spec:
|
||||
|
||||
SPECS: dict[str, Spec] = {
|
||||
# What the console calls this instance. Plain text; the console escapes it.
|
||||
"instance_name": Spec(TEXT, "Parafa", max_length=80, required=True),
|
||||
"instance_name": Spec(TEXT, "Workflow", max_length=80, required=True),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[project]
|
||||
name = "parafa-backend"
|
||||
name = "workflow-backend"
|
||||
version = "0.1.0"
|
||||
description = "A self-hosted management console."
|
||||
requires-python = ">=3.12"
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
# The repo is PRIVATE, so pip needs credentials to fetch it:
|
||||
# local — a GitHub PAT in your git credential helper (or an SSH `insteadOf` rewrite)
|
||||
# CI — the DREDD_CORE_TOKEN repo secret; see the auth step in .github/workflows/ci.yml
|
||||
dredd-core @ git+https://github.com/Alpaq92/dredd-core@v0.23.0
|
||||
dredd-core @ git+https://github.com/Alpaq92/dredd-core@v0.24.0
|
||||
|
||||
# Web framework
|
||||
fastapi==0.115.6
|
||||
|
||||
@@ -11,7 +11,7 @@ Run it before shipping: python scripts/deploy_check.py [--env PATH]
|
||||
points anywhere but the compose `postgres` service, this machine or a DB_LOCAL_HOSTS entry, the
|
||||
database is external — the family's shared managed database — and both URLs are checked for what that
|
||||
needs: verify-full TLS (against the mounted CA, or the system trust store), exactly this app's own
|
||||
roles (parafa_app / parafa_migrator: no platform-admin user, no sibling app's role), a
|
||||
roles (workflow_app / workflow_migrator: no platform-admin user, no sibling app's role), a
|
||||
pooler's session mode rather than its transaction-mode port 6543, distinct migrator and runtime roles,
|
||||
DB_APP_ROLE naming the runtime role, and a bounded pool.
|
||||
"""
|
||||
@@ -25,7 +25,7 @@ from urllib.parse import parse_qs, unquote
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||||
|
||||
_parser = argparse.ArgumentParser(description="Deployment pre-flight for the Parafa stack.")
|
||||
_parser = argparse.ArgumentParser(description="Deployment pre-flight for the Workflow stack.")
|
||||
_parser.add_argument("--env", type=pathlib.Path, default=ROOT / ".env",
|
||||
help="the settings file to check (default: .env at the repository root)")
|
||||
ENV_PATH: pathlib.Path = _parser.parse_args().env
|
||||
@@ -76,7 +76,7 @@ check(not undocumented,
|
||||
# ── compose wiring ────────────────────────────────────────────────────────────
|
||||
check("env_file: .env" in compose,
|
||||
"compose services do not load .env", "compose loads .env")
|
||||
check(compose.count("image: parafa-backend:local") >= 2,
|
||||
check(compose.count("image: workflow-backend:local") >= 2,
|
||||
"migrate and backend should share one built image",
|
||||
"migrate and backend share one image (no double build)")
|
||||
check("condition: service_completed_successfully" in compose,
|
||||
@@ -85,8 +85,8 @@ check("condition: service_completed_successfully" in compose,
|
||||
check("condition: service_healthy" in compose,
|
||||
"nothing waits on the postgres healthcheck",
|
||||
"migrate waits for a healthy postgres")
|
||||
check(':-8121}:8000"' in compose and "expose:" in compose,
|
||||
"expected the backend published on :8121 (PARAFA_PORT) and postgres expose-only",
|
||||
check(':-8141}:8000"' in compose and "expose:" in compose,
|
||||
"expected the backend published on :8141 (WORKFLOW_PORT) and postgres expose-only",
|
||||
"only the backend is published; postgres is expose-only")
|
||||
# No reverse proxy: the backend is its own edge (app/edge.py). A proxy service or config file coming
|
||||
# back would mean two places deciding headers and routing again.
|
||||
@@ -171,17 +171,17 @@ if ENV_PATH.exists():
|
||||
|
||||
# ── the shared managed database: provisioning and the compose override ────────
|
||||
provision_sql = read("db/managed/provision.sql")
|
||||
check("--schema parafa --app-role parafa_app --migrator-role parafa_migrator"
|
||||
check("--schema workflow --app-role workflow_app --migrator-role workflow_migrator"
|
||||
in provision_sql,
|
||||
"db/managed/provision.sql is not dredd-core's rendering for schema parafa "
|
||||
"db/managed/provision.sql is not dredd-core's rendering for schema workflow "
|
||||
"(re-render it: see db/managed/README.md)",
|
||||
"db/managed/provision.sql provisions schema parafa (CI checks it is current)")
|
||||
"db/managed/provision.sql provisions schema workflow (CI checks it is current)")
|
||||
override = read("docker-compose.managed-db.yml")
|
||||
CA_TARGET = "/run/certs/db-ca.crt"
|
||||
# The platform admin at a provider, and its stand-in in dredd-core's emulation.
|
||||
PLATFORM_ROLES = ("postgres", "postgres_managed")
|
||||
#: Parafa's roles in the shared database (db/managed/README.md), the names provision.sql is rendered for.
|
||||
SHARED_ROLES = {"DATABASE_URL": "parafa_app", "MIGRATION_DATABASE_URL": "parafa_migrator"}
|
||||
#: Workflow's roles in the shared database (db/managed/README.md), the names provision.sql is rendered for.
|
||||
SHARED_ROLES = {"DATABASE_URL": "workflow_app", "MIGRATION_DATABASE_URL": "workflow_migrator"}
|
||||
|
||||
|
||||
def service_block(name: str) -> str:
|
||||
@@ -279,14 +279,14 @@ if runtime and runtime["host"].strip("[]") not in LOCAL_HOSTS:
|
||||
f"{name} verifies the server against "
|
||||
f"{'the mounted provider CA' if root_certs else 'the system trust store'}")
|
||||
check(role not in PLATFORM_ROLES and role != "",
|
||||
f"{name} logs in as {role or 'no user'}: never the platform admin — use Parafa's "
|
||||
"own roles (parafa_app / parafa_migrator)",
|
||||
f"{name} logs in as {role or 'no user'}: never the platform admin — use Workflow's "
|
||||
"own roles (workflow_app / workflow_migrator)",
|
||||
f"{name} does not log in as the platform admin ({role})")
|
||||
check(role == SHARED_ROLES[name],
|
||||
f"{name} logs in as {role or 'no user'}, but Parafa's role there is {SHARED_ROLES[name]}: "
|
||||
f"{name} logs in as {role or 'no user'}, but Workflow's role there is {SHARED_ROLES[name]}: "
|
||||
"role names are cluster-wide in the shared database, and the runtime-grants migration grants "
|
||||
"whichever role it is given, so another app's role would carry privileges between schemas",
|
||||
f"{name} logs in as Parafa's own role ({role})")
|
||||
f"{name} logs in as Workflow's own role ({role})")
|
||||
check(url["port"] != 6543,
|
||||
f"{name} uses port 6543, a pooler's transaction mode: use session mode (5432)",
|
||||
f"{name} avoids a transaction-mode pooler port (port {url['port']})")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Two tiers, on purpose. Unit tests are DB-free and always run, so `pytest` is green on a laptop
|
||||
with no Postgres. Integration tests need a migrated + seeded database and are opted into with
|
||||
PARAFA_RUN_INTEGRATION=1 — a suite that fails by default because of missing
|
||||
WORKFLOW_RUN_INTEGRATION=1 — a suite that fails by default because of missing
|
||||
infrastructure is one people stop running.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -13,11 +13,11 @@ import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
RUN_INTEGRATION = os.environ.get("PARAFA_RUN_INTEGRATION") == "1"
|
||||
RUN_INTEGRATION = os.environ.get("WORKFLOW_RUN_INTEGRATION") == "1"
|
||||
|
||||
integration = pytest.mark.skipif(
|
||||
not RUN_INTEGRATION,
|
||||
reason="set PARAFA_RUN_INTEGRATION=1 with a migrated Postgres to run these",
|
||||
reason="set WORKFLOW_RUN_INTEGRATION=1 with a migrated Postgres to run these",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ def test_a_generated_app_is_standalone_until_somebody_says_otherwise():
|
||||
assert s.identity_schema == ""
|
||||
assert s.shares_identity is False
|
||||
assert s.identity_hub_url == ""
|
||||
assert s.session_cookie_name == "parafa_session"
|
||||
assert s.session_cookie_name == "workflow_session"
|
||||
|
||||
|
||||
def test_one_setting_is_the_whole_switch():
|
||||
@@ -139,7 +139,7 @@ def test_a_module_signs_nobody_in_and_writes_no_accounts(monkeypatch):
|
||||
assert policy.app_tokens_enabled is False
|
||||
# And the per-module permissions wake up, keyed by this module's own slug.
|
||||
assert moderation_shim.POLICY.shared_permissions is True
|
||||
assert moderation_shim.POLICY.module_slug == "parafa"
|
||||
assert moderation_shim.POLICY.module_slug == "workflow"
|
||||
# A module never writes them. If it could, a compromised module could admit anyone, promote
|
||||
# anyone and promote itself, and the hub could neither see it nor take it back.
|
||||
assert moderation_shim.POLICY.permission_writes_enabled is False
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""The API against a real, migrated and seeded Postgres — run as the least-privilege `app` role.
|
||||
|
||||
Opt in with PARAFA_RUN_INTEGRATION=1 (CI does). Names are suffixed per run and every
|
||||
Opt in with WORKFLOW_RUN_INTEGRATION=1 (CI does). Names are suffixed per run and every
|
||||
setting a test changes is put back, so the suite can be re-run against the same database: users
|
||||
cannot be deleted, only deactivated, and nothing here depends on a clean slate.
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ PASSWORD = "s3cret-pw-9f1c"
|
||||
|
||||
|
||||
def _url(user: str, hostport: str, query: str = "") -> str:
|
||||
return f"postgresql+pg8000://{user}:{PASSWORD}@{hostport}/parafa{query}"
|
||||
return f"postgresql+pg8000://{user}:{PASSWORD}@{hostport}/workflow{query}"
|
||||
|
||||
|
||||
def _settings(**values) -> Settings:
|
||||
|
||||
+46
-46
@@ -1,24 +1,24 @@
|
||||
# Parafa in the family's shared managed database
|
||||
# Workflow in the family's shared managed database
|
||||
|
||||
The Dredd family can run in **one managed PostgreSQL database** — one Postgres 16/17 database at a
|
||||
managed provider, one schema and two roles per app — with Atrium as the hub and every other app
|
||||
(Galena, Sygna, Counsel Scorecard, and now Parafa) as its modules. The provider hosts only the
|
||||
database; Parafa's backend still runs on your own server with Docker Compose. The same steps work
|
||||
(Galena, Sygna, Counsel Scorecard, and now Workflow) as its modules. The provider hosts only the
|
||||
database; Workflow's backend still runs on your own server with Docker Compose. The same steps work
|
||||
against any PostgreSQL 16/17 whose admin may create roles and schemas.
|
||||
|
||||
Step 0 applies to the whole database, so do it once, whichever app you deploy first. The family runbook
|
||||
in the Atrium repository (`deploy/README.md`) covers it in more depth; the checklist below is the
|
||||
minimum and works on its own. Steps 1 to 5 cover only Parafa's part.
|
||||
minimum and works on its own. Steps 1 to 5 cover only Workflow's part.
|
||||
|
||||
## 0. The database itself (once, for every app)
|
||||
|
||||
- **Create the database** at the provider: Postgres 16 or 17, in a region close to your container hosts.
|
||||
Keep the platform admin's password (the provider's `postgres` role, usually not a superuser there) in
|
||||
your secret store. Parafa uses it only for provisioning (step 1).
|
||||
your secret store. Workflow uses it only for provisioning (step 1).
|
||||
- **Keep the schemas out of any auto-generated API.** Some providers expose tables through an
|
||||
auto-generated HTTP API that connects as `anon` / `authenticated` / `service_role` and exposes `public`
|
||||
by default. Switch such an API off, or never add an app schema to it. The backends connect to Postgres
|
||||
directly; `0002` and step 4's check also make sure those roles hold nothing in `parafa`.
|
||||
directly; `0002` and step 4's check also make sure those roles hold nothing in `workflow`.
|
||||
- **Enforce TLS** on the server side if the provider offers a setting for it, so no client can connect in
|
||||
plaintext. Changing it may briefly restart the database.
|
||||
- **Download the provider's root CA** from its dashboard (skip this if the server's certificate chains to
|
||||
@@ -35,14 +35,14 @@ minimum and works on its own. Steps 1 to 5 cover only Parafa's part.
|
||||
`--reset-passwords`, and each other app's equivalent), because a restore may drop custom role
|
||||
passwords, and run every app's check (step 4) before you start the backends.
|
||||
|
||||
## What Parafa gets
|
||||
## What Workflow gets
|
||||
|
||||
| | Parafa |
|
||||
| | Workflow |
|
||||
|---|---|
|
||||
| Schema | `parafa` (never `public`), owned by the migrator; `PUBLIC` holds nothing on it |
|
||||
| Migrator role | `parafa_migrator`: owns every object; used only by `alembic upgrade head` in the one-shot `migrate` service. Its `statement_timeout` is `30min`, because a provider may cap statements at a couple of minutes, which is too short for a migration |
|
||||
| Runtime role | `parafa_app`: DML only, no `UPDATE` / `DELETE` / `TRUNCATE` on `audit_log`; the backend's only login |
|
||||
| Extensions | none. `gen_random_uuid()` is core PostgreSQL, and `0001`'s `CREATE EXTENSION IF NOT EXISTS pgcrypto` is a no-op where the provider keeps a copy in `extensions` |
|
||||
| Schema | `workflow` (never `public`), owned by the migrator; `PUBLIC` holds nothing on it |
|
||||
| Migrator role | `workflow_migrator`: owns every object; used only by `alembic upgrade head` in the one-shot `migrate` service. Its `statement_timeout` is `30min`, because a provider may cap statements at a couple of minutes, which is too short for a migration |
|
||||
| Runtime role | `workflow_app`: DML only, no `UPDATE` / `DELETE` / `TRUNCATE` on `audit_log`; the backend's only login |
|
||||
| Extensions | `pgcrypto`, created by provisioning in schema `extensions` (the platform rendering the family plan prescribes); `0001`'s `CREATE EXTENSION IF NOT EXISTS pgcrypto` is then a no-op |
|
||||
| Shared identity | **only if this app joins a platform** (section 6): `USAGE` on a neutral schema the hub owns, plus a column-restricted read of the accounts in it. Never ownership, never `CREATE`, never an `INSERT` |
|
||||
|
||||
Role names are cluster-wide, so they carry the app's name: with a generic `app` / `migrator`, one app's
|
||||
@@ -50,7 +50,7 @@ migration could grant back what another app revoked, and one password would open
|
||||
create plain `app` or `migrator` roles in the shared database** — those names are for the local stack
|
||||
and CI only.
|
||||
|
||||
## 1. Provision Parafa (once, as the platform admin)
|
||||
## 1. Provision Workflow (once, as the platform admin)
|
||||
|
||||
dredd-core owns the provisioning routine; nothing here is hand-written SQL.
|
||||
|
||||
@@ -59,19 +59,19 @@ from environment variables, go to the server as SCRAM verifiers, and are never p
|
||||
|
||||
```bash
|
||||
python -c "import secrets; print(secrets.token_urlsafe(32))" # once per role: URL-safe, no encoding later
|
||||
read -rs PARAFA_MIGRATOR_PASSWORD && export PARAFA_MIGRATOR_PASSWORD
|
||||
read -rs PARAFA_APP_PASSWORD && export PARAFA_APP_PASSWORD
|
||||
read -rs WORKFLOW_MIGRATOR_PASSWORD && export WORKFLOW_MIGRATOR_PASSWORD
|
||||
read -rs WORKFLOW_APP_PASSWORD && export WORKFLOW_APP_PASSWORD
|
||||
read -rs ADMIN_DATABASE_URL && export ADMIN_DATABASE_URL
|
||||
# postgresql+pg8000://postgres.<tenant>:<admin-password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=./certs/db-ca.crt
|
||||
|
||||
python -m dredd_core.managed provision --admin-url ADMIN_DATABASE_URL \
|
||||
--schema parafa --app-role parafa_app --migrator-role parafa_migrator \
|
||||
--migrator-password-env PARAFA_MIGRATOR_PASSWORD --app-password-env PARAFA_APP_PASSWORD
|
||||
--schema workflow --app-role workflow_app --migrator-role workflow_migrator \
|
||||
--extension pgcrypto --migrator-password-env WORKFLOW_MIGRATOR_PASSWORD --app-password-env WORKFLOW_APP_PASSWORD
|
||||
```
|
||||
|
||||
In one transaction it creates both roles as plain `LOGIN` roles and schema `parafa` owned by the
|
||||
In one transaction it creates both roles as plain `LOGIN` roles and schema `workflow` owned by the
|
||||
migrator; gives `PUBLIC` nothing on the schema and the runtime role `USAGE`; grants both roles `USAGE`
|
||||
on `extensions` and sets `search_path = parafa, extensions` (the migrator also gets
|
||||
on `extensions` and sets `search_path = workflow, extensions` (the migrator also gets
|
||||
`statement_timeout = 30min`); then revokes the admin's temporary membership in the migrator, which
|
||||
removes its standing `SET ROLE` path to the migrator, and verifies the result. That revoke is not a
|
||||
wall: the admin keeps `ADMIN OPTION` on the roles it created and can grant itself membership again, so
|
||||
@@ -89,12 +89,12 @@ avoids.
|
||||
(CI's `managed-db` job runs the same command with `--check-file` and fails when the file is stale):
|
||||
|
||||
```bash
|
||||
python -m dredd_core.managed provision --sql-only --schema parafa --app-role parafa_app \
|
||||
--migrator-role parafa_migrator --identity-schema dredd --identity-owner atrium_migrator \
|
||||
python -m dredd_core.managed provision --sql-only --schema workflow --app-role workflow_app \
|
||||
--migrator-role workflow_migrator --extension pgcrypto --identity-schema dredd --identity-owner atrium_migrator \
|
||||
--output db/managed/provision.sql
|
||||
```
|
||||
|
||||
The committed file is the **platform** rendering: Parafa is split out of Compass (work package M6)
|
||||
The committed file is the **platform** rendering: Workflow is split out of Compass
|
||||
to run as a module of Atrium, so it ships with the identity flags, exactly as Galena, Sygna,
|
||||
Counsel, Lexicon and Agora do, and CI's `--check-file` step passes the same two flags. A standalone
|
||||
deployment renders without `--identity-schema` / `--identity-owner` (and must then not use the
|
||||
@@ -112,9 +112,9 @@ Replace the Database settings with the commented "managed PostgreSQL" block in
|
||||
|
||||
```dotenv
|
||||
MANAGED_DB_CA_FILE=./certs/db-ca.crt
|
||||
DATABASE_URL=postgresql+pg8000://parafa_app.<tenant>:<password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
MIGRATION_DATABASE_URL=postgresql+pg8000://parafa_migrator.<tenant>:<password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
DB_APP_ROLE=parafa_app
|
||||
DATABASE_URL=postgresql+pg8000://workflow_app.<tenant>:<password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
MIGRATION_DATABASE_URL=postgresql+pg8000://workflow_migrator.<tenant>:<password>@<host>:5432/postgres?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt
|
||||
DB_APP_ROLE=workflow_app
|
||||
# the connection budget below
|
||||
DB_POOL_SIZE=4
|
||||
DB_MAX_OVERFLOW=8
|
||||
@@ -150,20 +150,20 @@ DB_MAX_OVERFLOW=8
|
||||
DB_MAX_OVERFLOW + 1` per app (the busy backend plus a seed, `migrate` or check beside it), and keep
|
||||
the apps' total at or below about 80% of the limit: 72 of 90, 48 of 60.
|
||||
- **Five apps do not fit a 90-connection limit at the defaults**: Atrium, Galena, Sygna, Counsel
|
||||
Scorecard and Parafa at `5` / `10` take 5 × (15 + 1) = 80. Set `DB_POOL_SIZE=4` and
|
||||
Scorecard and Workflow at `5` / `10` take 5 × (15 + 1) = 80. Set `DB_POOL_SIZE=4` and
|
||||
`DB_MAX_OVERFLOW=8` in **every** app, 5 × (12 + 1) = 65, or size the instance for more.
|
||||
- With a **60-connection limit**, set `DB_POOL_SIZE=3` and `DB_MAX_OVERFLOW=2` in every app: 5 × (5 + 1)
|
||||
= 30.
|
||||
- Through a pooler in session mode, each client keeps its connection, so the pooler's own pool size
|
||||
(per user + database) must be at least `DB_POOL_SIZE + DB_MAX_OVERFLOW + 1`. With less, the extra
|
||||
client queues and then fails.
|
||||
- The family runbook's connection table counts four apps: add Parafa's row there, and change the
|
||||
- The family runbook's connection table counts four apps: add Workflow's row there, and change the
|
||||
other apps' `.env` files to match.
|
||||
|
||||
Then run the pre-flight (`--env` checks another file): `python backend/scripts/deploy_check.py`. For an
|
||||
external `DATABASE_URL` it also checks both URLs — `sslmode=verify-full`, and `sslrootcert` at the
|
||||
mounted CA when given; the roles are exactly `parafa_app` (`DATABASE_URL`) and
|
||||
`parafa_migrator` (`MIGRATION_DATABASE_URL`), never `postgres` or another platform role, a sibling
|
||||
mounted CA when given; the roles are exactly `workflow_app` (`DATABASE_URL`) and
|
||||
`workflow_migrator` (`MIGRATION_DATABASE_URL`), never `postgres` or another platform role, a sibling
|
||||
app's roles or a generic `app` / `migrator`; not port 6543; a percent-encoded password and no
|
||||
`<placeholder>`; different migrator and runtime roles; `DB_APP_ROLE` matching the runtime role; a bounded
|
||||
pool; and that the CA file exists when the URLs name one. Compose does not run it, so run it yourself.
|
||||
@@ -178,13 +178,13 @@ DREDD_CORE_TOKEN=github_pat_... \
|
||||
[`docker-compose.managed-db.yml`](../../docker-compose.managed-db.yml) switches the local `postgres` off,
|
||||
stops `migrate` waiting for it, and mounts the CA into `migrate` and `backend`.
|
||||
|
||||
- **`migrate`** runs `alembic upgrade head` as `parafa_migrator`. Through the role's `search_path`,
|
||||
every table, enum type and `alembic_version` lands in `parafa` with nothing schema-qualified in
|
||||
- **`migrate`** runs `alembic upgrade head` as `workflow_migrator`. Through the role's `search_path`,
|
||||
every table, enum type and `alembic_version` lands in `workflow` with nothing schema-qualified in
|
||||
code; a sibling's same-named `audit_log`, `app_user` or `node_role` in its own schema does not make a
|
||||
table or type here get skipped. `0002` then grants `DB_APP_ROLE` its privileges, strips the API roles,
|
||||
and verifies the result. **The seed** then runs as `parafa_app`.
|
||||
and verifies the result. **The seed** then runs as `workflow_app`.
|
||||
- **`backend`** gets a blank `MIGRATION_DATABASE_URL` (and blank local-postgres passwords), so the
|
||||
long-running process can only log in as `parafa_app`. This skeleton never needs the migrator at
|
||||
long-running process can only log in as `workflow_app`. This skeleton never needs the migrator at
|
||||
runtime. If you add an in-app restore (as Galena and Sygna have), keeping the migrator's URL in the
|
||||
backend is an explicit opt-in; prefer a one-shot restore container
|
||||
(`docker compose -f … -f … run --rm -e MIGRATION_DATABASE_URL=… backend python -m <restore>`).
|
||||
@@ -205,17 +205,17 @@ and the CA at the path they name, which a shell on the host has neither of.
|
||||
```bash
|
||||
for url in DATABASE_URL MIGRATION_DATABASE_URL; do
|
||||
docker compose -f docker-compose.yml -f docker-compose.managed-db.yml run --rm --no-deps migrate \
|
||||
python -m dredd_core.managed check --url "$url" --expect-schema parafa --require-tls \
|
||||
--app-role parafa_app --migrator-role parafa_migrator --append-only audit_log
|
||||
python -m dredd_core.managed check --url "$url" --expect-schema workflow --require-tls \
|
||||
--app-role workflow_app --migrator-role workflow_migrator --append-only audit_log
|
||||
done
|
||||
```
|
||||
|
||||
It only reads, and fails (exit 1) unless: TLS is on from both ends; the connected role is neither a
|
||||
superuser nor the platform admin; the current schema is `parafa` and `search_path` starts with it;
|
||||
superuser nor the platform admin; the current schema is `workflow` and `search_path` starts with it;
|
||||
the migrator owns the schema and no table belongs to a superuser or the platform admin;
|
||||
`parafa_app` cannot modify `audit_log`; **isolation**
|
||||
`workflow_app` cannot modify `audit_log`; **isolation**
|
||||
— neither role holds `USAGE`, `CREATE`, ownership or an object privilege in any other app's schema;
|
||||
and `anon`, `authenticated` and `service_role` hold nothing in `parafa`. Keep `--append-only` /
|
||||
and `anon`, `authenticated` and `service_role` hold nothing in `workflow`. Keep `--append-only` /
|
||||
`--no-delete` in step with `APPEND_ONLY_TABLES` / `NO_DELETE_TABLES` in `backend/app/models/__init__.py`.
|
||||
A provider whose platform keeps further schemas of its own in the database: name them with
|
||||
`--system-schema NAME ...` so the isolation check skips them.
|
||||
@@ -231,7 +231,7 @@ the direct connection, keep `--require-tls`.
|
||||
A point-in-time or backup restore at the provider rewinds **every app in the database together** —
|
||||
there is no per-app database restore (an app's own backup/export is the only per-app path). Follow the
|
||||
family runbook's restore procedure (stop every backend, restore, reset custom-role passwords, start).
|
||||
For Parafa that means:
|
||||
For Workflow that means:
|
||||
|
||||
1. Reset both passwords — a provider's restore may drop custom role passwords — by re-running step 1
|
||||
with the passwords from your secret store and `--reset-passwords`. It changes nothing else.
|
||||
@@ -251,7 +251,7 @@ connection to Postgres uses TLS (section 4's `--require-tls`).
|
||||
|
||||
Everything above is true whether or not this app shares a roster. This section is the one change
|
||||
that makes it a **module** of a platform rather than an app that merely lives next door: `app_user`,
|
||||
`session` and `module_permission` move out of `parafa` into a neutral schema the hub owns, and
|
||||
`session` and `module_permission` move out of `workflow` into a neutral schema the hub owns, and
|
||||
this app reads them. One person, one account, one password, one sign-in — and because the family
|
||||
runs at ONE origin, the cookie they got at the hub already arrives here. There is nothing to hand
|
||||
over and nothing to sign.
|
||||
@@ -273,14 +273,14 @@ Two extra flags on step 1's command, and on the `--sql-only` re-render:
|
||||
|
||||
```bash
|
||||
python -m dredd_core.managed provision --admin-url ADMIN_DATABASE_URL \
|
||||
--schema parafa --app-role parafa_app --migrator-role parafa_migrator \
|
||||
--identity-schema dredd --identity-owner atrium_migrator \
|
||||
--migrator-password-env PARAFA_MIGRATOR_PASSWORD --app-password-env PARAFA_APP_PASSWORD
|
||||
--schema workflow --app-role workflow_app --migrator-role workflow_migrator \
|
||||
--extension pgcrypto --identity-schema dredd --identity-owner atrium_migrator \
|
||||
--migrator-password-env WORKFLOW_MIGRATOR_PASSWORD --app-password-env WORKFLOW_APP_PASSWORD
|
||||
```
|
||||
|
||||
It grants this app's two roles `USAGE` on `dredd` — **only its own two**, so the
|
||||
grants accumulate one provisioning run per app and no script ever has to enumerate every role on the
|
||||
platform — and changes the `search_path` to `parafa, dredd, extensions`. It does
|
||||
platform — and changes the `search_path` to `workflow, dredd, extensions`. It does
|
||||
**not** create the schema: that happens on the owning app's own run, and a module provisioned before
|
||||
its owner is refused by name rather than left half-configured.
|
||||
|
||||
@@ -305,7 +305,7 @@ refuses by name if it finds the tables missing, which is the loud version of the
|
||||
|
||||
What this app ends up holding, and nothing more:
|
||||
|
||||
| on | `parafa_app` (runtime) | `parafa_migrator` |
|
||||
| on | `workflow_app` (runtime) | `workflow_migrator` |
|
||||
|---|---|---|
|
||||
| `app_user` | `SELECT` on the ordinary columns only — **nothing at all** on `password_hash`, `failed_login_count`, `locked_until` | `SELECT`, `REFERENCES` (it re-points foreign keys) |
|
||||
| `session` | `SELECT`, and `UPDATE` on `last_seen_at` / `expires_at` / `revoked_at` | nothing |
|
||||
@@ -322,7 +322,7 @@ anyone and promote itself. The console's 409s are politeness; this table is the
|
||||
Run a census first — one `SELECT id, email, is_admin, is_active` per schema's `app_user` — and
|
||||
compare by lower-cased e-mail. Anybody present here and absent there must be created in the hub
|
||||
**before** step 6.4, because neither side can do it: this app's migrator holds no `INSERT` on the
|
||||
shared `app_user`, and the hub's migrator holds nothing in `parafa` to read from. It is a
|
||||
shared `app_user`, and the hub's migrator holds nothing in `workflow` to read from. It is a
|
||||
platform-admin step, run by eye, and on a freshly seeded pair of apps it is usually zero rows.
|
||||
|
||||
Anybody who administered *this* app and is not a platform administrator will come out an ordinary
|
||||
|
||||
+46
-43
@@ -1,17 +1,17 @@
|
||||
-- =================================================================================================
|
||||
-- Managed Postgres provisioning for one app of the family, in the shared database:
|
||||
-- schema parafa, migrator parafa_migrator, app parafa_app, extensions: none, migrator statement_timeout 30min
|
||||
-- search_path parafa, dredd, extensions; shared identity schema dredd, owned by atrium_migrator (created by its owner, USAGE only here)
|
||||
-- schema workflow, migrator workflow_migrator, app workflow_app, extensions: pgcrypto, migrator statement_timeout 30min
|
||||
-- search_path workflow, dredd, extensions; shared identity schema dredd, owned by atrium_migrator (created by its owner, USAGE only here)
|
||||
--
|
||||
-- Rendered by dredd-core. Do not edit: re-render, and let CI check it is current (exit 1 = stale):
|
||||
-- python -m dredd_core.managed provision --sql-only \
|
||||
-- --schema parafa --app-role parafa_app --migrator-role parafa_migrator --identity-schema dredd --identity-owner atrium_migrator \
|
||||
-- --schema workflow --app-role workflow_app --migrator-role workflow_migrator --extension pgcrypto --identity-schema dredd --identity-owner atrium_migrator \
|
||||
-- --output db/managed/provision.sql (CI: --check-file db/managed/provision.sql)
|
||||
--
|
||||
-- Preferred path, from a shell (passwords come from environment variables and are never printed):
|
||||
-- python -m dredd_core.managed provision --admin-url ADMIN_DATABASE_URL \
|
||||
-- --schema parafa --app-role parafa_app --migrator-role parafa_migrator --identity-schema dredd --identity-owner atrium_migrator \
|
||||
-- --migrator-password-env PARAFA_MIGRATOR_PASSWORD --app-password-env PARAFA_APP_PASSWORD
|
||||
-- --schema workflow --app-role workflow_app --migrator-role workflow_migrator --extension pgcrypto --identity-schema dredd --identity-owner atrium_migrator \
|
||||
-- --migrator-password-env WORKFLOW_MIGRATOR_PASSWORD --app-password-env WORKFLOW_APP_PASSWORD
|
||||
--
|
||||
-- SQL editor path (no shell): paste this whole file into the provider's SQL editor, replace both
|
||||
-- change_me passwords in step 2 there (never in the committed file; at least 16 printable ASCII
|
||||
@@ -25,11 +25,11 @@ BEGIN;
|
||||
-- 1. preflight: refuse a connection, schema, role or extension this must not touch
|
||||
DO $dredd_provision_preflight$
|
||||
DECLARE
|
||||
target_schema text := 'parafa';
|
||||
migrator_role text := 'parafa_migrator';
|
||||
app_role text := 'parafa_app';
|
||||
target_schema text := 'workflow';
|
||||
migrator_role text := 'workflow_migrator';
|
||||
app_role text := 'workflow_app';
|
||||
admin_roles text[] := ARRAY['postgres', 'postgres_managed']::text[];
|
||||
extension_names text[] := '{}'::text[];
|
||||
extension_names text[] := ARRAY['pgcrypto']::text[];
|
||||
identity_schema text := 'dredd';
|
||||
identity_owner text := 'atrium_migrator';
|
||||
owns_identity boolean := false;
|
||||
@@ -118,11 +118,11 @@ BEGIN
|
||||
END
|
||||
$dredd_provision_preflight$;
|
||||
|
||||
-- 2. roles: create parafa_migrator and parafa_app (plain LOGIN roles) where missing
|
||||
-- 2. roles: create workflow_migrator and workflow_app (plain LOGIN roles) where missing
|
||||
DO $dredd_provision_roles$
|
||||
DECLARE
|
||||
migrator_role text := 'parafa_migrator';
|
||||
app_role text := 'parafa_app';
|
||||
migrator_role text := 'workflow_migrator';
|
||||
app_role text := 'workflow_app';
|
||||
migrator_password text := 'change_me'; -- replace change_me here (in the SQL editor, never in the committed file)
|
||||
app_password text := 'change_me'; -- replace change_me here (in the SQL editor, never in the committed file)
|
||||
reset_passwords boolean := false; -- true: also set the password of a role that already exists
|
||||
@@ -167,26 +167,26 @@ BEGIN
|
||||
END
|
||||
$dredd_provision_roles$;
|
||||
|
||||
-- 3. temporary membership: PostgreSQL 16+ needs SET on parafa_migrator to hand it a schema
|
||||
GRANT parafa_migrator TO CURRENT_USER;
|
||||
-- 3. temporary membership: PostgreSQL 16+ needs SET on workflow_migrator to hand it a schema
|
||||
GRANT workflow_migrator TO CURRENT_USER;
|
||||
|
||||
-- 4. schema parafa, owned by parafa_migrator
|
||||
CREATE SCHEMA IF NOT EXISTS parafa AUTHORIZATION parafa_migrator;
|
||||
-- 4. schema workflow, owned by workflow_migrator
|
||||
CREATE SCHEMA IF NOT EXISTS workflow AUTHORIZATION workflow_migrator;
|
||||
|
||||
-- 5. schema parafa: nothing for PUBLIC
|
||||
REVOKE ALL ON SCHEMA parafa FROM PUBLIC;
|
||||
-- 5. schema workflow: nothing for PUBLIC
|
||||
REVOKE ALL ON SCHEMA workflow FROM PUBLIC;
|
||||
|
||||
-- 6. schema parafa: USAGE for parafa_app
|
||||
GRANT USAGE ON SCHEMA parafa TO parafa_app;
|
||||
-- 6. schema workflow: USAGE for workflow_app
|
||||
GRANT USAGE ON SCHEMA workflow TO workflow_app;
|
||||
|
||||
-- 7. schema extensions: USAGE for parafa_migrator and parafa_app
|
||||
GRANT USAGE ON SCHEMA extensions TO parafa_migrator, parafa_app;
|
||||
-- 7. schema extensions: USAGE for workflow_migrator and workflow_app
|
||||
GRANT USAGE ON SCHEMA extensions TO workflow_migrator, workflow_app;
|
||||
|
||||
-- 8. schema extensions: check that the USAGE grant took
|
||||
DO $dredd_provision_extensions_usage$
|
||||
DECLARE
|
||||
migrator_role text := 'parafa_migrator';
|
||||
app_role text := 'parafa_app';
|
||||
migrator_role text := 'workflow_migrator';
|
||||
app_role text := 'workflow_app';
|
||||
BEGIN
|
||||
IF NOT (has_schema_privilege(migrator_role, 'extensions', 'USAGE')
|
||||
AND has_schema_privilege(app_role, 'extensions', 'USAGE')) THEN
|
||||
@@ -203,15 +203,15 @@ $dredd_provision_extensions_usage$;
|
||||
-- 9. temporary membership in the identity owner atrium_migrator: needed to grant on dredd
|
||||
GRANT atrium_migrator TO CURRENT_USER;
|
||||
|
||||
-- 10. schema dredd: USAGE for parafa_migrator and parafa_app
|
||||
GRANT USAGE ON SCHEMA dredd TO parafa_migrator, parafa_app;
|
||||
-- 10. schema dredd: USAGE for workflow_migrator and workflow_app
|
||||
GRANT USAGE ON SCHEMA dredd TO workflow_migrator, workflow_app;
|
||||
|
||||
-- 11. schema dredd: check that the USAGE grant took
|
||||
DO $dredd_provision_identity_usage$
|
||||
DECLARE
|
||||
identity_schema text := 'dredd';
|
||||
migrator_role text := 'parafa_migrator';
|
||||
app_role text := 'parafa_app';
|
||||
migrator_role text := 'workflow_migrator';
|
||||
app_role text := 'workflow_app';
|
||||
identity_owner text := 'atrium_migrator';
|
||||
BEGIN
|
||||
IF NOT (has_schema_privilege(migrator_role, identity_schema, 'USAGE')
|
||||
@@ -228,30 +228,33 @@ BEGIN
|
||||
END
|
||||
$dredd_provision_identity_usage$;
|
||||
|
||||
-- 12. search_path of parafa_migrator
|
||||
ALTER ROLE parafa_migrator SET search_path = parafa, dredd, extensions;
|
||||
-- 12. search_path of workflow_migrator
|
||||
ALTER ROLE workflow_migrator SET search_path = workflow, dredd, extensions;
|
||||
|
||||
-- 13. search_path of parafa_app
|
||||
ALTER ROLE parafa_app SET search_path = parafa, dredd, extensions;
|
||||
-- 13. search_path of workflow_app
|
||||
ALTER ROLE workflow_app SET search_path = workflow, dredd, extensions;
|
||||
|
||||
-- 14. statement_timeout of parafa_migrator
|
||||
ALTER ROLE parafa_migrator SET statement_timeout = '30min';
|
||||
-- 14. statement_timeout of workflow_migrator
|
||||
ALTER ROLE workflow_migrator SET statement_timeout = '30min';
|
||||
|
||||
-- 15. end the temporary membership: no standing SET ROLE parafa_migrator for the admin
|
||||
REVOKE parafa_migrator FROM CURRENT_USER;
|
||||
-- 15. extension pgcrypto in schema extensions
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA extensions;
|
||||
|
||||
-- 16. end the temporary membership in atrium_migrator
|
||||
-- 16. end the temporary membership: no standing SET ROLE workflow_migrator for the admin
|
||||
REVOKE workflow_migrator FROM CURRENT_USER;
|
||||
|
||||
-- 17. end the temporary membership in atrium_migrator
|
||||
REVOKE atrium_migrator FROM CURRENT_USER;
|
||||
|
||||
-- 17. verify the end state
|
||||
-- 18. verify the end state
|
||||
DO $dredd_provision_verify$
|
||||
DECLARE
|
||||
target_schema text := 'parafa';
|
||||
migrator_role text := 'parafa_migrator';
|
||||
app_role text := 'parafa_app';
|
||||
extension_names text[] := '{}'::text[];
|
||||
target_schema text := 'workflow';
|
||||
migrator_role text := 'workflow_migrator';
|
||||
app_role text := 'workflow_app';
|
||||
extension_names text[] := ARRAY['pgcrypto']::text[];
|
||||
timeout_setting text := 'statement_timeout=30min';
|
||||
path_setting text := 'search_path=parafa, dredd, extensions';
|
||||
path_setting text := 'search_path=workflow, dredd, extensions';
|
||||
identity_schema text := 'dredd';
|
||||
identity_owner text := 'atrium_migrator';
|
||||
admin_roles text[] := ARRAY['postgres', 'postgres_managed']::text[];
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Parafa on a managed PostgreSQL database (the family's shared one, or any Postgres 16/17 reached
|
||||
# Workflow on a managed PostgreSQL database (the family's shared one, or any Postgres 16/17 reached
|
||||
# over a network): an override for docker-compose.yml.
|
||||
#
|
||||
# DREDD_CORE_TOKEN=github_pat_... \
|
||||
# docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d --build
|
||||
#
|
||||
# The database lives elsewhere — the family shares ONE managed database, and Parafa has schema
|
||||
# `parafa` in it — so the local postgres service is switched off and nothing waits for it;
|
||||
# migrate (+seed) and backend are otherwise unchanged. Provision Parafa first
|
||||
# The database lives elsewhere — the family shares ONE managed database, and Workflow has schema
|
||||
# `workflow` in it — so the local postgres service is switched off and nothing waits for it;
|
||||
# migrate (+seed) and backend are otherwise unchanged. Provision Workflow first
|
||||
# (db/managed/README.md), and give .env the database's URLs — the provider's host and port (through a
|
||||
# pooler, its session mode, never transaction mode), user names parafa_migrator /
|
||||
# parafa_app (with the `.<tenant>` suffix where the pooler wants one),
|
||||
# ?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt — plus DB_APP_ROLE=parafa_app.
|
||||
# pooler, its session mode, never transaction mode), user names workflow_migrator /
|
||||
# workflow_app (with the `.<tenant>` suffix where the pooler wants one),
|
||||
# ?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt — plus DB_APP_ROLE=workflow_app.
|
||||
# `python backend/scripts/deploy_check.py` checks the .env side before you start.
|
||||
#
|
||||
# Uses the !reset merge tag (docs.docker.com/reference/compose-file/merge/, "Reset value"), so it needs a
|
||||
@@ -33,9 +33,9 @@ services:
|
||||
depends_on: !reset null
|
||||
environment:
|
||||
# The one-shot migrate service keeps the whole .env: alembic runs as MIGRATION_DATABASE_URL's
|
||||
# parafa_migrator, the seed as DATABASE_URL's parafa_app. 0002_runtime_grants grants
|
||||
# workflow_migrator, the seed as DATABASE_URL's workflow_app. 0002_runtime_grants grants
|
||||
# the role DB_APP_ROLE names, so an unset DB_APP_ROLE stops here rather than inside the migration.
|
||||
DB_APP_ROLE: ${DB_APP_ROLE:?set DB_APP_ROLE in .env to the runtime role, parafa_app in the shared database}
|
||||
DB_APP_ROLE: ${DB_APP_ROLE:?set DB_APP_ROLE in .env to the runtime role, workflow_app in the shared database}
|
||||
volumes: &managed_db_ca
|
||||
# The provider's root CA (downloaded from its dashboard; when the server's certificate chains to
|
||||
# a public CA, drop this mount and the URLs' sslrootcert — verify-full then uses the system trust
|
||||
@@ -51,10 +51,10 @@ services:
|
||||
|
||||
backend:
|
||||
environment:
|
||||
# Least privilege: the long-running backend connects ONLY as parafa_app (DATABASE_URL).
|
||||
# Least privilege: the long-running backend connects ONLY as workflow_app (DATABASE_URL).
|
||||
# Blank the migrator's URL and the local-postgres passwords that `env_file: .env` would otherwise
|
||||
# inject (`environment:` wins over `env_file:`), so a compromised backend cannot log in as
|
||||
# parafa_migrator and rewrite audit_log. This skeleton never needs the migrator at runtime.
|
||||
# workflow_migrator and rewrite audit_log. This skeleton never needs the migrator at runtime.
|
||||
# An app that adds an in-app restore (Galena and Sygna have one) needs it there: keeping it is a
|
||||
# documented opt-in, and a one-shot restore container (`docker compose run --rm` with the
|
||||
# migrator's URL) is the recommended path.
|
||||
@@ -64,7 +64,7 @@ services:
|
||||
POSTGRES_PASSWORD: ""
|
||||
# Passed through explicitly so the running configuration is visible here. The pool bounds the
|
||||
# connections this backend takes from the shared database's limit (db/managed/README.md).
|
||||
DB_APP_ROLE: ${DB_APP_ROLE:?set DB_APP_ROLE in .env to the runtime role, parafa_app in the shared database}
|
||||
DB_APP_ROLE: ${DB_APP_ROLE:?set DB_APP_ROLE in .env to the runtime role, workflow_app in the shared database}
|
||||
DB_POOL_SIZE: ${DB_POOL_SIZE:-5}
|
||||
DB_MAX_OVERFLOW: ${DB_MAX_OVERFLOW:-10}
|
||||
volumes: *managed_db_ca
|
||||
|
||||
+12
-12
@@ -1,17 +1,17 @@
|
||||
# Parafa stack: postgres → migrate (+seed) → backend. No reverse proxy: the backend is its own
|
||||
# Workflow stack: postgres → migrate (+seed) → backend. No reverse proxy: the backend is its own
|
||||
# edge (app/edge.py) and serves the console. Only the backend is published; postgres is expose-only.
|
||||
#
|
||||
# Runs alongside a sibling's stack — different volumes, different DB name. Each app in the family
|
||||
# keeps its OWN database; what they share is the `dredd-core` package, not a cluster.
|
||||
#
|
||||
# Published on host port 8121 (the family's standalone ports: Galena 8021 · Sygna 8041 · Compass
|
||||
# 8061 · Counsel 8081 · Insider 8101, with 8092/8094 reserved · Parafa 8121). On the PLATFORM the
|
||||
# modules publish nothing; Atrium's front door forwards /parafa/* to the backend.
|
||||
# Published on host port 8141 (the family's standalone ports: Galena 8021 · Sygna 8041 · Compass
|
||||
# 8061 · Counsel 8081 · Insider 8101, with 8092/8094 reserved · signing 8121 · Scribe 8125 ·
|
||||
# Workflow 8141). On the PLATFORM the modules publish nothing; Atrium's front door forwards /workflow/* to the backend.
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:-parafa}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-workflow}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-change_me_super}
|
||||
DB_APP_PASSWORD: ${DB_APP_PASSWORD:-change_me_app}
|
||||
DB_MIGRATOR_PASSWORD: ${DB_MIGRATOR_PASSWORD:-change_me_migrator}
|
||||
@@ -20,7 +20,7 @@ services:
|
||||
- ./db/init:/docker-entrypoint-initdb.d:ro
|
||||
expose: ["5432"]
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d ${POSTGRES_DB:-parafa}"]
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d ${POSTGRES_DB:-workflow}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
@@ -30,12 +30,12 @@ services:
|
||||
context: ./backend
|
||||
additional_contexts: { frontend: ./frontend }
|
||||
secrets: [dredd_core_token]
|
||||
image: parafa-backend:local
|
||||
image: workflow-backend:local
|
||||
env_file: .env
|
||||
command: sh -c "alembic upgrade head && python -m app.seed"
|
||||
restart: "no"
|
||||
volumes:
|
||||
- parafa-data:/data
|
||||
- workflow-data:/data
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
@@ -45,19 +45,19 @@ services:
|
||||
context: ./backend
|
||||
additional_contexts: { frontend: ./frontend }
|
||||
secrets: [dredd_core_token]
|
||||
image: parafa-backend:local
|
||||
image: workflow-backend:local
|
||||
env_file: .env
|
||||
ports:
|
||||
- "${PARAFA_PORT:-8121}:8000"
|
||||
- "${WORKFLOW_PORT:-8141}:8000"
|
||||
volumes:
|
||||
- parafa-data:/data
|
||||
- workflow-data:/data
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
parafa-data:
|
||||
workflow-data:
|
||||
|
||||
secrets:
|
||||
# Used only by the build stage's one `pip install`; no running container gets it. Compose resolves
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* Parafa console.
|
||||
/* Workflow console.
|
||||
UI chrome stays monochrome (near-black light / near-white dark) — buttons, emphasis, text.
|
||||
The brand is Open Color **yellow #e67700** (yellow9; indigo is Arbiter's), and it is confined to things that read as
|
||||
an identity rather than a control: the app mark, icon tiles, the avatar, the focus ring. Nav
|
||||
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
/* Parafa console — vanilla JS, no build step.
|
||||
/* Workflow console — vanilla JS, no build step.
|
||||
Source strings are in the product's first language; I18N translates to the other. The
|
||||
mechanism (_tr / _trAttr / localize, matching on source text, with data-no-i18n opt-outs) is
|
||||
the same across the family — only the source language differs.
|
||||
@@ -11,14 +11,14 @@
|
||||
|
||||
/* The API base, derived from the document rather than hard-coded to the origin root. Served at the
|
||||
root (the standalone stack, ROOT_PATH empty) this is `/api/v1`; served under a path prefix as a
|
||||
module of a platform — one origin, one module per path — it is `/parafa/api/v1`, and every
|
||||
module of a platform — one origin, one module per path — it is `/workflow/api/v1`, and every
|
||||
`API + path` call site below is unchanged. This is the ONE line that makes the console portable
|
||||
across the prefix, and it only works because everything else here already is: every asset in
|
||||
index.html is document-relative and routing is hash-based. So: no leading-slash `src`, `href`,
|
||||
`fetch`, `location` or `window.open` anywhere in this console, ever.
|
||||
A fragment in the base is dropped by URL resolution, so a hash route resolves identically. It DOES
|
||||
depend on the trailing slash — bare `/parafa` would resolve to `/api/v1` — which is why a
|
||||
platform proxy must redirect `/parafa` to `/parafa/`. */
|
||||
depend on the trailing slash — bare `/workflow` would resolve to `/api/v1` — which is why a
|
||||
platform proxy must redirect `/workflow` to `/workflow/`. */
|
||||
const API = new URL('api/v1', document.baseURI).pathname;
|
||||
/* 'nodes' = records live in a permission tree; 'simple' = flat, owner-based. */
|
||||
const TENANCY = 'simple';
|
||||
@@ -155,7 +155,7 @@ function svg(p, w) {
|
||||
const TH = { system: ICN.desktop, light: ICN.sun, dark: ICN.moon };
|
||||
|
||||
function themeMode() {
|
||||
try { return localStorage.getItem('parafa_theme') || 'system'; } catch { return 'system'; }
|
||||
try { return localStorage.getItem('workflow_theme') || 'system'; } catch { return 'system'; }
|
||||
}
|
||||
function applyTheme(m) {
|
||||
const dark = m === 'dark' || (m === 'system' && matchMedia('(prefers-color-scheme:dark)').matches);
|
||||
@@ -164,7 +164,7 @@ function applyTheme(m) {
|
||||
}
|
||||
function cycleTheme() {
|
||||
const next = { system: 'light', light: 'dark', dark: 'system' }[themeMode()] || 'system';
|
||||
try { localStorage.setItem('parafa_theme', next); } catch { /* private mode */ }
|
||||
try { localStorage.setItem('workflow_theme', next); } catch { /* private mode */ }
|
||||
applyTheme(next);
|
||||
}
|
||||
/* "System" has to keep following the OS after load, not just at first paint: switching the OS to
|
||||
@@ -222,7 +222,7 @@ const I18N = {
|
||||
|
||||
let LANG = (function () {
|
||||
try {
|
||||
const s = localStorage.getItem('parafa_lang');
|
||||
const s = localStorage.getItem('workflow_lang');
|
||||
if (s === SRC_LANG || s === ALT_LANG) return s;
|
||||
} catch { /* private mode */ }
|
||||
return (navigator.language || SRC_LANG).toLowerCase().startsWith(SRC_LANG) ? SRC_LANG : ALT_LANG;
|
||||
@@ -267,7 +267,7 @@ function localize(root) {
|
||||
}
|
||||
function cycleLang() {
|
||||
LANG = LANG === SRC_LANG ? ALT_LANG : SRC_LANG;
|
||||
try { localStorage.setItem('parafa_lang', LANG); } catch { /* private mode */ }
|
||||
try { localStorage.setItem('workflow_lang', LANG); } catch { /* private mode */ }
|
||||
location.reload();
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -3,12 +3,12 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Parafa — System zarządzania</title>
|
||||
<title>Workflow — System zarządzania</title>
|
||||
<meta name="description" content="A self-hosted management console." />
|
||||
<meta name="robots" content="noindex" />
|
||||
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
|
||||
<script>/* set theme before first paint to avoid a flash */
|
||||
(function(){try{var m=localStorage.getItem('parafa_theme')||'system';
|
||||
(function(){try{var m=localStorage.getItem('workflow_theme')||'system';
|
||||
var dark=m==='dark'||(m==='system'&&window.matchMedia&&matchMedia('(prefers-color-scheme:dark)').matches);
|
||||
document.documentElement.dataset.theme=dark?'dark':'light';}catch(e){}})();</script>
|
||||
<link rel="stylesheet" href="app.css" />
|
||||
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
<form class="login-card" id="loginForm">
|
||||
<svg class="logo" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><rect x="2" y="2" width="20" height="20" rx="5" fill="#e67700"/><g stroke="#fff9db" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" fill="none"><path d="M7 12.5l3.2 3.2L17 9"/></g></svg>
|
||||
<h1>Parafa</h1>
|
||||
<h1>Workflow</h1>
|
||||
<div class="lsub">System zarządzania</div>
|
||||
<label class="field">E-mail <input id="email" type="email" autocomplete="username" /></label>
|
||||
<label class="field" style="margin-top:12px">Hasło
|
||||
@@ -49,7 +49,7 @@
|
||||
ours would bake its slug in here. Hidden, and empty of controls, unless the server says so. -->
|
||||
<div class="login-card hidden" id="hubCard">
|
||||
<svg class="logo" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><rect x="2" y="2" width="20" height="20" rx="5" fill="#e67700"/><g stroke="#fff9db" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" fill="none"><path d="M7 12.5l3.2 3.2L17 9"/></g></svg>
|
||||
<h1>Parafa</h1>
|
||||
<h1>Workflow</h1>
|
||||
<div class="lsub">System zarządzania</div>
|
||||
<p id="hubCopy" style="margin:18px 0 0;font-size:13px;line-height:1.55;color:var(--text-secondary)">
|
||||
<span>Jedno konto obejmuje tu wszystko.</span>
|
||||
@@ -65,7 +65,7 @@
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="brand">
|
||||
<svg class="logo" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><rect x="2" y="2" width="20" height="20" rx="5" fill="#e67700"/><g stroke="#fff9db" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" fill="none"><path d="M7 12.5l3.2 3.2L17 9"/></g></svg>
|
||||
<span class="nm">Parafa</span>
|
||||
<span class="nm">Workflow</span>
|
||||
</div>
|
||||
<nav class="nav" id="nav"></nav>
|
||||
<div class="nav sidebar-foot"><div class="nav-item" id="navAdmin"></div></div>
|
||||
|
||||
Reference in New Issue
Block a user