carlos / platform Public

console: removal's door-key publication is durable (H4-M1 r1)

Review round 1 (Astra P1-4, Fable P2-5): a failed publish after a
removal was swallowed, and the box-side member tool never published, so
a removed member's door key stayed admitted until the 12-hour re-sign.

The removal now writes a member_revocations row in its own transaction
(classified NonApp: account and address only). drainMemberRevocations
republishes the account's door-key records and deletes the row only when
every publish landed. The browser door drains at once; linkSyncPass
drains every 10 s until it succeeds, which covers `console member
remove`. Link channels were already durable (revoke_synced). The bound,
stated in memberrevoke.go: drain cadence plus the edge's 30 s poll. The
demo holding-member removal is unchanged, by design.

TestRemovalDoorKeyPublicationIsDurable; it fails without the drain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5b1b3f1e79b71df63544aac2077ae223bc784415 parent 9cc5c8e
5 files changed, +175 −13
  • internal/console/links_sync.go +5 −0
  • internal/console/memberrevoke.go +134 −13
  • internal/console/memberrevoke_test.go +31 −0
  • internal/console/store.go +4 −0
  • internal/console/store_gate.go +1 −0
diff --git a/internal/console/links_sync.go b/internal/console/links_sync.go
index 9cb339b1f..6e72246a6 100644
--- a/internal/console/links_sync.go
+++ b/internal/console/links_sync.go
@@ -176,5 +176,10 @@ func (s *Server) linkSyncPass(ctx context.Context) error {
errs = append(errs, fmt.Errorf("link %s: finish unlink: %w", id, err))
}
}
+ // Member removals' door-key follow-up rides the same cadence
+ // (memberrevoke.go): each row retries until its publishes land.
+ if err := s.drainMemberRevocations(ctx, 0); err != nil {
+ errs = append(errs, err)
+ }
return errors.Join(errs...)
}
diff --git a/internal/console/memberrevoke.go b/internal/console/memberrevoke.go
index 841addc41..7b449fc94 100644
--- a/internal/console/memberrevoke.go
+++ b/internal/console/memberrevoke.go
@@ -26,17 +26,30 @@ package console
// Each is refused at its check the moment the transaction commits:
// CLIPrincipal reads revoked_at on every request (no cache), and
// linkPrincipalLive reads the links row. Door keys and link channels also
-// live outside this database; the caller publishes them after the commit
-// (afterMemberRemoved), the same way their own revoke doors do, and the
-// re-sign pass (12 hours) and linkSyncLoop (10 seconds) catch anything
-// that publish misses.
+// live outside this database, and their publication is durable:
+//
+// - door keys: the removal writes a member_revocations row in its own
+// transaction; drainMemberRevocations republishes the account's
+// door-key records and deletes the row only once every publish
+// landed. The browser door drains at once after the commit; the link
+// sync loop drains every linkSyncInterval (10 seconds) until it
+// succeeds, which also covers `console member remove` on the box.
+// - link channels: the links row's revoke_synced flag, which the same
+// loop already retries (syncLinkChannel).
+//
+// So a revoked door key is refused at the edge within the drain cadence
+// (10 seconds, when the immediate publish fails) plus the edge's 30-second
+// door-key record poll; a successful immediate publish leaves the poll.
//
// A person's own CLI token (kind '') is not touched: it names no account,
// and its reach into this one already ended with the membership.
import (
"context"
+ "crypto/ed25519"
"database/sql"
+ "errors"
+ "fmt"
"log"
"net/http"
"time"
@@ -97,8 +110,115 @@ WHERE account_id = ? AND app = ? AND created_by IN (?, '') AND revoked_at = 0`,
return out, err
}
}
- _, err = tx.Exec(`DELETE FROM invites WHERE account_id = ? AND invited_by = ? AND accepted_at = 0`, accountID, address)
- return out, err
+ if _, err := tx.Exec(`DELETE FROM invites WHERE account_id = ? AND invited_by = ? AND accepted_at = 0`, accountID, address); err != nil {
+ return out, err
+ }
+ if len(out.doorKeyApps) > 0 {
+ if _, err := tx.Exec(`INSERT INTO member_revocations (account_id, address, created_at) VALUES (?, ?, ?)`,
+ accountID, address, now.Unix()); err != nil {
+ return out, err
+ }
+ }
+ return out, nil
+}
+
+// migrateMemberRevocations creates the follow-up queue. Additive and
+// idempotent, called from Store.migrate.
+func (s *Store) migrateMemberRevocations() error {
+ _, err := s.db.Exec(`CREATE TABLE IF NOT EXISTS member_revocations (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ account_id INTEGER NOT NULL,
+ address TEXT NOT NULL,
+ created_at INTEGER NOT NULL
+);`)
+ return err
+}
+
+// memberRevocationRow is one queued follow-up.
+type memberRevocationRow struct {
+ ID int64
+ AccountID int64
+ Address string
+}
+
+// pendingMemberRevocations lists the queue, oldest first; accountID 0 is
+// every account.
+func (s *Store) pendingMemberRevocations(accountID int64) ([]memberRevocationRow, error) {
+ rows, err := s.db.Query(`SELECT id, account_id, address FROM member_revocations
+WHERE ? = 0 OR account_id = ? ORDER BY id`, accountID, accountID)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var out []memberRevocationRow
+ for rows.Next() {
+ var r memberRevocationRow
+ if err := rows.Scan(&r.ID, &r.AccountID, &r.Address); err != nil {
+ return nil, err
+ }
+ out = append(out, r)
+ }
+ return out, rows.Err()
+}
+
+// finishMemberRevocation deletes a drained row.
+func (s *Store) finishMemberRevocation(id int64) error {
+ _, err := s.db.Exec(`DELETE FROM member_revocations WHERE id = ?`, id)
+ return err
+}
+
+// drainMemberRevocations finishes queued removals: it republishes every
+// door-key record of the row's account (the revoke bumped the changed
+// apps' revisions; an unchanged record re-signs harmlessly) and deletes the
+// row once all of them landed. accountID 0 drains every account. A row
+// that fails stays for the next pass; the errors are returned joined.
+func (s *Server) drainMemberRevocations(ctx context.Context, accountID int64) error {
+ rows, err := s.store.pendingMemberRevocations(accountID)
+ if err != nil {
+ return fmt.Errorf("member revocations: %w", err)
+ }
+ var errs []error
+ for _, row := range rows {
+ if err := s.finishOneMemberRevocation(ctx, row); err != nil {
+ errs = append(errs, fmt.Errorf("member revocation %d (account %d): %w", row.ID, row.AccountID, err))
+ continue
+ }
+ if err := s.store.finishMemberRevocation(row.ID); err != nil {
+ errs = append(errs, err)
+ }
+ }
+ return errors.Join(errs...)
+}
+
+// finishOneMemberRevocation is one row's work. An account that is gone
+// has nothing left to publish.
+func (s *Server) finishOneMemberRevocation(ctx context.Context, row memberRevocationRow) error {
+ acct, err := s.store.AccountByID(row.AccountID)
+ if err != nil {
+ return err
+ }
+ if acct == nil {
+ return nil
+ }
+ if len(s.cfg.Key) != ed25519.PrivateKeySize || s.cfg.Releases == nil {
+ return nil // nothing to sign with: this console publishes no record
+ }
+ apps, err := s.store.DoorKeyApps()
+ if err != nil {
+ return err
+ }
+ for _, a := range apps {
+ if a.AccountID != row.AccountID {
+ continue
+ }
+ pctx, cancel := context.WithTimeout(ctx, doorKeyPublishBudget)
+ err := s.publishDoorKeys(pctx, acct, a.App)
+ cancel()
+ if err != nil {
+ return err
+ }
+ }
+ return nil
}
// scanStrings reads one string column to the end and closes rows.
@@ -115,15 +235,16 @@ func scanStrings(rows *sql.Rows) ([]string, error) {
return out, rows.Err()
}
-// afterMemberRemoved publishes what a committed removal revoked outside the
-// database: each changed door-key record (publishDoorKeys, as the revoke
-// door does) and each link's channel (syncLinkChannel, as unlink does).
-// Best-effort: the database is already the truth, and the re-sign pass and
-// linkSyncLoop retry anything that fails here.
+// afterMemberRemoved publishes, at once, what a committed removal revoked
+// outside the database: the queued door-key records (drainMemberRevocations)
+// and each link's channel (syncLinkChannel, as unlink does). A failure here
+// is retried by the link sync loop: the queue row and revoke_synced stay.
func (s *Server) afterMemberRemoved(r *http.Request, acct *Account, rev memberRevocation) {
- for _, app := range rev.doorKeyApps {
- s.republishDoorKeys(r, acct, app)
+ dctx, dcancel := context.WithTimeout(context.WithoutCancel(r.Context()), doorKeyPublishBudget)
+ if err := s.drainMemberRevocations(dctx, acct.ID); err != nil {
+ log.Printf("console: door keys after member removal: %v (the link sync loop retries)", err)
}
+ dcancel()
for _, id := range rev.links {
ctx, cancel := context.WithTimeout(context.WithoutCancel(r.Context()), linkFirstSyncTimeout)
if err := s.syncLinkChannel(ctx, id); err != nil {
diff --git a/internal/console/memberrevoke_test.go b/internal/console/memberrevoke_test.go
index d09998fd8..3be20994c 100644
--- a/internal/console/memberrevoke_test.go
+++ b/internal/console/memberrevoke_test.go
@@ -1,6 +1,7 @@
package console
import (
+ "context"
"net/http"
"net/http/httptest"
"strings"
@@ -258,3 +259,33 @@ func TestRemoveMemberRevokesUnattributedDoorKeys(t *testing.T) {
t.Errorf("another account's unattributed key = %+v, %v; want it live", keys, err)
}
}
+
+// TestRemovalDoorKeyPublicationIsDurable (review round 1): a removal that
+// publishes nothing itself (the box-side member tool, or a browser
+// removal whose publish failed) leaves a queue row, and the link sync
+// pass republishes the record and clears the row.
+func TestRemovalDoorKeyPublicationIsDurable(t *testing.T) {
+ fx, member := instanceFixture(t, "code-revoke-durable")
+ key := mintDoorKey(t, fx, member)
+ if !readDoorRecord(t, fx).Admits(key) {
+ t.Fatal("test bug: the minted key is not published")
+ }
+ if err := fx.st.MembershipTransition(RemoveMemberWrite(OpsAccountID, "alice@keymail.dev")); err != nil {
+ t.Fatal(err)
+ }
+ if rows, err := fx.st.pendingMemberRevocations(0); err != nil || len(rows) != 1 {
+ t.Fatalf("queued follow-ups = %+v, %v; want one", rows, err)
+ }
+ if !readDoorRecord(t, fx).Admits(key) {
+ t.Fatal("test bug: the record changed with no publish")
+ }
+ if err := fx.srv.linkSyncPass(context.Background()); err != nil {
+ t.Fatal(err)
+ }
+ if readDoorRecord(t, fx).Admits(key) {
+ t.Error("the link sync pass did not republish the record without the removed member's key")
+ }
+ if rows, err := fx.st.pendingMemberRevocations(0); err != nil || len(rows) != 0 {
+ t.Errorf("queued follow-ups after the drain = %+v, %v; want none", rows, err)
+ }
+}
diff --git a/internal/console/store.go b/internal/console/store.go
index 1f62e5dd9..029e0cfef 100644
--- a/internal/console/store.go
+++ b/internal/console/store.go
@@ -746,6 +746,10 @@ func (s *Store) migrate() error {
if err := s.migrateDoorKeys(); err != nil {
return err
}
+ // Member removals' follow-up queue (memberrevoke.go), same reason.
+ if err := s.migrateMemberRevocations(); err != nil {
+ return err
+ }
// Plans 4a's cap state (plangrace_store.go), for the same reason.
if err := s.migratePlanGrace(); err != nil {
return err
diff --git a/internal/console/store_gate.go b/internal/console/store_gate.go
index dfcfbfa82..66f266c1b 100644
--- a/internal/console/store_gate.go
+++ b/internal/console/store_gate.go
@@ -267,6 +267,7 @@ var claimSQLTables = map[string]claimSQLTable{
"move_log_outbox": {NonApp: "a moves audit outbox that stores no app name: rows are keyed by host, move and entry and bound to an instance incarnation, verified against the host's claim and record at every write, written only by the moves recovery and log passes, and purged with the incarnation"},
"edge_proof_seen": {NonApp: "single-row edge proof marker"},
"cli_auth_requests": {NonApp: "device-code logins in flight, keyed by code hash"},
+ "member_revocations": {NonApp: "member removals whose credential follow-up has not finished, keyed by account and address; names no app and grants nothing: the drain republishes door-key records and revokes through each app's own permit"},
"links": {NonApp: "linked deployments, keyed by link id and bound to an account; names no app"},
"step_ups": {NonApp: "passkey step-up marks, keyed by session hash"},
"claim_sql_identity": {NonApp: "private receipt database identity"},