Repository navigation
feat: retire a signed-out session key (POST /session/retire) - #678
Merged
Merged
Conversation
Sign-out option B. A session did:key signs a 120 s, proofless UCAN to this node with tinycloud.session/retire on urn:tinycloud:session:self; the node records (did, retired_at) idempotently for session_retire.ttl_secs (default 30 days) behind a per-IP rate limit. - The retired key invokes nothing (401 session_retired:). - A delegation it signs that this node had not stored before the retire is refused on every new-delegation path (precheck, validate_with, save_owner_renewal_lease); a stored one resubmitted, single or batch, answers as already registered. - Invoke-time chain check: a chain delegation from the key first seen after the retire is refused (new delegation.first_seen_at; NULL counts as before). - No renewal lease or stamp for a delegation the key holds. - Delegations made before sign-out keep working; Revoke ends them. Hosts that start hosting the space after sign-out never get the marker (follow-up TC-3673). - Retire lookups ride the existing graph snapshot query; no extra invoke round trip. Details: TC-3443
A retire row expired after ttl_secs even if the key still held a longer-lived grant, so a retired key could act again. The row now lasts until the latest-expiring stored delegation (or renewal stamp) held by the key ends; NULL expiry keeps it for good; a delegation to the key stored later raises it (on PostgreSQL inside the existing insert statement, no extra round trip). ttl_secs is the minimum. Details: TC-3443
Completes b95475f, whose selection missed this line. Details: TC-3443
…0 refused (TC-3443) Bobbie's review of #678: - N1: the retire (prune, live-grant check, end computation, insert/raise) is one write transaction. On PostgreSQL it takes a per-DID advisory lock and the renewal lock of each original the key holds; delegation::save takes the same DID lock for a did:key delegatee inside its existing actor-insert statement (no extra round trip). - F1: active renewal leases (lease_expiry) count toward the row's end, and registering a lease raises it; session_retire.ttl_secs = 0 refuses to start. - F2: a row is written only for a DID holding a live delegation, stamp or lease; the route answers the same 200 otherwise, so a forged X-Real-IP cannot fill the table. - F3/F4: wording (authority the key holds as owner is unaffected) and the <=300 s signed-KV ticket / hook stream tail documented as a known limit. Details: TC-3443
…ded (TC-3443)
Bobbie's N2: with the live-grant gate, a retire on a host that stored no grant for
the key wrote nothing yet answered 200, and the key's root posted afterwards made it
usable there. POST /session/retire now takes an optional {"delegations": [...]} body
(the /delegate header encoding, at most 8, each delegatee must be the retiring DID or
the whole request is refused). Carried roots go through policy admission, precheck
and process_with inside the retire's own write transaction, under the DID lock, so the
row covers them. The response gains recorded and expiresAt; recorded:false means
nothing was written. Docs: the client sends every root it holds for the key.
Adds a PostgreSQL stamp-vs-retire lock test.
Details: TC-3443
Completes b98b4b4, whose selection left out the rest of db.rs. Details: TC-3443
Conflicts resolved: - delegation::process_with keeps both Existing arms: a stored delegation refused as SessionRetired (TC-3443) or UnverifiableHolder (TC-1500) answers Existing on resubmit. - delegation::save_owner_renewal_lease runs check_holder, then the retire check. - CHANGELOG/README keep both entries; tinycloud.toml drops the removed did_resolution block and keeps session_retire. Details: TC-3443
… not a refusal (TC-3443) CI at a42ea3c: - space_purge_table_inventory: session_retire names a did, so it needs a purge classification. RETAINED: keyed by a session did:key, names no space, expires_at-bounded and pruned. - operation_retry::delegate_route_answers_the_safe_503_when_the_retry_is_lost_too: precheck now reads the retire table for a did:key issuer, and a lost connection there was followed by a second pool read (is it stored?) that spent the retry's injected loss. delegate_verified now returns a storage failure from precheck as it is; only refusals ask whether the bytes are already stored. Details: TC-3443
…ed roots outside their window (TC-3443) Bobbie's PASS WITH NOTES on a42ea3c: - L1: a retire carrying a root took the key's lock, then the space sequence lock, while /delegate takes them the other way round: a PostgreSQL deadlock. The retire now takes locks as transact_verified does: chain guards, the in-process space sequence guards (TC-732), the SQLite writer lock, then in the transaction the space sequence locks, the key's lock, and (in retire_in) the originals' renewal locks. The carried roots are stored with those sequence locks marked held. - L2: a carried root that has expired is skipped and its index returned in `skipped`; one not valid yet is checked (signature, issuer standing, capability rules, holder) but not stored, and the row lasts at least until it expires. Details: TC-3443
# Conflicts: # CHANGELOG.md
This was referenced Nov 21, 2026
samgbafa
marked this pull request as ready for review
November 21, 2026 22:56
This was referenced Nov 21, 2026
samgbafa
pushed a commit
that referenced
this pull request
Nov 21, 2026
Conflict in tinycloud-core/src/migrations/mod.rs: #678 (session retire) and this branch both added a new migration module and Migrator entry. Resolved by keeping both; session retire runs first by version-string order (m20261121 < m20261122).
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.
Sign-out option B, "retire the key", node half. Details: TC-3443. Draft until Bobbie's PASS. #677 (TC-1500) is merged; main is merged into this branch (a42ea3c) with both batch Existing arms kept and
check_holderbefore the retire check insave_owner_renewal_lease.What changes
POST /session/retire. The header isAuthorization: Bearer <UCAN>, issued by the sessiondid:keyto this node's DID. It must carry exactly{"urn:tinycloud:session:self":{"tinycloud.session/retire":[{}]}}, noprf, a nonce, andexp <= now + 120 s(nbfallows 30 s skew). The signature is verified offline.{"delegations": ["<delegation>", ...]}: the session's root delegations, each encoded exactly asPOST /delegatetakes it in itsAuthorizationheader; at most 8, body at most 512 KiB, unknown fields refused. The client must send every root it holds for the session key (all spaces, including any signed but never posted). Each must be to the retiring DID, or the whole request is refused. Each is admitted exactly as/delegateadmits it (Policy/v3 admission, signature,precheckwithcheck_holder, thenprocess_with) inside the retire's own write transaction under the DID lock, so the row covers it and posting it later cannot bring the key back (N2). Any refusal answers401 session_retire_invalid: delegation <i>: <reason>and nothing is written."skipped". One not valid yet (nbfahead) gets every check but its time window (signature, issuer standing, capability rules, holder), is not stored, and the row lasts at least until it expires.transact_verifiedtakes them: chain guards, in-process space sequence guards (TC-732), the SQLite writer lock, then in the transaction the space sequence locks, the key's lock, and the originals' renewal locks./delegatetakes a space's sequence lock before the key's lock too, so the two never deadlock.200 {"did","retiredAt","recorded","expiresAt","skipped"}. A repeat call answers the firstretiredAtand the storedexpiresAt."recorded": false(noexpiresAt) means this node holds no live grant for the key and none was carried, so nothing was written (F2).skippedis omitted when empty.401 session_retire_invalid: <reason>.429once one IP sends more thansession_retire.rate_limit_per_minute(default 10) requests a minute. The limiter is only a throttle: it trusts the IP Rocket reports (X-Real-IP), and its per-IP map never evicts (pre-existing, not fixed here). The live-grant gate is what bounds the table.503 session_retire_unavailable: …on a database error.session_retire(did, retired_at, expires_at)table and a nullabledelegation.first_seen_at, set when this node first stores a delegation. A resubmitted delegation keeps its first time. Legacy rows stay NULL and count as stored before any retire.401 session_retired: …). The key can no longer use any delegated authority. Authority it holds as the owner of a space or network is unaffected (root authority is checked first):precheck,validate_with(single/delegate, batchprocess_with, Policy/v3 roots and sessions), andsave_owner_renewal_lease. A delegation already stored, resubmitted singly or in a batch, still answers as already registered;session_retire.ttl_secs(default 30 days;0refuses to start), and until the latest end among the delegations, renewal stamps (new_end) and active renewal leases (lease_expiry) this node stores for the key. A grant with no expiry keeps it for good. A delegation to the key, or a lease on an original it holds, stored after the retire raises the row's expiry; nothing lowers it. Lookups ignore expired rows, which are pruned on each retire call and on the invocation-replay cleanup tick.delegation::savetakes the same DID lock for adid:keydelegatee inside its existing actor-insert statement, so registration gains no round trip.did:keydelegators.Known gap (follow-up TC-3673)
A host only knows the retires posted to it, and records one only if it stores a live grant for the key or is given the key's roots in the request. Sign-out covers only those: a root the client does not send and this node does not hold is not covered. A host that starts hosting the space after the sign-out never gets the marker. It accepts the key until the session root expires (at most 7 days by default). TC-3673 tracks the fix: the retire record goes to the registry and is imported when a node admits a space.
Review notes (Bobbie, PASS WITH NOTES at 8bf52aa; follow-up TC-3692)
delegation::savetakes eachdid:keydelegatee's retire lock in event order, so two batches naming the same two delegatees in opposite order could deadlock on PostgreSQL. PostgreSQL aborts one side, so it fails closed, and no production caller sends a batch with more than one delegatee. TC-3692: sort the locks, or document the invariant.SpaceDatabase, whose in-process guard serializes them, so it cannot catch a PostgreSQL lock-order regression. The order is right by code reading (S → DID → O). TC-3692: a two-instance test./delegate.Migration
m20261121_000000_session_retireadds the table and the column.downdrops both. There are up→down→up tests on SQLite and PostgreSQL.Tests
models::session_retire::tests::*(request verification for each malformed case; idempotence; TTL and prune; no row for a key without a live grant)db::session_retire_tests::{sqlite,postgres}_retired_session_refuses_itself_and_new_children_only, which covers:db::session_retire_tests::{sqlite,postgres}_child_first_seen_after_retire_is_refused_at_invoke,first_seen_is_set_on_insert_and_kept_on_resubmit,expired_retire_does_not_refuse_and_is_pruneddb::session_retire_tests::{sqlite,postgres}_retire_row_outlasts_every_grant_the_key_holds(60-day root sets the end; a later grant raises it; nothing lowers it; NULL expiry is never pruned)db::session_retire_tests::{sqlite,postgres}_retire_holds_past_its_ttl_while_a_longer_grant_lives(retire + 31 days: invoke still refused, the intake lookup still finds the row, prune deletes nothing)db::session_retire_tests::{sqlite,postgres}_retire_racing_a_delegation_to_the_key_covers_it(N1);renewal::tests::postgres_retire_waits_for_a_stamp_in_flight_on_an_original_it_holds(N1, PostgreSQL lock)db::session_retire_tests::{sqlite,postgres}_carried_root_is_admitted_and_covered(N2 thief case: an unstored root carried in the retire is stored and covered; posting it later answers Existing; invoke refused at retire + 31 days),{sqlite,postgres}_retire_with_nothing_to_record_writes_nothing,{sqlite,postgres}_refused_carried_delegation_writes_nothing(wrong delegatee; non-owner root beside a valid one; nothing stored)db::session_retire_tests::{sqlite,postgres}_carried_roots_outside_their_time_window(L2: expired root skipped and reported; future-nbfroot from a non-owner refused; future-nbfowner root covered, not stored),sqlite_carried_retire_racing_a_delegate_in_its_space/postgres_carried_retire_racing_a_delegate_in_its_space_does_not_deadlock(L1: a carrying retire and a/delegateto the same key in the same space, joined, four rounds)renewal::registration_tests::lease_for_an_original_held_by_a_retired_session_key_is_refused(checked past a 1 s TTL);frozen_proofless_owner_lease_registers_active_generation_one(extended: the row lasts to the lease expiry);renewal::tests::sqlite_issue_caps_to_ancestor_and_replay_is_atomic(extended: a declined stamp spends no stamp or replay, also past the TTL; a stamp racing a retire is covered; a stamp committed before the retire sets the end)config::tests::tc3443_startup_rejects_a_zero_session_retire_ttlmigrations::m20261121_000000_session_retire::tests::{sqlite,postgres}_session_retire_up_down_uptests/session_retire_routes.rs, four tests:recorded:false; foreign key, not-JSON, nine entries, non-delegation entry each 401; carried retirerecorded:true; the root posted later answers 200 and the key's invoke 401).Local results at 8bf52aa: core lib 1257/1257,
session_retire_routes4/4,did_resolution_routes9/9, nodeoperation_retry16/16, clippy clean, fmt clean. The PostgreSQL variants andpostgres_round_trip_budgetrun in CI; Bobbie's reviewer ran the PostgreSQL 14 variants at a42ea3c (42/42, round-trip budget 9/9).session_retireis classified RETAINED for space purge (keyed by a session did:key, names no space, expires_at-bounded).Release
Merges only on Naomi's GO naming the head SHA, and only after v1.26.17 is tagged from 4a93060 (so 1.26.17 stays #677 alone). It ships in its own node release after 1.26.17, through Amos (it adds a migration). The release note must carry the bold statements from the CHANGELOG.
test-ruling: TC-3443 tinycloud-node renewal/registration_tests.rs moves lease setup into the shared frozen_lease_graph helper and frozen_proofless_owner_lease_registers_active_generation_one gains a retire-row-lasts-to-lease-expiry check; renewal.rs sqlite_issue_caps_to_ancestor_and_replay_is_atomic gains a C2 block (a declined stamp past a 1 s TTL, a concurrent stamp + retire, a pre-retire stamp setting the row's end); delegation literals in existing fixtures gain first_seen_at: Default::default(); additions only, no assertion removed or loosened (2026-11-21)