From 4b11f66b4be36d91112b5c1fe9174b8a886edc3f Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 18 Nov 2026 02:11:40 +0100 Subject: [PATCH] resolution: an own secret's owner may be the operator account or root, as rows of the owner table (ADR 0680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: ADR 0680 §1, §4 --- .../resolution/own_secret_owner_test.go | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/internal/compose/resolution/own_secret_owner_test.go b/internal/compose/resolution/own_secret_owner_test.go index c64d6fa2..9942f1e5 100644 --- a/internal/compose/resolution/own_secret_owner_test.go +++ b/internal/compose/resolution/own_secret_owner_test.go @@ -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") + } + }) } } -- 2.54.0