Merge pull request 'resolution: an own secret owned by the operator account or root (ADR 0680 §4 test rows)' (#237) from fix/adr0680-own-secret-owner-rows into main

This commit was merged in pull request #237.
This commit is contained in:
2026-11-18 01:18:52 +00:00
@@ -27,45 +27,53 @@ func mailSenderManifest(t *testing.T, own string) mcat.Manifest {
// 1170/AC1: a family owned by the module's own account lands at 0600, owned by that account — and a module's
// other own secrets (no per-secret owner declared) keep secrets-owner, unchanged.
func TestAnOwnSecretsOwnerIsGivenToItsFiles(t *testing.T) {
m := mailSenderManifest(t, "mesh-mail-send")
m.OwnSecrets["smtp-relay-key"] = mcat.OwnSecret{Path: "/var/lib/mesh-mail/smtp-relay-key", Taken: mcat.TakenAtStart}
r := mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{m}}
out, err := Declaration(r, mcat.Rendering{
Needed: map[string]map[string]string{"mesh-mail": {"mail-credential-smtp": "sealed-credential", "smtp-relay-key": "sealed-relay"}},
})
if err != nil {
t.Fatalf("composing the declaration: %v", err)
}
var family, plain map[string]any
for _, res := range out {
if res["type"] != "file" {
continue
}
switch res["path"] {
case "/var/lib/mesh-mail/mail-credential-smtp.secret":
family = res
case "/var/lib/mesh-mail/smtp-relay-key":
plain = res
}
}
if family == nil {
t.Fatalf("the family member was not composed at all: %v", out)
}
if got := family["owner"]; got != "mesh-mail-send" {
t.Fatalf("the family member's owner: %v; want mesh-mail-send", got)
}
// review round 1, finding 7: asserted, not merely logged. ownedBy never sets "mode", so a sealed secret
// file carries none here either — the host applies 0600 to every one regardless (novox/hq ADR 0086) —
// and the owner clause must not have added one of its own that could override that.
if _, has := family["mode"]; has {
t.Fatalf("the family member carries its own mode %v; the owner clause must not set one, so the "+
"host's 0600 for every sealed secret file stands", family["mode"])
}
if plain == nil {
t.Fatalf("the module's other own secret was not composed at all: %v", out)
}
if got := plain["owner"]; got != "mesh-mail" {
t.Fatalf("a secret with no per-secret owner kept %v; want the module's secrets-owner %q", got, "mesh-mail")
// ADR 0680 §1, §4: the owner is the account the manifest names: one the module makes, the operator account
// (`${machine:account}`, filled with the machine's account) or root.
for _, c := range []struct{ name, owner, account, want string }{
{"an account the module makes", "mesh-mail-send", "", "mesh-mail-send"},
{"the operator account", "${machine:account}", "ops", "ops"},
{"root", "root", "ops", "root"},
} {
t.Run(c.name, func(t *testing.T) {
m := mailSenderManifest(t, c.owner)
m.OwnSecrets["smtp-relay-key"] = mcat.OwnSecret{Path: "/var/lib/mesh-mail/smtp-relay-key", Taken: mcat.TakenAtStart}
r := mcat.Resolution{Node: "novox", Account: c.account, Modules: []mcat.Manifest{m}}
out, err := Declaration(r, mcat.Rendering{
Needed: map[string]map[string]string{"mesh-mail": {"mail-credential-smtp": "sealed-credential", "smtp-relay-key": "sealed-relay"}},
})
if err != nil {
t.Fatalf("composing the declaration: %v", err)
}
var family, plain map[string]any
for _, res := range out {
if res["type"] != "file" {
continue
}
switch res["path"] {
case "/var/lib/mesh-mail/mail-credential-smtp.secret":
family = res
case "/var/lib/mesh-mail/smtp-relay-key":
plain = res
}
}
if family == nil {
t.Fatalf("the family member was not composed at all: %v", out)
}
if got := family["owner"]; got != c.want {
t.Fatalf("the family member's owner: %v; want %s", got, c.want)
}
// ownedBy never sets "mode", so a sealed secret file carries none here either: the host applies
// 0600 to every one regardless (novox/hq ADR 0086), and the owner clause must not override it.
if _, has := family["mode"]; has {
t.Fatalf("the family member carries its own mode %v; the host's 0600 must stand", family["mode"])
}
if plain == nil {
t.Fatalf("the module's other own secret was not composed at all: %v", out)
}
if got := plain["owner"]; got != "mesh-mail" {
t.Fatalf("a secret with no per-secret owner kept %v; want the module's secrets-owner %q", got, "mesh-mail")
}
})
}
}