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>
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>
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>
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>
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>
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>
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>
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
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
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
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>
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>
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>
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>
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>
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>
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>
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
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
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>
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>
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>
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>
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>
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>
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>
`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>
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>
`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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>