messenger: approve only on the controller's recent word that root is free, and close the review's gaps (hq ADR 0259)
The review of 2026-10-09: the router read the absence of an agent-root condition as a pass, and its minute hung on a break-glass file, taking the work it already held. An approval now rests on the controller's verb root-free, asked live for the router's machine and the channel's, failing closed on every other answer, and a stale word on the kinds promises no verified sender. Break-glass runs in the minute, says on every channel what root did, and ends the router's own open questions. An ask offering an approval is answered only where it could be approved; a message says who asks, what each answer does and what expiry does. The router's own asks bind the account they are about; a link is checked against one per kind as it is made; an unlinked account does not come back by a code within a day; a fresh link is unlinked from the desk; no link begins while the desk cannot show its code, and a code is marked secret on every path. Links are bounded per account in the router's state; a warrant's message id cannot be foreseen. Moves to mesh-sdk 76902998 (canonical digests).
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -29,11 +30,19 @@ const SelfAsker = "messenger"
|
||||
// RelinkWaits is how long after an unlink a new link waits for the replaced account's approval.
|
||||
const RelinkWaits = 24 * time.Hour
|
||||
|
||||
// SelfAct is what the router does on its own ask's warrant.
|
||||
// SelfAct is what the router does on its own ask's warrant. It names the account it concerns: an option
|
||||
// binds that account, so a warrant for unlinking one account never unlinks another linked in its place
|
||||
// (the review of 2026-10-09).
|
||||
type SelfAct struct {
|
||||
Do string `json:"do"` // "unlink" or "link"
|
||||
Kind string `json:"kind"`
|
||||
Link *Identity `json:"link,omitempty"` // the account a link makes the operator's
|
||||
Do string `json:"do"` // "unlink" or "link"
|
||||
Kind string `json:"kind"`
|
||||
Identity string `json:"identity"` // the account unlinked, or the account a link makes the operator's
|
||||
Link *Identity `json:"link,omitempty"` // the account a link makes the operator's
|
||||
}
|
||||
|
||||
// act is what an option of the router's own ask binds: its named fields (asks.ActDigest).
|
||||
func (a SelfAct) act() asks.Act {
|
||||
return asks.Act{"do": a.Do, "kind": a.Kind, "identity": a.Identity}
|
||||
}
|
||||
|
||||
// Unlinked is the last account unlinked on a kind, kept a day so a relink is asked of it.
|
||||
@@ -45,7 +54,7 @@ type Unlinked struct {
|
||||
// askSelf puts a question of the router's own to one account, on its kind, and keeps it like any ask.
|
||||
func (h *Holder) askSelf(a asks.Ask, only Identity, act SelfAct) error {
|
||||
// Its options bind the act, as any asker's do (ADR 0259 §6): the warrant then performs this act alone.
|
||||
binds, err := asks.ActDigest(act)
|
||||
binds, err := asks.ActDigest(act.act())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -95,7 +104,7 @@ func (h *Holder) selfAct(rec AskRecord, w asks.Warrant) {
|
||||
}
|
||||
o, err := w.For(SelfAsker, rec.Ask)
|
||||
if err == nil {
|
||||
err = o.Performs(*rec.Act)
|
||||
err = o.Performs(rec.Act.act())
|
||||
}
|
||||
if err != nil {
|
||||
h.Logf("[messenger] REFUSED a warrant for its own ask %s: %v", rec.Ask.ID, err)
|
||||
@@ -103,9 +112,23 @@ func (h *Holder) selfAct(rec AskRecord, w asks.Warrant) {
|
||||
}
|
||||
switch rec.Act.Do {
|
||||
case "unlink":
|
||||
h.unlinkNow(rec.Act.Kind, "approved by the account itself")
|
||||
if o.Level == asks.Acknowledge {
|
||||
// Asked at the desk: only an account still in its first hour, which cannot approve yet, is unlinked
|
||||
// this way (ADR 0259 §7, the review of 2026-10-09). Past its hour it decides for itself.
|
||||
id := h.identity(rec.Act.Kind, rec.Act.Identity)
|
||||
if id == nil || !h.Now().Before(id.ApproveFrom) {
|
||||
h.Logf("[messenger] an unlink chosen at the desk was not done: the account's first hour has passed")
|
||||
h.announce(Message{Title: "An unlink chosen at the desk was not done",
|
||||
Body: "The account's first hour had passed, so only the account itself, or root at the router's " +
|
||||
"machine, can unlink it now.", Urgent: true})
|
||||
return
|
||||
}
|
||||
h.unlinkNow(rec.Act.Kind, rec.Act.Identity, "at the desk, within the hour after it was linked")
|
||||
return
|
||||
}
|
||||
h.unlinkNow(rec.Act.Kind, rec.Act.Identity, "approved by the account itself")
|
||||
case "link":
|
||||
if rec.Act.Link != nil {
|
||||
if rec.Act.Link != nil && rec.Act.Link.Identity == rec.Act.Identity {
|
||||
h.linkNow(*rec.Act.Link, "approved by the account it replaces")
|
||||
}
|
||||
}
|
||||
@@ -126,7 +149,7 @@ func (h *Holder) Unlink(kind string) (map[string]any, error) {
|
||||
"from here stop counting as yours until an account is linked again.", Display(kind), id.Display, id.Identity),
|
||||
Who: asks.Operator, Expires: now.Add(time.Hour), OnExpiry: "the account stays linked",
|
||||
Options: []asks.Option{{ID: "unlink", Label: "Unlink", Does: "this account stops answering as you", Level: asks.Approve}}}
|
||||
if err := h.askSelf(a, id, SelfAct{Do: "unlink", Kind: kind}); err != nil {
|
||||
if err := h.askSelf(a, id, SelfAct{Do: "unlink", Kind: kind, Identity: id.Identity}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h.announceExcept(kind, Message{Title: "An unlink of your " + Display(kind) + " account was asked",
|
||||
@@ -135,23 +158,27 @@ func (h *Holder) Unlink(kind string) (map[string]any, error) {
|
||||
return map[string]any{"kind": kind, "asked": true, "of": id.Display}, nil
|
||||
}
|
||||
|
||||
// unlinkNow unlinks a kind's account: told first, by name, then every channel.
|
||||
func (h *Holder) unlinkNow(kind, how string) {
|
||||
ids := h.identitiesOf(kind)
|
||||
if len(ids) == 0 || h.Asks == nil {
|
||||
// unlinkNow unlinks one account of a kind: told first, by name, then every channel. It unlinks the account it
|
||||
// is named, and nothing when another is linked now.
|
||||
func (h *Holder) unlinkNow(kind, identity, how string) {
|
||||
if h.Asks == nil {
|
||||
return
|
||||
}
|
||||
id := h.identity(kind, identity)
|
||||
if id == nil {
|
||||
h.Logf("[messenger] the unlink of %s on %s was not done: that account is not linked", identity, kind)
|
||||
return
|
||||
}
|
||||
id := ids[0]
|
||||
_ = h.showOn(kind, Message{Title: "This account is no longer linked as you",
|
||||
Body: "Unlinked, " + how + ". Answers from here no longer count as yours.", Urgent: true, To: id.Identity})
|
||||
if err := h.Asks.DeleteIdentity(identityKey(kind, id.Identity)); err != nil {
|
||||
h.Logf("[messenger] the unlink of %s on %s could not be recorded: %v", id.Display, kind, err)
|
||||
return
|
||||
}
|
||||
h.unlinked(kind, Unlinked{Identity: id, At: h.Now()})
|
||||
h.unlinked(kind, Unlinked{Identity: *id, At: h.Now()})
|
||||
h.announce(Message{Title: "No " + Display(kind) + " account is linked as you any more",
|
||||
Body: fmt.Sprintf("Unlinked: %s (number %s), %s. A new link within a day waits for that account's approval.",
|
||||
id.Display, id.Identity, how), Urgent: true})
|
||||
Body: fmt.Sprintf("Unlinked: %s (number %s), %s. A new link within a day waits for that account's approval, "+
|
||||
"and that account itself can be linked again only after a day.", id.Display, id.Identity, how), Urgent: true})
|
||||
h.record(Sent{At: h.Now(), Channel: kind, Key: "(link)", What: "unlinked", Outcome: id.Display + ", " + how})
|
||||
}
|
||||
|
||||
@@ -160,6 +187,19 @@ func (h *Holder) linkNow(id Identity, how string) {
|
||||
if h.Asks == nil {
|
||||
return
|
||||
}
|
||||
// One account per kind, checked again as it is linked: a link approved, or allowed by root, while
|
||||
// another account was linked meanwhile is not made (the review of 2026-10-09).
|
||||
for _, other := range h.identitiesOf(id.Kind) {
|
||||
if other.Identity != id.Identity {
|
||||
h.Logf("[messenger] the link of %s on %s was not made: %s is linked there", id.Display, id.Kind, other.Display)
|
||||
h.announce(Message{Title: "A " + Display(id.Kind) + " link was not made",
|
||||
Body: fmt.Sprintf("%s (number %s) was not linked, %s: the account %s (number %s) is linked there now. "+
|
||||
"One account is linked per channel.", id.Display, id.Identity, how, other.Display, other.Identity),
|
||||
Urgent: true})
|
||||
return
|
||||
}
|
||||
return // already linked
|
||||
}
|
||||
now := h.Now()
|
||||
id.Linked, id.ApproveFrom = now, now.Add(LinkedApproveAfter)
|
||||
if err := h.Asks.PutIdentity(identityKey(id.Kind, id.Identity), id); err != nil {
|
||||
@@ -175,9 +215,12 @@ func (h *Holder) linkNow(id Identity, how string) {
|
||||
h.record(Sent{At: now, Channel: id.Kind, Key: "(link)", What: "linked " + id.Display, Outcome: how})
|
||||
}
|
||||
|
||||
// BreakGlass does what root asked at the router's machine: a file `unlink.<kind>` or `allow-link.<kind>` in the
|
||||
// router's directory, owned by root. Called every minute.
|
||||
func (h *Holder) BreakGlass() {
|
||||
// breakGlass does what root asked at the router's machine: a file `unlink.<kind>` or `allow-link.<kind>` in
|
||||
// the router's directory, owned by root. Called every minute from Tick, which holds the work: it takes no
|
||||
// lock of its own (the review of 2026-10-09 found it took the work again, and so hung the router's minute
|
||||
// the first time root used it). Loud: what root did, or why nothing was done, is said on every channel, and
|
||||
// every open question of the router's own ends, since root decided in its place.
|
||||
func (h *Holder) breakGlass() {
|
||||
if h.StateDir == "" {
|
||||
return
|
||||
}
|
||||
@@ -199,20 +242,58 @@ func (h *Holder) BreakGlass() {
|
||||
Urgent: true})
|
||||
continue
|
||||
}
|
||||
h.work.Lock()
|
||||
where := "at the router's machine"
|
||||
if h.Node != "" {
|
||||
where = "at " + h.Node
|
||||
}
|
||||
done := ""
|
||||
switch what {
|
||||
case "unlink":
|
||||
h.unlinkNow(kind, "at the router's machine, as root")
|
||||
if ids := h.identitiesOf(kind); len(ids) > 0 {
|
||||
h.unlinkNow(kind, ids[0].Identity, where+", as root")
|
||||
done = fmt.Sprintf("the %s account %s (number %s) was unlinked", Display(kind), ids[0].Display, ids[0].Identity)
|
||||
} else {
|
||||
done = "nothing was unlinked: no " + Display(kind) + " account is linked"
|
||||
}
|
||||
case "allow-link":
|
||||
if p, err := h.Asks.GetLink(kind); err == nil && p != nil && p.Confirmed {
|
||||
h.linkNow(Identity{Kind: kind, Identity: p.Identity, Display: p.Display}, "allowed at the router's machine, as root")
|
||||
h.linkNow(Identity{Kind: kind, Identity: p.Identity, Display: p.Display}, "allowed "+where+", as root")
|
||||
done = fmt.Sprintf("the waiting link of %s (number %s) was allowed", p.Display, p.Identity)
|
||||
} else {
|
||||
done = "nothing was linked: no link with its code given waits on " + Display(kind)
|
||||
}
|
||||
}
|
||||
h.work.Unlock()
|
||||
ended := h.endSelfAsks("root decided " + where)
|
||||
body := "Root " + where + " asked it: " + done + "."
|
||||
if ended > 0 {
|
||||
body += fmt.Sprintf(" %d open question(s) of the router's own were ended.", ended)
|
||||
}
|
||||
h.Logf("[messenger] break-glass %s: %s", name, done)
|
||||
h.announce(Message{Title: "Root changed who is you", Body: body, Urgent: true})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// endSelfAsks ends every open ask of the router's own: root decided in their place.
|
||||
func (h *Holder) endSelfAsks(why string) int {
|
||||
h.mu.Lock()
|
||||
var keys []string
|
||||
for k, e := range h.asks {
|
||||
if e.rec.Asker == SelfAsker && e.rec.State == StateOpen {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
h.mu.Unlock()
|
||||
sort.Strings(keys)
|
||||
n := 0
|
||||
for _, k := range keys {
|
||||
if err := h.closeAsk(k, asks.OutcomeCancelled, why, nil, ""); err == nil {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// fileOwner is the uid owning a file; a variable so a test, which is not root, can stand for root.
|
||||
var fileOwner = func(info os.FileInfo) uint32 {
|
||||
if st, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||
|
||||
Reference in New Issue
Block a user