Repository navigation
feat(identity-pg): Postgres adapter for people, sessions, grants and the auth log - #788
Merged
Merged
Conversation
ajianaz
force-pushed
the
feat/identity-sessions-grants
branch
from
December 5, 2026 01:17
37b45db to
afff9da
Compare
…the auth log ADR-0022 slice 8. migrations/0009_identity.sql adds nine tables, the unique index that allows one live grant for each person and client, and the guard triggers (a session that ended and a grant that was revoked stay so, a bound only rises, an auth event is edited only to erase its subject and leaves only after 90 days). The new crate meldframe-identity-pg (kind bin) implements the IdentityStore seam over the pool and runtime of PgStore and passes the 85-case contract unchanged. Time is always the now_ms of the call; the one exception is the retention trigger of auth_events. Every call that counts and then inserts takes an advisory lock (person, then workspace), proved by threaded tests and by hand-made mutants that remove each lock and the index. PgStore gains pool() and block_on(), and exports db_i64. meldframe-identity makes the stored words (ALL and parse), Session::holds_slot, Grant::new_pending and check_time public so the adapter calls the rule of the core and has no copy of it. tools/check-migrations.sh has a sixth section. Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
ajianaz
changed the base branch from
feat/identity-sessions-grants
to
develop
December 5, 2026 09:01
ajianaz
force-pushed
the
feat/identity-postgres
branch
from
December 5, 2026 09:01
82af5d1 to
9aa24d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ADR-0022 slice 8, Postgres for identity. A migration and a new crate,
meldframe-identity-pg, that implement theIdentityStoreseam ofmeldframe-identityon Postgres: people, sign-in sessions, login attempts, agent grants with the deny, the Gatehouse revoke calls and the auth event log. The 85-casestore_contract!passes on it unchanged.This pull request is stacked on #782 (slice 7b), so its base is
feat/identity-sessions-grantsand the diff holds only slice 8. When #782 merges, the base moves todevelop.Why
Slices 3b to 7b built the rules and the in-memory reference adapter. Nothing survives a restart until the store is real, and three rules (the ten-session count, the concurrent sign-in cap and one live grant for each person and client) only mean something when two callers race. The slices that follow (11b sessions on the wire, 12, 15c, 16) read and write through this adapter.
Changes
migrations/0009_identity.sql: nine tables, the guard triggerspeople_guard,sign_in_sessions_guard,agent_grants_guard,auth_events_guardandauth_events_no_truncate, and the unique partial indexagent_grants_one_live. A session that ended stays ended, a confirmed revoke is final, a bound and a last use only rise, and an auth event is edited only to erase its subject and leaves only after 90 days.crates/integrations/meldframe-identity-pg(kind bin): the adapter over the pool and the private runtime ofPgStore, synchronous at the seam and bridged withblock_on. Time is only thenow_msof the call; the one exception is the retention trigger ofauth_events. Each call that counts and then inserts takes an advisory lock (people, then person, then workspace). No raw cookie, token or email is stored, only SHA-256 names. Auth events: a refused sign-in is kept once for each subject and UTC day, at most 1,000 a day, with erasure of a subject and a purge cut at 90 days.crates/integrations/meldframe-store-pg:PgStore::pool()andPgStore::block_on(), anddb_i64exported.crates/core/meldframe-identity: the stored words (ALLandparse) come from one macro inwords.rs;Session::holds_slot,Grant::new_pendingandcheck_timeare public so the adapter calls the rule and does not copy it.tools/check-migrations.sh: a sixth section for the identity schema (unique subject, the guards, one live grant for each pair, append-only events with the 89 and 91 day cases, no truncate, the cascade from a person).docs/epics.md,AGENTS.mdanddocs/architecture.md.Testing
Run against a local Postgres 16 with
MELDFRAME_REQUIRE_PG=1:cargo test -p meldframe-identity-pg -p meldframe-identity: 148 tests in the new crate (85 contract cases, the rest differential, concurrency, schema, restart, purge, events, hostile input, isolation and an async caller) and 154 in the core crate, all passing.now()in place ofnow_ms, the unique index dropped): each fails a test. The unique index on live grants is killed by the schema test and bycheck-migrations.sh; the locks mask it in the threaded tests.tools/check-migrations.shsection 6,cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings,cargo xtask deps-check,mm-check,size-check,licences --check,portable-check,sh scripts/ci/selftest.shall pass.cargo deny check(not installed on the machine used).seededinmeldframe-identityfails the same way on the unmodified base (feat(identity): sign-in sessions, login attempts and agent grants with the deny #782).Cora: the local deterministic review (
cora review --base feat/identity-sessions-grants --no-llm) found no issues, andcora mcpansweredinitializeandtools/list. An agent review throughcora.review_prepareandreview_finalizewas not done, so no independent review is claimed here; the CI Cora review is the first one.