adminandClaude Opus 5.5 5374467df2
CI / backend (16) (push) Successful in 1m26s
CI / backend (17) (push) Successful in 1m31s
CI / managed-db (push) Successful in 1m35s
CI / compose-smoke (push) Successful in 2m1s
Fetch private dredd-core from the Haski Gitea, not GitHub
The Dockerfiles still rewrote credentials for github.com only, so the build
token never reached Gitea and installs worked only while dredd-core was
public. Rewrite http://77.216.148.202:3000/ instead, give every workflow
that pip-installs the same rewrite (org secret DREDD_CORE_TOKEN, the
read-only haski-reader token), and drop the GitHub PAT leftovers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 22:18:09 +01:00

Agora

Negocjacje umów — contract negotiations.

Agora is the family's contract negotiations module (Negocjacje), split out of Compass: a negotiation room on one document, the rounds each side sends, a word-level comparison of two Word rounds, and the team's internal comment thread. With Galena a room sits on a Galena document and every round is saved there as a new version of it, with the person's own account; without Galena the room and its rounds are plain files. A room is seen by its participants and the module's moderators.

Open questions for review [T]:

  • Comparison. The plan (Podgląd i porównanie) prefers ReaderJS's compare and drops compare.py "if ReaderJS covers its rules". It is kept for now: ReaderJS diffs extracted text word by word, while compare.py pairs reworded paragraphs, reads tracked changes as accepted, puts footnotes last and is hardened against XXE and zip bombs on the server. Agora also has no ReaderJS viewer yet. To decide: are those rules needed, or does ReaderJS suffice?
  • Access without Galena (P5): participants + moderators, as recommended. On a Galena room Galena's tree still decides on the bytes; the room list does not mirror it.
  • Event semantics: negotiation.round_received is written only for a round from the other side (the old G8 trigger), not for our own rounds.

Self-hosted and single-tenant, built on dredd-core — the shared substrate this app family installs as a dependency rather than copies.

Stack

FastAPI + SQLAlchemy 2 + Alembic + PostgreSQL 16 / 17, Argon2id password hashing, server-side cookie sessions, an append-only audit log enforced by database grants, RFC 9457 Problem Details errors, opt-in OpenTelemetry, and a no-build vanilla-JS console (Open Color palette, Tabler icons, light/dark theme, two languages). Shipped with Docker Compose; the backend is its own edge (no reverse proxy). Apache-2.0, and CI refuses any GPL/AGPL/SSPL dependency.

dredd-core

Identity and sessions, authentication, the access-control resolver, the org tree, the audit writer, the security primitives, the shared enums and error types, and the engine/session factories all come from one installed package. backend/requirements.txt pins it by tag:

dredd-core @ git+https://github.com/Alpaq92/dredd-core@v0.22.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 agora_pat_ token prefix, the agora_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.

dredd-core ships models, not migrations: importing it registers its tables on the shared metadata, and this repo owns its own 0001 (native enum types are created first, then create_all). A core upgrade that changes the schema needs a new revision here.

It is a private repository. Local installs use your own GitHub credentials; CI authenticates with a DREDD_CORE_TOKEN repository secret (a fine-grained PAT with read access to Alpaq92/dredd-core), which the workflow injects before pip install. Without it, the install step fails with an authentication error.

This app is its own deployment with its own domain data. It shares code with its siblings, not that data: locally it has its own database; in the family's shared managed database it has its own schema and roles, which no sibling's roles can reach.

Identity is the exception, and it is shared on purpose: the family's shape is one platform, one account, one admin pane — one origin, one module per path, where you sign in once at the hub and every module resolves the same session. Separate schemas, one roster. As scaffolded this app is standalone: it serves at the root of its own host with its own accounts, its own sign-in and its own Users administration, and it keeps running that way whatever the family does. Mounting it under a path prefix of a shared origin is one setting (ROOT_PATH, empty by default) and no code change.

Joining the platform

Sharing the roster is one more setting, IDENTITY_SCHEMA, plus three steps that are not this app's to take. Once it is set, app_user, session and module_permission live in a neutral schema the hub owns and this app reads: there is no password here, the sign-in screen becomes a link to the hub, creating or re-passwording an account answers 409 pointing there, and app tokens stay listable and revocable but are minted at the hub. And module_permission is what decides who may open this app at all — no row for this module is no entry — so the hub is where somebody is admitted to it and where somebody is made its moderator. Standalone that table is inert: there is one application, and having an account here is permission to use it. One origin means one cookie, so there is no handoff to build — no signed assertion, no audience binding, nothing to exchange. A design that adds one for this topology is over-engineering.

Both shapes are the same code, switched at runtime, and that is the property to defend: the moment they fork, the shape nobody runs locally is the shape that breaks.

The order matters, because only the last of the four steps happens in this repository:

  1. The platform admin provisions. db/managed/provision.sql, re-rendered with --identity-schema dredd --identity-owner atrium_migrator (commit it, and add the same flags to CI's --check-file step — the platform's push.sh refuses a module whose committed file is not that rendering): the schema, USAGE for this app's two roles, and a search_path that reaches it. A migrator role may do none of those. The kit also sets FRAME_ANCESTORS='self'.
  2. The hub migrates. It owns the schema, so it creates the three tables and grants this app's roles their tier — a column-restricted SELECT on app_user that does not include password_hash, SELECT plus a narrow UPDATE on session, SELECT and nothing else on module_permission, and INSERT on none of them.
  3. A person imports any account this app has and the hub does not. Neither side can do it alone, by design, so it is a platform-admin step run from a census of every schema's app_user.
  4. alembic upgrade head here runs 0003_shared_identity: it matches this schema's accounts to the shared ones by e-mail address, rewrites every id that names a person, re-points every foreign key, and drops the local copies. Read it before running it on anything you care about. Sessions and app tokens are deliberately not carried over — everybody signs in once more, at the hub.

Two administration tiers come with it, and these are the only two words for them: an administrator is platform-wide and is made in the hub; a moderator administers this module only, is also made in the hub, and is merely read here. Standalone they are the same thing and nothing queries anything.

Quick start

cp .env.example .env          # then set the three DB passwords
DREDD_CORE_TOKEN=github_pat_... docker compose up -d --build  # postgres -> migrate(+seed) -> backend

Building the image needs DREDD_CORE_TOKEN (a read-only fine-grained PAT for Alpaq92/dredd-core) in your shell — compose hands it to the build as a BuildKit secret, so it 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 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)). PowerShell's Out-File -Encoding utf8 adds one, and pydantic-settings folds it into the first key name, which produces a baffling "field required" error at startup.

Development

cd backend
python -m venv .venv && . .venv/Scripts/activate   # or: source .venv/bin/activate
pip install -r requirements-dev.txt      # pulls dredd-core from GitHub — needs repo access

pytest                                  # DB-free unit tests
alembic upgrade head --sql              # inspect the DDL without a database
python scripts/license_gate.py          # no GPL/AGPL/SSPL
python scripts/deploy_check.py          # stack-definition coherence
node --check ../frontend/app.js         # the console has no build step, so this is the check

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; Agora joins it as schema agora with its own roles agora_migrator and agora_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.

  • Database-wide steps (creating the database, the provider's root CA, keeping the schemas out of any auto-generated API, TLS enforcement, network restrictions, the connection budget, backups and point-in-time restore): step 0 of db/managed/README.md, and in more depth the family runbook in Atrium, deploy/README.md.
  • Agora's steps (provisioning with python -m dredd_core.managed provision or the rendered 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.
  • Connect through the provider's pooler in session mode (never a transaction-mode port such as 6543) or directly, as <role> — or <role>.<tenant> where the pooler wants the tenant in the user name — with ?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt. Never migrate as postgres.
  • The TLS rule: a database host that is not local ("", localhost, 127.0.0.1, ::1, postgres or a DB_LOCAL_HOSTS entry) must carry sslmode=verify-full, or the app refuses to start.

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 agora_app and runs the managed check.

Security model

Two Postgres roles do the heavy lifting. migrator owns DDL and is used only by Alembic; app is the runtime role and holds DML only. The migration then revokes UPDATE/DELETE on audit_log from app, which is what makes the audit log evidence rather than a convenience: a compromised application cannot rewrite its own history, because the database will not let it.

The runtime role's name is configuration (DB_APP_ROLE, app by default): the grants migration (0002_runtime_grants) grants to it and fails loudly — rolling back — when that role is missing, 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 (:80) — 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 dredd_core.authz in nodes tenancy, a local admin/owner check in simple tenancy. No access returns 404, not 403: a 403 confirms that the record the caller may not see exists.

Project layout

Path What
backend/app/models/ this app's ORM entities; __init__.py re-exports dredd-core's
backend/app/services/ every domain rule and all SQL; auth/audit are core shims (authz too, in nodes tenancy)
backend/app/routers/ HTTP shape, validation, authz calls — no SQL
backend/alembic/ 0001: enum types → create_all; 0002: runtime grants for DB_APP_ROLE
backend/scripts/ license gate, deploy pre-flight
frontend/ the console: index.html + app.css + app.js, no bundler
db/init/ least-privilege role creation for the local stack, run once by Postgres
db/managed/ the shared managed database: rendered provision.sql + this app's runbook
docker-compose.managed-db.yml override for a managed database: no local postgres, CA mounted, no migrator in the backend

License

Apache-2.0. See CREDITS.md for dependencies and design credits.

S
Description
No description provided
Readme
364 KiB
Languages
Python 77.1%
JavaScript 12.6%
CSS 4.6%
PLpgSQL 3.5%
HTML 1.2%
Other 1%