55 Commits
Author SHA1 Message Date
adminandClaude Opus 5.5 b1f8f9dfba CI: allow a manual run (Actions -> CI -> Run workflow)
CI / Tests (Postgres 17) (push) Successful in 4m58s
CI / Tests (Postgres 16) (push) Successful in 5m52s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:06:30 +01:00
adminandClaude Opus 5.5 b188f9cc18 CI: push runs only on main; branches are tested through their pull request [skip ci]
A push of many branches at once (the migration pushed 100 of Atrium's) started
a run per branch and flooded the runners. Every pull request is still tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:39:19 +01:00
admin 23c842b418 Merge pull request #8 from Alpaq92/fix/session-update-guard
CI / Tests (Postgres 16) (push) Successful in 9m10s
CI / Tests (Postgres 17) (push) Successful in 7m11s
session_update_guard_sql: a module never revives or prolongs a credential (0.26.1)
v0.26.1
2026-11-28 10:39:05 +01:00
Piotr ChojnackiandClaude Opus 5.5 32aa86682e session guard: keep each message one literal, so the SQL says what the test reads
CI / Tests (Postgres 16) (push) Failing after 3s
CI / Tests (Postgres 17) (push) Failing after 3s
The column message was split across two concatenated pieces of the trigger
body. PostgreSQL joined them at run time, so the raised text was right, but the
generated SQL never contained the sentence whole and
test_the_session_guard_is_one_statement_with_no_quote_escaping failed. This
suite had never been run before (CI does not start on the account).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 00:51:57 +01:00
Piotr ChojnackiandClaude Opus 5.5 433e083dae Merge main (0.26.0) into the session guard; ship it as 0.26.1
The chat contract took 0.26.0 while this PR waited. The guard's code merged
cleanly. The conflicts were the version and the release notes: the version is
now 0.26.1, and "0.26.1 notes" follow main's 0.26.0 section in README.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 00:45:16 +01:00
admin fb4867c1ad Merge pull request #7 from Alpaq92/feat/chat-contract
0.26.0: chat_contract, what a module tells the platform's chat (K4)
v0.26.0
2026-11-28 00:21:37 +01:00
Piotr ChojnackiandClaude Opus 5.5 b9d7f83b74 session_update_guard_sql: a module never revives or prolongs a credential (0.25.1)
The reader tier's UPDATE (last_seen_at, expires_at, revoked_at) on the shared
session table covers every row and every value, so any module role could set
revoked_at = NULL on a session the hub revoked, or push expires_at to infinity
on the administrator's session.

New schema.session_update_guard_sql(): a row-level BEFORE UPDATE trigger, run
from the identity owner's revision. For every role but the owner and the
writer it refuses a change to revoked_at once set, any later expires_at except
a live app token sliding to at most idle_days from now, and a change to any
other column. Sign-out, last_seen_at and the slide keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 23:31:11 +01:00
adminandClaude Opus 5.5 fbbbdbc53d fix(chat_contract): public link_ok, one limit rule, total required
CI / Tests (Postgres 17) (push) Failing after 2s
CI / Tests (Postgres 16) (push) Failing after 30s
search_contract.link_ok is public (the private _link_ok stays as an
alias) and chat/stats contracts use it. make_record cuts a long title at
a word like text, folds and filters members like labels, and names
MAX_MEMBER. make_page requires total, so pagination cannot stop
silently; a page without next_offset is refused by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 14:40:21 +01:00
adminandClaude Opus 5.5 6cd08ada43 fix(chat_contract): the module is a family slug (hyphens, never underscores)
From review: the regex let underscores through and refused a leading digit,
the opposite of module_permission's slug rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 12:41:50 +01:00
adminandClaude Opus 5.5 471b871248 0.26.0: chat_contract, what a module tells the platform's chat (K4)
One shape for a module's chat records: GET /chat/records answers pages
of one-sentence records (key <module>:<kind>:<id>, kind, title, text,
link, optional labels, at, members), filtered by the caller's access,
bounded, paged through next_offset. Module side: make_record, make_page,
page_params, validate_page. Opt-in, standard library only, no tables.
Atrium#53, stage 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 11:48:03 +01:00
admin 80d5058fa4 Merge pull request #5 into main (0.25.0)
# Conflicts:
#	README.md
#	pyproject.toml
v0.25.0
2026-11-24 20:22:28 +01:00
tobayahandClaude Opus 5.5 cb34855f9b 0.24.0: the Workflow contract (event kinds, payload, start client)
CI / Tests (Postgres 16) (push) Failing after 3s
CI / Tests (Postgres 17) (push) Failing after 3s
Opt-in dredd_core.workflow_contract for the Workflow module (approval runs on Galena documents, plain files and requests): the five workflow.* event kinds, payload()/parse() for the shared module_event log and WorkflowClient.start (POST /runs with the acting person's token). A document's path and a file's name never enter the shared log; receivers read the document by document_id + commit_sha. The engine stays in the Workflow module. No tables, no migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_016uwxqHzKngt1twLyg6mQML
v0.24.0
2026-11-22 15:14:33 +01:00
tobayahandClaude Opus 5.5 ab5c16670c model_access: step headers in the red-lines prompt (0.25.0)
CI / Tests (Postgres 16) (push) Failing after 23s
CI / Tests (Postgres 17) (push) Failing after 2s
0.24.0 stays reserved for K4 (the chat).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqJYwbXKWMeNZfrFuXq
2026-11-18 23:38:41 +01:00
admin 57d39598eb Merge pull request #4 from Alpaq92/model-provider-delete
0.23.2: usuwanie wyłączonego dostawcy modeli, na którego nie wskazuje żaden przebieg
2026-11-18 18:26:19 +01:00
tobayahandClaude Opus 5.5 f8afd24ef6 delete_unused checks the RESTRICT instead of assuming it
A module foreign key to model_provider that would cascade or set null refuses the delete (409 provider_reference_unsafe) before it runs; core's own key tables are left out, their CASCADE is by design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqKuxvGXDvtwWKrBWYR
2026-11-18 16:39:25 +01:00
tobayahandClaude Opus 5.5 4c5ecf4cde README: the hub's repin is enough, atrium-migrate re-applies the grants
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqKuxvGXDvtwWKrBWYR
2026-11-18 16:32:06 +01:00
tobayahandClaude Opus 5.5 14e51728f5 0.23.2: model_providers.delete_unused deletes a disabled provider no run points at
A key that expires after a day left its provider on the list for good. A disabled provider with no run pointing at it can now be deleted with its keys; one still active (409 provider_still_active) or used by any module's RESTRICT foreign key (409 provider_in_use) cannot. The writer gains DELETE on model_provider; managed check requires it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqKuxvGXDvtwWKrBWYR
v0.23.2
2026-11-18 16:31:45 +01:00
adminandClaude Opus 5.5 9a2ab1d400 0.23.1: model_providers.update keeps a stored key with its address
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.23.1
2026-11-14 12:53:20 +01:00
admin 5025098590 Merge pull request #3 from Alpaq92/fix/firm-key-stays-with-address
model_providers: a stored key does not follow the provider to a new address
2026-11-14 12:36:15 +01:00
Piotr ChojnackiandClaude Fable 5.2 3df4e5a7b9 model_providers: a stored key does not follow the provider to a new address
update() already drops every personal key when base_url changes, because a
key was given to one address. The firm's key stayed, so the next call sent
it to whatever the new address was: anyone who may edit a provider, or who
holds such a session, could read a write-only key back off one request.

update() now refuses to change base_url while a key is stored unless the
same call sends api_key for the new target or clears the key (422,
base_url_needs_key). Refused rather than cleared, so correcting an address
never loses a key unannounced. Checked before anything changes, and
whatever the key_mode: a key left stored is sent again once the mode
returns to firm.

Tests: test_the_firm_key_never_follows_the_provider_to_a_new_address.
Not run locally (needs DREDD_CORE_TEST_DATABASE_URL).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-13 15:27:49 +01:00
admin cc709c6391 Merge pull request #2 from Alpaq92/feat/m4-stats
0.23.0: the stats contract and the event log's reader tier
v0.23.0
2026-11-12 22:25:16 +01:00
adminandClaude Opus 5.5 f170334895 0.23.0: the stats contract and the event log's reader tier (Compass split M4)
CI / Tests (Postgres 17) (push) Failing after 4s
CI / Tests (Postgres 16) (push) Failing after 29s
dredd_core.stats_contract (opt-in, standard library only, no tables) is the
second read contract, built like search: GET <module>/api/v1/stats answers
{version, module, as_of, tiles: [{key, label, count, link, as_of?}]}, a tile
counts only what the caller may see and equals the list its link opens.
gather() asks every configured module in parallel through module_client with
the person's own token and never raises: each module is ok, absent,
no_access or unavailable, with a machine reason.

event_grants_sql gains reader_roles (SELECT only, verified; a role is an
emitter or a reader, never both) and managed check gains --events-reader, so
Panorama can read the shared module_event for its trends without being able
to write it. K4 (the chat), planned as 0.23.0, becomes 0.24.0. Not tagged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:30:14 +01:00
adminandClaude Opus 5.5 1e0d71d5f3 0.22.0: model access, the one model client (Compass split K3)
dredd_core.model_access: schema, client, loader, compute moved byte for byte out of
Compass app/agents/, with the golden request bodies and their tests. Opt-in, no tables;
the models extra brings httpx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.22.0
2026-11-11 18:18:21 +01:00
adminandClaude Opus 5.5 9e6ab64264 0.21.0: shared counterparty register (Compass split K2)
Opt-in dredd_core.counterparties: counterparty, counterparty_alias,
counterparty_contact in the identity schema, match_key and validated
NIP/KRS/REGON, matching NIP > KRS > match_key > alias (conflicts and
ambiguity stay separate rows), link_or_create, an insert-only import door
for the modules' legacy rows, and writer / reader / migrator grant tiers.
registries.py moves here from Compass. managed check --counterparties
reader|writer. repoint_identity_fks_sql leaves the register alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.21.0
2026-11-11 12:32:44 +01:00
adminandClaude Opus 5.5 973cb0c7ee 0.20.0: module events (Compass split K1)
Opt-in dredd_core.events: module_event in the identity schema, INSERT +
SELECT only, RLS binds source_role to current_user so no module can send
as another. emit() writes in the caller's transaction; receive() keeps a
(txid, id) cursor below the snapshot horizon and an append-only receipt
per event. create_event_tables, event_policies_sql, event_grants_sql for
the hub; managed check --events with tampering, exposure, forgery and
shadow findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.20.0
2026-11-10 20:11:15 +01:00
adminandClaude Opus 5.5 8c96803a6a 0.19.0: document_ref, plain_files, module_client (Compass split R2)
Three opt-in modules, none loaded by `import dredd_core`, no new deps:
- module_client: one module calls another as the acting person (their
  token, the public base URL, no redirects, one time budget, bounded
  body, proxies ignored, no retries - a caller may retry idempotent
  reads itself). Generalised from Sygna's Galena client.
- plain_files: DATA_DIR/files/<uuid>, one file one id, no overwrite;
  response_headers() is Galena's /raw rule (allowlisted inline media,
  everything else octet-stream + sandbox CSP + nosniff).
- document_ref: DocumentRef (Galena, pinned commit) | FileRef, the
  SubjectRefMixin columns with an exactly-one-shape CHECK, sha256 over
  decrypted bytes checked on read, D9 (no Galena -> 409 galena_disabled)
  and D15 move_to_documents (a failed plain-file delete leaves an orphan
  file, never a lost document).

No schema, grant or identity change: repinning alone changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.19.0
2026-11-09 19:50:21 +01:00
adminandClaude Opus 5.5 bf1861e8c8 0.18.1: dredd_core.routes.iter_routes
FastAPI 0.15x keeps each included router as one _IncludedRouter entry in
app.routes, so a plain walk sees no API route (404 instead of 405 + Allow,
empty route sweeps). iter_routes yields (original, effective) pairs via
iter_route_contexts where it exists, the flat list otherwise. Opt-in, no
new dependency, no schema change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.18.1
2026-11-07 16:04:49 +01:00
admin b7665a4c7e Merge pull request #1 from Alpaq92/user-provider-keys
0.18.0: personal API keys per provider (key_mode, model_provider_user_key, key_for)
v0.18.0
2026-11-06 08:56:22 +01:00
tobayahandClaude Opus 5.5 28b792cadc A personal key never follows the provider to a new address
The administrator owns base_url, the person owns the key. An update that changes base_url, or moves
key_mode away from user, now deletes every personal key of that provider (audited as
user_keys: [n, 0]), so a moved address never receives keys given to the old one; each person enters
theirs again for the new target. Found by an automated security review of the previous commit.

Test: test_a_personal_key_never_follows_the_provider_to_a_new_address (rename/region keep the keys,
an address change drops both people's keys, a key_mode change drops them too); two mutants (purge
removed, key_mode case missed) killed. Provider tests green on Postgres 16 and 17, full suite on 16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqGRpAezXG78YwnHRka
2026-11-06 00:54:49 +01:00
tobayahandClaude Opus 5.5 ab4c6738f9 0.18.0: personal API keys per provider (key_mode, model_provider_user_key, key_for)
dredd_core.model_providers: whose key a call carries, one source per provider and never a fallback.
- model_provider.key_mode: firm (default, every existing provider) / user / none (KEY_MODES, CHECK).
- model_provider_user_key (provider_id, user_id, api_key_encrypted, key_prefix): a person's own key,
  the hub's alone. No module reaches it, the key opt-in included; the grant block strips and verifies
  it and `managed check` reports any grant to a module as key exposure.
- set_user_key / clear_user_key / user_key_prefix: a person writes and clears only their own, audited
  as model_provider.user_key with only "set" / "replaced" in the diff. Clearing is never refused.
- key_for(db, provider, *, user_id, is_admin, decrypt) -> (key, source): the one door out for every
  mode, applying the policy on every call (level, allowed_for, eu_only, is_active) - a stored personal
  key stops working the moment the administrator takes the provider away (404).
- DIALECTS += anthropic (native Messages API; Anthropic documents its OpenAI-compatible endpoint as not
  production-ready).
- model_provider_key_mode_sql: idempotent upgrade of a 0.15.0 model_provider (column + CHECK, every
  provider stays firm); create_model_provider_tables adds the new table; the import door carries
  key_mode.
README: key_mode, the personal-key functions, the grant table, 0.18.0 notes (hub first).

Tests: unit, DB (incl. the policy on every key_for call) and grants/check on Postgres 16 and 17;
6 mutants (policy skipped in key_for, key_mode ignored on write, opt-in reaching personal keys, check
blind to a reader grant, upgrade default flipped, writer grant dropped) all killed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqGRpAezXG78YwnHRka
2026-11-06 00:48:57 +01:00
adminandClaude Opus 5.5 93e88483e8 0.17.0: one search contract for every module (dredd_core.search_contract)
Standard library only: the response shape Atrium's Home reads from every module, query
normalisation, limit clamping, hit/response builders and a validator for conformance tests.
Rule 1 of the contract: authorisation stays in the module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.17.0
2026-10-23 09:46:04 +02:00
adminandClaude Opus 5.5 67caa305e5 0.16.0: charset=utf-8 on every JSON response (dredd_core.json_charset)
Opt-in, stdlib only, promoted from Insider's edge (be065e7). Starlette
sends raw UTF-8 under a bare application/json / application/problem+json,
and Windows PowerShell 5.1's Invoke-RestMethod decodes that as Latin-1
("Rozporządzenie" -> "RozporzÄ…dzenie").

- needs_json_charset / ensure_json_charset: application/json and
  application/*+json without a charset get "; charset=utf-8"; HTML, text/*,
  event streams, NDJSON and binary types are untouched.
- ensure_json_charset_headers (raw ASGI header lists) and
  ensure_json_charset_message (the one line for a pure-ASGI edge's send
  wrapper); JsonCharset as a stand-alone pure-ASGI middleware. No body is
  ever buffered.
- README: the section and the 0.16.0 notes. Version 0.16.0 (untagged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.16.0
2026-10-22 21:04:17 +02:00
adminandClaude Opus 5.5 aebab1438f 0.15.0: shared model providers, the keys behind their own grant
dredd_core.model_providers (opt-in): the platform's model providers and
who may use them, in the shared identity schema, written only by the hub.
- model_provider (Compass's card: kind local/api, base_url, models, region,
  processor, DPA, allowed_for, is_active, key_prefix), model_provider_policy
  (one row: nobody / admins_only / everyone + eu_only; no row fails closed
  to admins_only, EU-only) and model_provider_key.
- Keys sit in their own table: modules get no grant on it, and the hub
  opts a module in explicitly (key_reader_roles, e.g. compass_app).
  model_provider_grants_sql is authoritative (it strips stray grants);
  `managed check --model-provider-keys` proves both directions.
- offering(), offering_to_an_administrator(), usable_providers(), strict
  base-URL and model validation, audit of every write (the key never in a
  diff), keys encrypted by the caller's own function. Callers take the call
  target only from the row (SSRF). LEGACY_POLICY_CODES maps Compass's
  nikt / tylko_admin / kazdy.
- A one-shot SECURITY DEFINER import_model_providers for compass_migrator
  to move Compass's rows (ids kept); the hub drops it afterwards.
README: the section and the 0.15.0 adoption steps for Atrium and Compass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.15.0
2026-10-20 07:57:00 +02:00
adminandClaude Opus 5.5 212817234e 0.14.0: the cross-site write guard and the audit-log reader, opt-in
Two helpers the apps carried as copies:
- dredd_core.cross_site: cross_site_write_refused(method, headers,
  allowed_origins) is the exact logic of the five identical
  refuse_cross_site_write copies (Sec-Fetch-Site, then Origin against Host,
  bearer tokens exempt, CORS_ALLOW_ORIGINS trusted), as a pure function with
  no framework import; SAFE_METHODS and bearer_token beside it. It returns a
  bool, so each app raises its own error (Sygna keeps its Polish message).
- dredd_core.audit_log: list_entries(db, limit, offset, action) is Atrium's
  reader (actor_email joined, an escaped action-prefix filter, newest first
  with an id tie-break), with limit clamped to 1..500.

Both are opt-in; `import dredd_core` loads neither. slugify and the typed
settings stay in the apps: their copies differ in behaviour (stored slugs
would change; only Atrium's settings store is closed). README carries the
modules and the 0.14.0 notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.14.0
2026-10-19 17:09:27 +02:00
adminandClaude Opus 5.5 cd8bf66f54 0.13.0: English kind codes, an entity registry, the naming rule
From Tobiasz's review (Atrium PR #2):
- CustomFieldKind is text / number / date / choice / boolean (was tekst /
  liczba / data / lista / tak_nie); the PG type stays custom_field_kind.
  Everything core defines is an English snake_case code; the Polish detail
  sentences stay, they are human text.
- An entity registry, the way tables already are: EntitySpec,
  register_entity, entity, registered_entities. An app declares its
  entities at startup; an unknown one (a typo like `contrat`) is a 404
  entity_unknown before any SQL, instead of silently starting a second set
  of fields. register_table refuses a TableSpec whose entity is not
  registered.
- README: the naming rule (core codes are English snake_case, a module's
  domain vocabulary stays in the module, human text is never a code), the
  singular entity / plural table_key sentence, the kind table, the
  registry and the 0.13.0 notes with Compass's adoption steps.
- test_create_update_archive_and_audit no longer depends on the order of
  two audit rows written at the same now().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.13.0
2026-10-16 17:08:40 +02:00
adminandClaude Opus 5.5 46b8e0db4e 0.13.0: custom fields and saved table views, opt-in
Two modules every app can switch on, ported from Compass (Tobiasz Badura's
register configuration, Apache-2.0) and generalised:

- dredd_core.custom_fields: moderator-defined fields per record type
  (`custom_field`, unique (entity, key), 30 active per entity, kinds
  tekst/liczba/data/lista/tak_nie), values in the owner's JSONB column;
  server-derived keys (^[a-z0-9_]{1,40}\Z, Polish transliteration), archive
  instead of delete, strict write / lenient read, exact-digit numbers,
  per-entity advisory lock, bound-parameter sort and filter expressions,
  audited with a diff.
- dredd_core.table_views: saved views (own -> firm default -> built-in) over a
  table registry (TableSpec); `table_view` 1:1 with Compass's, so Compass
  adopts it without moving data; the firm default under its own lock.

Opt-in: importing dredd_core alone registers neither table. Refusals carry a
Polish detail plus extra.code and extra.en. No new dependency (SQLAlchemy
>=2.0.16 for NULLS NOT DISTINCT). 720 tests pass against PostgreSQL 16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 20:24:19 +02:00
adminandClaude Opus 5.5 5308933438 0.12.0: the runtime role reads its migration stamp and never writes it
runtime_grants_sql grants the runtime role SELECT, INSERT, UPDATE and DELETE
ON ALL TABLES IN SCHEMA — and Alembic creates alembic_version in that same
schema before any revision runs. So the sweep handed every app's backend write
access to its own migration stamp. A backend that can rewrite the stamp can make
the next deploy skip a revision or run one twice, and nothing in a backend ever
needs to write it: migrations, restores and seeds that touch schema state all
run as the migrator.

Found by Tobiasz's audit of the family from the Compass side
(compass-contract-hub, apps/compass/docs/ATRIUM-CUTOVER.md), filed there as a
family-wide item.

runtime_grants_sql gains `read_only`, defaulting to ("alembic_version",), the
same shape as append_only and no_delete: step 3 revokes INSERT, UPDATE, DELETE
and TRUNCATE on each read-only table that exists.

THE TRAP, and the reason this is more than one REVOKE. Step 5's first
verification required SELECT, INSERT, UPDATE and DELETE on every table in the
schema. Revoking writes on the version table without teaching the verifier
would have made every app's grants revision raise on its own revoke — revoking
a privilege and demanding it in the same block. A read-only table now needs
SELECT and nothing else, and the second verification refuses one that is still
writable another way (a PUBLIC grant, an inherited role). Its message says
"protected tables" now, since a version table is not evidence.

`managed check` gains --read-only (same default), so the check tool proves on
a live box what the grants enforce. A read-only table that does not exist yet
is a WARN, as an absent append-only table already was, and leaves the report ok.

The block still carries no `%` and no `:name` sequence, so it passes through
text() verbatim.

Tests: the full suite against a live Postgres, exit 0, no failures; the five
skips are the TLS-server tests, which need a TLS-only server. New: the runtime
role reads the stamp and cannot write it; the verifier does not demand what step
3 revoked (the block run twice); a stamp writable through an inherited role
fails loudly; managed check in both directions. And one negative control:
read_only=() leaves INSERT in place, so it is the revoke that does it.

Existing databases are unchanged by this alone — the grants are applied at
migration time. Each app needs a revision that re-runs the block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.12.0
2026-10-04 11:37:52 +02:00
adminandClaude Opus 5 e42ebdffff 0.11.0: one table says what a person may do in each module
`module_moderator` answered one question -- is this person a moderator
here -- and the question that actually gates a module was asked nowhere.
It is now `module_permission`:

    user_id      -> app_user.id
    module_slug  'galena' | 'sygna' | 'counsel'
    role         'user' | 'moderator'
    UNIQUE (user_id, module_slug)

    no row              no access to that module at all
    role = 'user'       may use it
    role = 'moderator'  may use it and administer it
    app_user.is_admin   platform administrator: everywhere, no row needed

`role` is text with a CHECK rendered from `MODULE_ROLES`, not a native
enum, for the reason `node.kind` and `session.kind` are text: adding a
value must not mean a migration in four schemas, run in an order nobody
can arrange. Python and the database validate against the same tuple, so
they cannot drift.

`module_role()` is the one read; `may_use`/`assert_may_use` are what an
app's edge calls, and four answers never touch the database -- an
administrator, a standalone app (everyone is `user`, so the guard is a
no-op and there is no second code path), the hub's own slug, and a
misconfigured empty slug, which fails closed.

Grants: a module gets SELECT and nothing else -- a module that could
write this table would admit anyone, promote anyone, and promote itself.
The hub gets SELECT, INSERT, UPDATE, DELETE; UPDATE is new, because a
promotion changes a row rather than replacing it. `grant()` is an upsert
for the same reason.

The hub's own slug is refused for both roles. Every account may open the
launcher, so a `user` row there would say nothing, and the hub has
administrators whose job is not delegable one module at a time.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.11.0
2026-10-01 11:51:39 +02:00
adminandClaude Opus 5 e520d19cd8 0.10.2: a retried cutover converges instead of refusing for ever
The orphan check asked one question -- "does this principal_id name an
account the shared store has?" -- and raised on every no. Two quite
different things answer no, and only one of them is a merge's doing:

  the id is still a row of the app's OWN app_user
      an id the repoint was supposed to rewrite and did not. The missed
      row this guard exists for. Still refuses, as loudly as before.

  the id is in NEITHER store
      nothing was missed. There is no account, no e-mail, nothing to map
      it to. An account somebody DELETEd rather than deactivated leaves
      its grants behind, because the column is polymorphic and carries no
      foreign key, so PostgreSQL performed no referential action. Now
      reported and left alone.

Raising on the second is what made a cutover un-retryable. After a
successful run the local app_user is gone, so the check could no longer
tell the two apart and blamed the merge for both -- offering a hint ("map
every old account id to its merged one, match on e-mail") that cannot be
followed for an account that exists nowhere. One dead grant refused the
deploy for ever. And the merge can never be the cause once that table is
gone: the run that dropped it passed this same check in the same
transaction.

The guard is not weakened. Mutation-tested: turn the RAISE into a
WARNING and test_the_orphan_check_raises_on_a_grant_left_behind_by_the_merge
fails.

orphan_rows_query is the second half of the warning. RAISE WARNING from
inside a DO block reaches the PostgreSQL log and no human -- pg8000
collects server notices on the connection and nothing prints them -- so
the revision runs the count afterwards and logs it itself, where Alembic
puts it on stdout with everything else.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.10.2
2026-09-28 09:13:41 +02:00
adminandClaude Opus 5 1690a6ac8d 0.10.1: refuse the wrong migrating role before anything is built
`runtime_grants_sql` already refused to run as a superuser, the platform
admin or the runtime role -- but it sits in whichever revision applies
the grants, which is the second, third or sixth. By the time it speaks,
the wrong role has created every table in the schema, owned by itself,
and only the transaction undoes that. On a managed provider those are
precisely the objects that pick up an auto-generated API's grants, with
every later GRANT from the migrator a silent no-op.

Measured, not assumed, by stubbing this preflight out: as the platform
admin, Counsel built its whole schema and was stopped by 0002, Galena by
0006, and Atrium -- which owns the platform's identity -- by 0003, having
already created app_user and session. Sygna alone died early, and for an
accident: with identity shared, its 0001 emits an unqualified foreign key
to app_user, and the platform admin's search_path (`"$user", public,
extensions`) never carries the identity schema, so the table is not
visible. `relation "app_user" does not exist` -- 42P01, not a permission
error, and nothing to do with the guard.

`migration_preflight_sql(app_role)` is what an app's 0001 runs FIRST. It
reads only `current_user`, `pg_roles` and `current_schema()` -- nothing it
could be denied, nothing that must already exist -- which is what lets it
run before the schema does. `app_role` is compared to, never looked up,
so a first revision may still legitimately run before the runtime role is
provisioned; `runtime_grants_sql` keeps its own copy of the two checks as
a second line of defence, and says so.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.10.1
2026-09-26 14:40:32 +02:00
adminandClaude Opus 5 34f827c2d8 0.10.0: one identity store the whole family shares
A person gets ONE account across a family deployment. The three tables
that carry identity -- app_user, session, module_moderator -- can live in
a neutral schema every app reads, so a session created by the hub
resolves in every module. Nothing is handed between apps: the family runs
at one origin, so one cookie is the whole of it.

The split is forced by what a migrator may do. A migrator holds no CREATE
on the database and cannot ALTER ROLE another role, so the schema, its
owner and every role's search_path are PROVISIONING (--identity-schema /
--identity-owner, rendered into each app's provision.sql). Only the
tables themselves come from the identity owner's own migration.

Who may do what, enforced by grants rather than by convention:

  the hub's migrator   owns the schema and the tables
  the hub's app role   writes identity -- the only role that can
  a module's app role  SELECT on named columns of app_user, SELECT on
                       module_moderator, and UPDATE on three columns of
                       session. No INSERT on any of them: a module able
                       to insert a session row could mint a credential
                       for anyone.
  a module's migrator  SELECT + REFERENCES on app_user, so its own
                       foreign keys can point at the shared table.

app_user's password hash and lockout columns are `deferred`, which is
what makes a column-restricted read survivable: an ordinary load names
only the readable columns, so a module does not 500 on every
authenticated request. AuthService undefers them on the login path alone.

Two admin tiers: is_admin is the ADMINISTRATOR, platform-wide; the
MODERATOR is per-module, a row in module_moderator, written only by the
hub. authz binds it as data -- the app passes its slug, never a
predicate.

`managed check` had to change shape for this: "no privilege outside my
schema" becomes an explicit allowlist that names the identity schema and
then says, per role, exactly what it may reach there. It also detects a
shadow copy in an app's own schema, which the search_path would find
first and which has no other symptom.

Also fixes, found by running it rather than reading it:

- has_table_privilege(role, table, 'SELECT, INSERT') is an OR, not an
  AND. Three positive assertions used comma lists, so a stray SELECT
  satisfied them while the writes were never granted -- including the
  module migrator's REFERENCES, the entire reason that tier exists.
- pytest.raises(match=...) around a DO block is a tautology: SQLAlchemy
  appends the failing statement, which contains every message the block
  can raise. A test matching "moderator escalation" passed on an error
  that said "not the identity owner". conftest.refuses_with() asserts on
  the driver's message instead; eight assertions in test_runtime_grants
  had been meaningless since v0.9.0.
- `check` called the identity OWNER an escalation -- the loudest possible
  failure against the most trusted role, on a correct deployment.
- A bare `postgresql://` meant psycopg2, which nothing here installs, so
  the first command of a cutover died naming a Python module rather than
  the URL. resolve_url now supplies the driver the rest of this module
  already assumes.
- provision no longer demands a password for roles it is not creating;
  it decides against pg_roles inside the transaction instead of against
  argv, which cannot know.

A standalone app is unchanged in every respect: it owns its identity, and
none of the above switches on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.10.0
2026-09-26 12:52:57 +02:00
adminandClaude Opus 5 28fdb8ea7e Identity is the platform's, not one app's
Corrects the README's claim that every app carries its own copy of
`app_user` and that there is therefore no cross-app single sign-on.
That was never the design anyone chose; it was inferred and then
written down as fact, and it has been shaping the family since.

The family runs at one origin, one module per path, with ONE identity
per person. Core supports both: an app standing alone owns its identity
store, and a platform deployment shares one. No code change here beyond
the `is_admin` comment, which now says what its reach actually is and
where the per-module "moderator" tier will live -- beside `app_user` in
the shared schema, written only by the hub, never a column added here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-23 21:14:40 +02:00
adminandClaude Fable 5.1 c5fc835f90 0.9.0: managed PostgreSQL without a provider name, and the family's TLS rule
- No provider literals anywhere: the API roles constant is API_ROLES (was
  SUPABASE_API_ROLES); `managed emulate` refuses a public host unless
  --allow-remote instead of matching a domain; `check` gains
  --system-schema; messages, hints, the rendered provision.sql header and
  the README say "managed PostgreSQL provider".
- db: is_local_host() and require_verified_tls() — the one rule every app
  applies to its database URLs at start-up: a host that is not local
  ("", localhost, 127.0.0.1, ::1, postgres, or DB_LOCAL_HOSTS) must carry
  sslmode=verify-full, or the app refuses to start.
- provision refuses the generic role names app / migrator, so a local
  shape cannot reach a shared database.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
v0.9.0
2026-09-23 17:04:23 +02:00
adminandClaude Opus 5 5ebf16b228 tests: look for a leaked password where a URL would carry it
test_check_cli_against_the_test_database asserted the database password
never appears in the check's output. CI's password is literally
"postgres", which the report rightly prints as the connected role's name,
so the test failed on both Postgres 16 and 17. Assert that ":<password>@"
is absent instead. Test-only; v0.8.0 is unaffected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 20:41:21 +02:00
adminandClaude Opus 5 b6899b4708 managed Postgres: TLS, loud runtime grants, provisioning and a preflight
dredd-core 0.8.0 is what the family needs to run in one Supabase project:
one schema per app, per-app roles, and verified TLS.

- db: make_engine turns libpq-style sslmode / sslrootcert URL parameters
  into a pg8000 SSLContext (require, verify-ca, verify-full); disable,
  allow and prefer are refused because they permit plaintext. pg8000 has
  no sslmode of its own and silently falls back to unverified TLS or
  plaintext. strip_tls_params() for Alembic's offline mode;
  make_engine(url, poolclass=NullPool) works now.
- schema: runtime_grants_sql() grants the runtime role its privileges in
  current_schema() as one idempotent DO block, revokes Supabase's Data API
  roles, keeps append-only / no-delete tables so, and fails loudly: when
  the app role is missing, when run as a superuser or the platform admin,
  and when a grant did not take.
- provisioning: python -m dredd_core.managed provision creates an app's
  schema and roles as the platform admin (postgres on Supabase), isolates
  it from other apps and PUBLIC, sets search_path and statement_timeout,
  and revokes its own temporary membership; --sql-only renders the same
  steps as plain SQL for the dashboard's SQL editor.
- managed check: read-only preflight (TLS both ends, roles, schema, table
  owners, append-only tables, Data API roles, cross-schema isolation).
- managed emulate: TEST-ONLY Supabase lookalike for CI and local tests.
- CI runs on Postgres 16 and 17 (Supabase offers 15 and 17).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.8.0
2026-09-15 19:39:32 +02:00
adminandClaude Opus 5 3a912b900a types: SafeInet reads back as str, as its annotation promises
Every SafeInet column is annotated Mapped[str | None], but the type only had a bind hook, so drivers handed back ipaddress.IPv4Address/IPv6Address objects. Any app that returned an audit row or session IP in a JSON response failed with 'Unable to serialize unknown type' — found when the /dredd template's admin audit screen 500'd on its first real login. process_result_value now returns str, and bind normalises to str too. No current caller depends on the address object: Galena, Sygna and Counsel Scorecard only ever write these columns.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.7.1
2026-09-14 19:52:34 +02:00
adminandClaude Opus 5 bf39401606 authz: a restrict-only overlay seam for app policy
register_overlay(fn) lets an app layer policy on top of the resolver — Sygna's ethical walls are the motivating case — without forking the one access authority. Overlays are restrict-only: an overlay returning a HIGHER role is discarded rather than trusted, so the seam cannot become a privilege-escalation path one buggy overlay away. They apply to instance admins too, because a wall the admin walks through is not a wall.

Applying it in effective_role alone would have left two bypasses, so both are closed: readable_node_ids (the batch path list screens use — otherwise a wall hides a document from its detail page while still listing it) and users_with_role_at_least (otherwise a hidden node still emails the person it is hidden from). Both take the slow path only when an overlay is actually registered; with none, the fast paths are untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.7.0
2026-09-12 17:50:51 +02:00
adminandClaude Opus 5 9db95ea125 authz: add readable_node_ids, the batch permission filter
A list screen that calls effective_role per row turns a page of 200 into 200 resolutions, which is how a permission check ends up 'optimised' away by whoever profiles the page later. readable_node_ids answers the same question for a whole page in two queries regardless of row count, with the same rules reduced to yes/no: instance admin, ownership on self-or-ancestor, or any grant on self-or-ancestor. A test asserts it never disagrees with effective_role. It belongs here rather than in an app because it is authz, and authz has exactly one authority.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.6.0
2026-09-12 16:38:26 +02:00
adminandClaude Opus 5 9958addc9d Move the auth service and the engine factory into core
AuthPolicy + AuthService carry login, lockout, sessions and app tokens. The per-install knobs are injected rather than read from any app's config, so core still imports nothing app-side; the HTTP edge (cookies, handlers) stays in each app. db.make_engine/make_session_factory carry the family's hardened defaults — notably hide_parameters=True, which keeps bound values out of logs and is easy to miss when hand-rolling an engine. SessionKind/TokenScope move in alongside, since they back core's session columns. Adds py.typed, and rewrites the README as a real front door (module map, pinning, new-app quickstart). 131 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.5.0
2026-09-12 15:49:22 +02:00
adminandClaude Opus 5 db6e68071d Derive and create the core enum types from the metadata
The models use pg_enum(create_type=False), so create_all never emits CREATE TYPE and every consuming app must create the enum types first — a list already hand-copied in two places (Galena's 0001 and this package's test conftest), and a third copy waiting to drift in each new app. dredd_core.schema.enum_types() derives them from the metadata itself and create_enum_types(conn) creates them idempotently, so a new app's migration is one call before create_all and the DDL cannot drift from the models. The test conftest now uses it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
v0.4.0
2026-09-12 15:35:09 +02:00