carlos / platform Public

console: removal revokes door keys with no recorded minter (H4-M1 r1)

Review round 1 (Astra P1-3, Fable P2-6): a key minted before created_by
existed whose audit row was missing stayed '' and no removal reached it.
Unknown provenance now fails safe: removing any member of an account
also revokes that account's keys with created_by ''. Migration logs how
many live keys are still unattributed. The keys list does not show
"minter unknown": that needs new copy (owed).

TestRemoveMemberRevokesUnattributedDoorKeys.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9cc5c8e94a44fcdc08d8ba9d444848f07128e547 parent 1bcc37e
3 files changed, +62 −4
  • internal/console/doorkeys_store.go +14 −1
  • internal/console/memberrevoke.go +9 −3
  • internal/console/memberrevoke_test.go +39 −0
diff --git a/internal/console/doorkeys_store.go b/internal/console/doorkeys_store.go
index 82a433a3c..52e95bbfe 100644
--- a/internal/console/doorkeys_store.go
+++ b/internal/console/doorkeys_store.go
@@ -16,6 +16,7 @@ import (
"database/sql"
"errors"
"fmt"
+ "log"
"os"
"strings"
"time"
@@ -66,7 +67,19 @@ func (s *Store) migrateDoorKeys() error {
WHERE a.account_id = door_keys.account_id AND a.app = door_keys.app AND a.action = 'door-key'
AND a.detail = 'minted door key ' || door_keys.id || ' for ' || door_keys.app || ' (cli)'
ORDER BY a.id LIMIT 1), '') WHERE created_by = ''`)
- return err
+ if err != nil {
+ return err
+ }
+ // What is still unattributed is revoked by the next removal of any
+ // member of its account (revokeMemberCredentialsTx); say how many.
+ var unknown int
+ if err := s.db.QueryRow(`SELECT COUNT(*) FROM door_keys WHERE created_by = '' AND revoked_at = 0`).Scan(&unknown); err != nil {
+ return err
+ }
+ if unknown > 0 {
+ log.Printf("console: %d live door key(s) have no recorded minter; removing any member of their account revokes them", unknown)
+ }
+ return nil
}
// bumpDoorKeyRevision adds one to the app's counter inside tx, creating the
diff --git a/internal/console/memberrevoke.go b/internal/console/memberrevoke.go
index a335c0a5d..841addc41 100644
--- a/internal/console/memberrevoke.go
+++ b/internal/console/memberrevoke.go
@@ -18,7 +18,9 @@ package console
// deploy and run among them (owner-minted)
// cli_tokens kind 'link' link credentials, with their links rows
// (approved by any member who creates apps)
-// door_keys door keys (any member), by created_by
+// door_keys door keys (any member), by created_by, and
+// every key of the account with no recorded
+// minter (created_by '')
// invites pending invitations the member sent (owner)
//
// Each is refused at its check the moment the transaction commits:
@@ -73,8 +75,12 @@ WHERE account_id = ? AND address = ? AND kind IN (?, ?, ?) AND revoked_at = 0`,
// A link's credential row names its approver as address, rotation
// included (RotateLinkToken), so the cli_tokens update above has
// already revoked it.
+ // Door keys: the member's own, and every key of the account whose
+ // minter is unknown (created_by '', a key minted before the column
+ // whose audit row was missing). Unknown provenance fails safe: removing
+ // any member ends those keys too (review round 1).
apps, err := tx.Query(`SELECT DISTINCT app FROM door_keys
-WHERE account_id = ? AND created_by = ? AND revoked_at = 0 ORDER BY app`, accountID, address)
+WHERE account_id = ? AND created_by IN (?, '') AND revoked_at = 0 ORDER BY app`, accountID, address)
if err != nil {
return out, err
}
@@ -84,7 +90,7 @@ WHERE account_id = ? AND created_by = ? AND revoked_at = 0 ORDER BY app`, accoun
}
for _, app := range out.doorKeyApps {
if _, err := tx.Exec(`UPDATE door_keys SET revoked_at = ?
-WHERE account_id = ? AND app = ? AND created_by = ? AND revoked_at = 0`, now.UnixNano(), accountID, app, address); err != nil {
+WHERE account_id = ? AND app = ? AND created_by IN (?, '') AND revoked_at = 0`, now.UnixNano(), accountID, app, address); err != nil {
return out, err
}
if _, err := bumpDoorKeyRevision(tx, accountID, app); err != nil {
diff --git a/internal/console/memberrevoke_test.go b/internal/console/memberrevoke_test.go
index 6521b78f2..d09998fd8 100644
--- a/internal/console/memberrevoke_test.go
+++ b/internal/console/memberrevoke_test.go
@@ -219,3 +219,42 @@ func mustMember(t *testing.T, s *Store, accountID int64, address string) {
t.Fatal(err)
}
}
+
+// TestRemoveMemberRevokesUnattributedDoorKeys (review round 1): a key with
+// no recorded minter (an empty created_by) fails safe: removing any member of
+// its account revokes it. Another account's unattributed key stays.
+func TestRemoveMemberRevokesUnattributedDoorKeys(t *testing.T) {
+ fx := newConsoleFixture(t)
+ st := fx.st
+ now := time.Now()
+ if _, err := st.CreateAppIn(OpsAccountID, "titogo", "paul@keymail.dev", now); err != nil {
+ t.Fatal(err)
+ }
+ if err := st.AddMember(OpsAccountID, "alice@keymail.dev", RoleMember, now); err != nil {
+ t.Fatal(err)
+ }
+ if err := st.CreateAccount(42, "bbw", "other", "bob@keymail.dev", now); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := st.CreateAppIn(42, "elsewhere", "bob@keymail.dev", now); err != nil {
+ t.Fatal(err)
+ }
+ for _, k := range []struct {
+ acct int64
+ app string
+ id string
+ }{{OpsAccountID, "titogo", "aaaaaaaaaaaaaaaa"}, {42, "elsewhere", "bbbbbbbbbbbbbbbb"}} {
+ if _, err := st.DoorKeyInsert(k.acct, k.app, doorkey.Entry{ID: k.id, SHA256: strings.Repeat("a", 64)}, ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := st.RemoveMember(OpsAccountID, "alice@keymail.dev"); err != nil {
+ t.Fatal(err)
+ }
+ if keys, _, err := st.DoorKeysLive(OpsAccountID, "titogo"); err != nil || len(keys) != 0 {
+ t.Errorf("the account's unattributed key after a removal = %+v, %v; want revoked", keys, err)
+ }
+ if keys, _, err := st.DoorKeysLive(42, "elsewhere"); err != nil || len(keys) != 1 {
+ t.Errorf("another account's unattributed key = %+v, %v; want it live", keys, err)
+ }
+}