Repository navigation
feat(core): user-only Principal, database-authoritative sessions, delete KvSessionStore - #74
Merged
Merged
Conversation
…only
A session belongs to a user, not to a workspace (ADR-0052 round 29). Principal loses its
workspace_id, and authorize takes the route's workspace slug beside the project: the
Database::membership call resolves the slug, the caller's membership of that workspace and of
the project in one query, and returns Member { workspace_id, role } for authorize to mint the
Scope with. 404 for a slug that names no workspace, a workspace the caller is not in, or a
project outside it; 403 for a workspace member who is not a member of the project or whose
role is too low.
Migration 0003_workspaces.sql adds workspaces (id, slug) and workspace_members, backfills a
database created before it (slug = the id as text) and puts the foreign keys on; it is
idempotent like 0002, with per-table scope comments as the first instance of ADR-0041's
tenant|directory marker. The slice routes gain /workspaces/{slug}, built from one SLICE_PREFIX
constant that stays /api/v1 until #47 moves it.
Tests are generative first: an exhaustive memory matrix and core authorize matrix over actor x
slug x project, new slug classes in the Postgres model and the core model, and a slug axis in
the contract matrix (7 x 3 x 3 x 8 = 504 combinations; slugs that can never reach a delete
share one victim per project, because the create rate limit counts rejected attempts too).
a_session_is_not_bound_to_a_workspace has a 404 control, and a pinned regression covers the
upgrade path of a stage-2 database. Each guard was shown to fail when broken: the
workspace-member join, the member backfill and the memory adapter's membership filter.
Refs: plane-byd.11.2.1
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ror and KvSessionStore
The session row is authoritative and read on every request (ADR-0052 round 29, ADR-0082), so a
revocation is a row update that every target sees at once; the spike's KV store was eventually
consistent and the native server lost its sessions on restart.
Migration 0004_sessions.sql adds the directory table: a SHA-256 token_hash key (32 bytes, checked),
user_id, created_at, expires_at, revoked_at and last_seen_at, with no plaintext column and no
workspace_id. Database gains session, touch_session, revoke_session and insert_session, none of
which takes a proof type: like membership they run before a Scope exists. thrust-core hashes the
token (hash_token, sha2 0.11, already in the Worker graph through SCRAM) so no adapter sees one;
authenticate reads the live row (not revoked, expires_at > now), rewrites last_seen_at only when
it is an hour old, and returns Principal { user_id }; seed hashes the fixture's tokens; revoke_session
is the use case a sign-out will call. CoreConfig gains session_ttl_secs (30 days) and
session_touch_after_secs.
Deleted: the SessionStore trait, CacheError, MemorySessionStore, KvSessionStore, Ports.sessions and
its four construction sites, and the SESSIONS kv_namespaces block in both wrangler files.
Tests are generative first: an exhaustive memory matrix and an exhaustive core matrix over
known x revoked x expired (the expiry boundary included), session ops in the Postgres model
(lookup at, before and after expiry, touch, revoke twice, reinsert of an existing hash), and a
column-list test that fails on a plaintext or workspace column. authenticate_resolves_a_live_session_and_nothing_else
keeps its name and now covers the matrix; a lazy-touch test pins the hour. A FIPS 180-4 known
answer pins hash_token. Each guard was shown to fail when broken: the Postgres query without
revoked_at and without expires_at, an added token column, an always-touch and a never-touch
authenticate, and an off-by-one expiry in the memory adapter.
Refs: plane-byd.11.2.2
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… every target POST /internal/revoke-session, behind the same test-routes and admin-token gate as the other /internal routes, revokes the session behind a bearer token through thrust_core::revoke_session. It stands in for sign-out until #38 and is idempotent: an unknown or already revoked token is a 204. a_revoked_session_is_rejected_on_the_next_request lists with a token (200), revokes it, and expects 401 on the very next list and on a create. Its controls: a second, unrevoked token on the same request gets 200 before and after, and revoking again or revoking a token that was never issued changes nothing. scripts/contract.sh now expects 20 tests in the main pass. contract-all.sh passes 16 of 16 cells, so the revocation reaches the memory and the Postgres adapters on the native server and on the Worker (worker-cf reads the row through Hyperdrive with caching off). mutant_ignore_revoked (the memory adapter's session lookup ignores revoked_at) is a new row in scripts/mutants.sh, declared in thrust-adapters-memory and forwarded by thrust-server. It is killed by that one test and no other; the four earlier mutants are still killed, with DOCKER_HOST set and no SocketNotFoundError in the Postgres run. Refs: plane-byd.11.2.3 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ce slug as built
flows/app.md: every slice route carries /workspaces/{slug} (built from one SLICE_PREFIX constant that #47
will change), authentication is a hashed-token lookup of a session row read on every request, a
Principal is a user and nothing else, and the 404/403/401 table now names the slug cases; the table
notes that Plane answers 403 for an unknown slug (PQ-003), which belongs to the compat routes (#44).
/internal/seed and the new /internal/revoke-session are documented.
architecture/app.md and infra.md lose the SessionStore port, the KV binding and the claim that a
postgres server loses its sessions on restart, and infra.md lists the four migrations and the
tenant|directory markers. contributing/patterns.md describes the slug-resolving authorize and the
session calls as the second exception to "repository calls take a Scope". The defect matrix gets a
row for session defects (X15) and its access-table count is now 504; status.md notes the one migration
test.
ADR-0052, ADR-0045 and ADR-0041 get an "issue #36" note: SHA-256 without a pepper and the requirement
it puts on sign-in (#38) to mint at least 128 bits of CSPRNG output, the trait that was not kept, the
session calls as a pre-Scope exception, and the first scope markers. A code comment in hash_token
that overstated what ADR-0052 says about token entropy is corrected, and the last KV mentions in
comments and descriptions go.
The mdBook build could not run locally (mdbook-mermaid is not installed); the edited tables were
checked for column counts with a script that was shown to fail on a malformed table.
Refs: plane-byd.11.2.4
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
Closes #36 (FR-03).
A session now belongs to a user, not to a workspace, and it lives in the database.
Principalis{ user_id };authorizetakes the workspace slug from the route and resolves the slug, the workspace membership and the projectmembership in one query; sessions are rows behind the
Databaseport, stored as a SHA-256 hash;KvSessionStore, theSESSIONSbinding,SessionStore,CacheErrorandPorts.sessionsare gone.Commits (one per bead)
feat(core):authorizeresolves the workspace slug;Principalis user-only.0003_workspaces.sql(idempotent):workspaces (id, slug)andworkspace_members, backfilled for adatabase that has projects and no workspaces (slug = the id as text), then the foreign keys. Each table carries a
-- scope: tenant|directorycomment, the first instance of ADR-0041's marker.membership(slug, project, user)returnsMember { workspace_id, role },NotAMemberorNoSuchProject./workspaces/{slug}, built from oneSLICE_PREFIXconstant that stays/api/v1until chore(api): move the slice's routes out of the/api/v1prefix; reserve it for wire-compatible routes #47.feat(ports): sessions areDatabaserows.0004_sessions.sql:token_hash(32 bytes, checked),user_id,created_at,expires_at,revoked_at,last_seen_at. No plaintext column and no workspace column.session,touch_session,revoke_sessionandinsert_sessiontake no proof type: likemembershipthey runbefore a
Scopeexists.thrust-corehashes the token (hash_token), so no adapter sees one.authenticatereads the live row on every request and rewriteslast_seen_atonly when it is an hour old.test(contract): a revoked session is rejected on the next request, on every target.POST /internal/revoke-session(test routes and the admin token) stands in for sign-out until spike(auth): the two-day Rust auth slice (argon2id, sessions, CSRF, API keys, one OIDC login) #38. New mutantmutant_ignore_revoked.docs:flows/app.md,architecture/app.mdandinfra.md,patterns.md, the defect matrix, and an"issue feat(core): user-only
Principal, database-authoritative sessions, deleteKvSessionStore#36" note in ADR-0052, ADR-0045 and ADR-0041.Decisions to review
/api/v1prefix; reserve it for wire-compatible routes #47 changes onlythe constant. Session tokens are hashed with SHA-256 and no pepper.
output. Nothing here can check that, because the only tokens today are the test seed's. It is written into the
ADR-0052 note and the
hash_tokencomment.to the wire-compatible routes (feat(compat): the 48-route minimum slice with the auth-client JSON change #44); the slice routes keep 404, which tells a probe less. Written down in
flows/app.md.Scope". Nothing but convention restrictswho calls them, and they read no tenant table. Recorded in ADR-0045.
SessionStoretrait is not kept, because the memoryDatabaseserves the tests.touch_sessiondoes not fail the request:last_seen_atis bookkeeping.Evidence
Local, at the PR head
62d82eeunless a row says otherwise.cargo nextest run --workspacecargo test --doc --workspacepg_adapterunder Dockermigration_0003_backfills_a_database_created_before_itandthe_sessions_table_has_a_hash_and_no_plaintext_and_no_workspacescripts/contract-all.sha4af81a. The two commits after it change documentation and comments onlyscripts/mutants.shDOCKER_HOSTset and noSocketNotFoundErrorin the Postgres run.ignore-revokedis killed bya_revoked_session_is_rejected_on_the_next_requestalonescripts/check-deps.shthrust-worker--no-default-featuresgrep -rn "KvSessionStore|SESSIONS" crates/Generative first: an exhaustive memory matrix and core matrix over actor × slug × project; slug and session classes in
the Postgres model; a 7 × 3 × 3 × 8 = 504-combination contract matrix; exhaustive session-state matrices (known ×
revoked × expired, the expiry instant included) in the memory adapter and the core. Static cases are the pinned
upgrade-path regression for a stage-2 database, a FIPS 180-4 known answer for
hash_token, and the column list.Each new check was seen to fail when the code it guards was broken:
workspace_membersjoinrevoked_at/ ignoreexpires_atsessionsgains a plaintexttokencolumnauthenticatealways touches / never touchesexpires_at >= nowrevoked_at(the mutant)Not verified, and one thing I could not explain
mdbook-mermaidis not installed). The edited tables were checked for columncounts with a script that was shown to fail on a malformed table.
contract-all.shrun (before the matrix fix) had one extra failure:sweeper_publishes_rows_the_fast_path_did_noton
worker-memoryfailed inside a request. It came right after the main pass on that target failed, it passed whenrerun alone, and it passed in the three full runs since. I found no cause and do not claim it was fixed.
the slug axis created a fresh delete victim for every combination. The slugs that can never reach a delete now share
one live victim per project, and the item must still be live at the end.
🤖 Generated with Claude Code