Judge: a process's own secrets belong to the account it runs as (ADR 0680) #249

Merged
mesh-tools merged 1 commits from fix/adr0680-credential-owner into main 2026-11-18 01:18:50 +00:00
5 changed files with 308 additions and 109 deletions
+87 -33
View File
@@ -2476,24 +2476,14 @@ func invokeProblems(m catalogue.Manifest) []string {
return problems
}
// ownSecretOwnerProblems is what is wrong with an own secret's declared owner (novox/hq ADR 0436 §1): naming
// an account the module makes — a `user` resource of that name — never root, which a secret file owned by it
// would make readable by anything, and never the operator account's placeholder (`${machine:account}`), which
// the mesh fills per machine and a manifest cannot say safely (novox/hq ADR 0436, settled by the lead).
// ownSecretOwnerProblems is what is wrong with an own secret's declared owner (novox/hq ADR 0680 §1, §2, which
// ends ADR 0436 §1's refusal of root and the operator account here): an account the module makes — a `user`
// resource of that name — the operator account's placeholder (`${machine:account}`) or root. Any other account
// the module does not make is still refused.
func ownSecretOwnerProblems(m catalogue.Manifest, name, owner string) []string {
if owner == "" {
if owner == "" || owner == "root" || owner == "${machine:account}" {
return nil
}
if owner == "root" {
return []string{fmt.Sprintf(
"%s names %q as the owner of its secret %q; an own secret's owner is an account the module "+
"makes, never root (novox/hq ADR 0436 §1)", m.Module, owner, name)}
}
if owner == "${machine:account}" {
return []string{fmt.Sprintf(
"%s names %q as the owner of its secret %q; an own secret's owner is an account the module "+
"makes, never the operator account (novox/hq ADR 0436 §1)", m.Module, owner, name)}
}
for _, r := range m.Resources {
if fmt.Sprint(r["type"]) == "user" && fmt.Sprint(r["name"]) == owner {
return nil
@@ -2501,7 +2491,7 @@ func ownSecretOwnerProblems(m catalogue.Manifest, name, owner string) []string {
}
return []string{fmt.Sprintf(
"%s names %q as the owner of its secret %q, which it does not make: a user resource named %q "+
"(novox/hq ADR 0436 §1)", m.Module, owner, name, owner)}
"(novox/hq ADR 0680 §2)", m.Module, owner, name, owner)}
}
// ownSecretPromptProblems is what is wrong with an own secret's declared prompt, in the module check's words:
@@ -3218,6 +3208,9 @@ func parseManifest(raw []byte, predefined catalogue.PredefinedList) (catalogue.M
problems = append(problems, ownSecretPromptProblems(m, name, own.Prompt, catalogue.IsFamily(name))...)
problems = append(problems, ownSecretOwnerProblems(m, name, own.Owner)...)
}
// The module's secrets-owner is held to the same accounts as an own secret's owner (novox/hq ADR 0680 §2).
problems = append(problems, ownSecretOwnerProblems(m, "(its secrets-owner)", m.SecretsOwner)...)
problems = append(problems, ownSecretReadProblems(m)...)
localOf := map[string]string{}
for _, to := range m.SecretRequirements() {
if _, plain := m.Secrets[to]; plain {
@@ -4204,25 +4197,19 @@ func passableDir(m catalogue.Manifest, id string, depth int) bool {
return false
}
// processAccountProblems is what is wrong with one process's bus account (novox/hq ADR 0436 §1, §2): an
// account the module makes — a `user` resource of that name — never root and never the operator account,
// which a manifest cannot say safely (a node with no account has nothing to resolve it to, novox/hq ADR
// 0436, settled by the lead).
// processAccountProblems is what is wrong with one process's bus account (novox/hq ADR 0680 §1, §2, which ends ADR
// 0436 §1's refusal of root and the operator account here): an account the module makes — a `user` resource of
// that name — the operator account's placeholder (`${machine:account}`) or root. A process that declares bus
// and names no account, or one the module does not make, is refused.
func processAccountProblems(m catalogue.Manifest, processID, user string) []string {
switch {
case user == "":
switch user {
case "":
return []string{fmt.Sprintf(
"%s's process %s declares bus and names no account; a process account is a user resource the "+
"module makes, never root and never the operator account (novox/hq ADR 0436 §1, §2)",
"module makes, the operator account or root (novox/hq ADR 0680 §2)",
m.Module, processID)}
case user == "root":
return []string{fmt.Sprintf(
"%s's process %s runs as root; a process account is the module's own, never root (novox/hq ADR "+
"0436 §1, §2)", m.Module, processID)}
case user == "${machine:account}":
return []string{fmt.Sprintf(
"%s's process %s runs as the operator account; a process account is the module's own, never the "+
"operator's (novox/hq ADR 0436 §1, §2)", m.Module, processID)}
case "root", "${machine:account}":
return nil
}
for _, r := range m.Resources {
if fmt.Sprint(r["type"]) == "user" && fmt.Sprint(r["name"]) == user {
@@ -4230,8 +4217,75 @@ func processAccountProblems(m catalogue.Manifest, processID, user string) []stri
}
}
return []string{fmt.Sprintf(
"%s's process %s runs as %s, which it does not make: a user resource named %s (novox/hq ADR 0436 §1, "+
"§2)", m.Module, processID, user, user)}
"%s's process %s runs as %s, which it does not make: a user resource named %s (novox/hq ADR 0680 §2)",
m.Module, processID, user, user)}
}
// ownSecretReadProblems is what is wrong with a process that names an own secret it cannot read (novox/hq ADR
// 0680 §3): a process resource whose `run` or `env` names an own secret's path must run as that secret's
// resolved owner (its `owner`, else the module's `secrets-owner`, else root) or as root. A module with a
// container is excepted: a container reads its secrets as its own account. A process with no `user` runs as
// root, as the service manager runs it (lead answer A-485 a, b: a container module is any module with a
// `container` resource). A word names a secret only when it is the secret's path (a family's: begins with the path
// up to its `*`).
func ownSecretReadProblems(m catalogue.Manifest) []string {
for _, r := range m.Resources {
if fmt.Sprint(r["type"]) == "container" {
return nil
}
}
var problems []string
for _, r := range m.Resources {
if fmt.Sprint(r["type"]) != "process" {
continue
}
user, _ := r["user"].(string)
if user == "" || user == "root" {
continue
}
var words []string
if run, ok := r["run"].([]any); ok {
for _, w := range run {
words = append(words, fmt.Sprint(w))
}
}
if env, ok := r["env"].(map[string]any); ok {
for _, v := range env {
words = append(words, fmt.Sprint(v))
}
}
for name, own := range m.OwnSecrets {
path, _, _ := strings.Cut(own.Path, "*")
if path == "" {
continue
}
named := false
for _, w := range words {
if w == own.Path || (strings.Contains(own.Path, "*") && strings.HasPrefix(w, path)) {
named = true
}
}
owner := own.Owner
if owner == "" {
owner = m.SecretsOwner
}
if named && owner != user {
problems = append(problems, fmt.Sprintf(
"%s's process %v runs as %s and names its secret %q, which belongs to %s; a process runs as "+
"the owner of an own secret it names, or as root (novox/hq ADR 0680 §3)",
m.Module, r["id"], user, name, ownerWord(owner)))
}
}
}
sort.Strings(problems)
return problems
}
func ownerWord(owner string) string {
if owner == "" {
return "root"
}
return owner
}
// busKeeps says the process resource r's bus declares `keeps` (novox/hq ADR 0626 §1): read from the resource as
@@ -2113,19 +2113,79 @@ func caseAnOwnSecretSaysWhenAnOutsidePartyIssuesIt(t *testing.T) {
}
}
// 1170/AC2: an owner naming an account the module does not make, root, or the operator account's placeholder is
// refused, naming the secret and the account.
// ADR 0680 §2, §4: an own secret's owner of root or the operator account's placeholder is accepted; an owner naming an
// account the module does not make is refused, naming the secret and the account.
func caseAnOwnSecretsOwnerIsRefusedWhenItIsNotAnAccountTheModuleMakes(t *testing.T) {
for name, c := range map[string]struct{ owner, says string }{
"root": {"root", "root"},
"the operator account": {"${machine:account}", "operator account"},
"an account not declared": {"not-made", "not-made"},
for name, c := range map[string]struct {
owner string
ok bool
}{
"root": {"root", true},
"the operator account": {"${machine:account}", true},
"an account the module makes": {"mesh-mail-send", true},
"an account not declared": {"not-made", false},
} {
_, err := ParseManifest([]byte(`{"module":"mesh-mail","version":"1.0","own-secrets":{` +
`"mail-credential-*":{"path":"/var/lib/mesh-mail/mail-credential-*.secret","issued-by":"outside","owner":"` +
c.owner + `"}},"resources":[{"id":"account","type":"user","name":"mesh-mail-send"}]}`))
if err == nil || !strings.Contains(err.Error(), "mail-credential-*") || !strings.Contains(err.Error(), c.says) {
t.Errorf("%s: %v; want a refusal naming the secret and %q", name, err, c.says)
switch {
case c.ok && err != nil:
t.Errorf("%s: refused: %v", name, err)
case !c.ok && (err == nil || !strings.Contains(err.Error(), "mail-credential-*") || !strings.Contains(err.Error(), c.owner)):
t.Errorf("%s: %v; want a refusal naming the secret and %q", name, err, c.owner)
}
}
}
// ADR 0680 §2, §4: the module's secrets-owner is held to the same accounts as an own secret's owner.
func caseASecretsOwnerIsRefusedWhenItIsNotAnAccountTheModuleMakes(t *testing.T) {
for name, c := range map[string]struct {
owner string
ok bool
}{
"root": {"root", true},
"the operator account": {"${machine:account}", true},
"an account the module makes": {"mesh-mail-send", true},
"an account not declared": {"not-made", false},
} {
_, err := ParseManifest([]byte(`{"module":"mesh-mail","version":"1.0","secrets-owner":"` + c.owner +
`","resources":[{"id":"account","type":"user","name":"mesh-mail-send"}]}`))
switch {
case c.ok && err != nil:
t.Errorf("%s: refused: %v", name, err)
case !c.ok && (err == nil || !strings.Contains(err.Error(), c.owner)):
t.Errorf("%s: %v; want a refusal naming %q", name, err, c.owner)
}
}
}
// ADR 0680 §3, §4: a process naming an own secret runs as its resolved owner (its owner, else the module's
// secrets-owner) or as root; any other account is refused; a module with a container is excepted.
func caseAProcessNamingAnOwnSecretMustBeAbleToReadIt(t *testing.T) {
const users = `{"id":"u1","type":"user","name":"alice"},{"id":"u2","type":"user","name":"bob"}`
for name, c := range map[string]struct {
secret, extra, proc string
ok bool
}{
"the resolved owner": {`"path":"/var/lib/x/k","owner":"alice"`, ``, `"user":"alice","run":["./x","--key","/var/lib/x/k"]`, true},
"the owner by secrets-owner": {`"path":"/var/lib/x/k"`, `"secrets-owner":"alice",`, `"user":"alice","env":{"KEY":"/var/lib/x/k"}`, true},
"root": {`"path":"/var/lib/x/k","owner":"alice"`, ``, `"user":"root","run":["./x","/var/lib/x/k"]`, true},
"the operator account": {`"path":"/var/lib/x/k","owner":"${machine:account}"`, ``, `"user":"${machine:account}","run":["./x","/var/lib/x/k"]`, true},
"a secret it does not name": {`"path":"/var/lib/x/k","owner":"alice"`, ``, `"user":"bob","run":["./x"]`, true},
"another account": {`"path":"/var/lib/x/k","owner":"alice"`, ``, `"user":"bob","run":["./x","/var/lib/x/k"]`, false},
"another account by secrets-owner": {`"path":"/var/lib/x/k"`, `"secrets-owner":"alice",`, `"user":"bob","env":{"KEY":"/var/lib/x/k"}`, false},
"a secret owned by root": {`"path":"/var/lib/x/k"`, ``, `"user":"bob","run":["./x","/var/lib/x/k"]`, false},
"a longer word holding the path": {`"path":"/var/lib/x/k","owner":"alice"`, ``, `"user":"bob","env":{"KEY":"/var/lib/x/keyring"}`, true},
"a container module": {`"path":"/var/lib/x/k","owner":"alice"`, ``, `"user":"bob","run":["./x","/var/lib/x/k"]},{"id":"c","type":"container","image":"x"`, true},
} {
raw := `{"module":"x","version":"1.0",` + c.extra + `"own-secrets":{"k":{` + c.secret + `}},"resources":[` + users +
`,{"id":"p","type":"process","artifact":"x",` + c.proc + `}]}`
_, err := ParseManifest([]byte(raw))
switch {
case c.ok && err != nil:
t.Errorf("%s: refused: %v", name, err)
case !c.ok && (err == nil || !strings.Contains(err.Error(), "ADR 0680 §3")):
t.Errorf("%s: %v; want the ADR 0680 §3 refusal", name, err)
}
}
}
@@ -2419,13 +2479,18 @@ func caseAPortWithNoSourceIsRefused(t *testing.T) {
}
}
// 1179/AC2: a bus on a process with no user, user root, or the operator account is refused naming the
// process and the account rule.
// ADR 0680 §2, §4: a bus on a process with no user, or a user the module does not make, is refused naming the
// process; root and the operator account are accepted.
func caseAProcessBusAccountMustBeTheModulesOwn(t *testing.T) {
for name, c := range map[string]struct{ user, says string }{
"no user": {"", "send"},
"user root": {"root", "root"},
"the operator account": {"${machine:account}", "operator"},
for name, c := range map[string]struct {
user string
ok bool
}{
"no user": {"", false},
"an account not declared": {"not-made", false},
"user root": {"root", true},
"the operator account": {"${machine:account}", true},
"the module's own": {"mesh-mail-send", true},
} {
raw := `{"module":"mesh-mail","version":"1.0","emits":["mail.send.sent"],"state":["sends"],` +
`"streams":[{"name":"mail-sends","events":["mail.send.approved"],"retention":"work-queue",` +
@@ -2434,10 +2499,13 @@ func caseAProcessBusAccountMustBeTheModulesOwn(t *testing.T) {
if c.user != "" {
raw += `,"user":"` + c.user + `"`
}
raw += `,"bus":{"emits":["mail.send.sent"]}}]}`
raw += `,"bus":{"emits":["mail.send.sent"],"queues":["mail-sends"]}}]}`
_, err := ParseManifest([]byte(raw))
if err == nil || !strings.Contains(err.Error(), "send") || !strings.Contains(err.Error(), c.says) {
t.Errorf("%s: %v; want a refusal naming the process and %q", name, err, c.says)
switch {
case c.ok && err != nil:
t.Errorf("%s: refused: %v", name, err)
case !c.ok && (err == nil || !strings.Contains(err.Error(), "send")):
t.Errorf("%s: %v; want a refusal naming the process", name, err)
}
}
}
@@ -6414,6 +6482,8 @@ func TestRulesSecrets(t *testing.T) {
t.Run("AnOffersIdentityIsParsedStrictly", caseAnOffersIdentityIsParsedStrictly)
t.Run("AnOwnSecretSaysWhenAnOutsidePartyIssuesIt", caseAnOwnSecretSaysWhenAnOutsidePartyIssuesIt)
t.Run("AnOwnSecretsOwnerIsRefusedWhenItIsNotAnAccountTheModuleMakes", caseAnOwnSecretsOwnerIsRefusedWhenItIsNotAnAccountTheModuleMakes)
t.Run("ASecretsOwnerIsRefusedWhenItIsNotAnAccountTheModuleMakes", caseASecretsOwnerIsRefusedWhenItIsNotAnAccountTheModuleMakes)
t.Run("AProcessNamingAnOwnSecretMustBeAbleToReadIt", caseAProcessNamingAnOwnSecretMustBeAbleToReadIt)
t.Run("AnOwnSecretTakenSomeOtherWayIsRefused", caseAnOwnSecretTakenSomeOtherWayIsRefused)
t.Run("AnUnknownAccessReferenceIsRefusedAtParse", caseAnUnknownAccessReferenceIsRefusedAtParse)
t.Run("AnUnknownPlaceholderKeyIsRefused", caseAnUnknownPlaceholderKeyIsRefused)
@@ -15,6 +15,8 @@ mesh-catalog b5dbfbb784507e211372a7c9640d91f7d6dadd84 modules/*/module.json, m
mesh-host 233bb23bbcb1a829ce2a6164a31a5c5cc4f3d950 internal/apply/placement_guard.go
mesh-catalog 2d5358b8 (milestone 47/G's AM-K1) modules/zsh/module.json alone: the login shell uses operator-channel for
its seat's marked execute (design 46 approval mark §21), which the validator requires (§4)
mesh-catalog cd3b8fe8 (restic's secrets-owner, ADR 0680) modules/restic/module.json and modules/restic/files/** alone: its
processes run as the operator account, so the validator (ADR 0680 §3) needs the secrets-owner it names
To move them, from mesh-delivery's modules/mesh-delivery-indexer directory, with the two repositories checked out
beside mesh-delivery:
@@ -0,0 +1 @@
${config:put-off-bound}
@@ -1,6 +1,9 @@
{
"module": "restic",
"version": "1",
"version": "0.1",
"packages": {
"git.novox.be/novox/mesh-catalog/modules/disk-load/diskreadings": "0.1"
},
"moved": true,
"claims": [
{
@@ -13,13 +16,27 @@
]
}
],
"invokes": [
"seat:mesh-module-assigner.assignments",
"seat:mesh-broker.show"
],
"consumes": [
"mesh-recovery.restore-started",
"mesh-recovery.restored",
"mesh-conditions.findings-asked"
],
"emits": [
"backed-up"
],
"tools": [
"backup_health",
"backup_delete_retired",
"backup_deleted"
],
"secrets-owner": "${machine:account}",
"own-secrets": {
"repository": "${dir:state}/repository.secret"
"repository": "${dir:state}/repository.secret",
"broker": "${dir:state}/broker"
},
"data": {
"own": [
@@ -38,40 +55,48 @@
}
]
},
"config": {
"keep-daily": {
"type": "number",
"description": "How many nightly restore points are kept, a count from 1 to 9999: two weeks undo a mistake noticed within a fortnight. Read by the night, which thins nothing while it does not read (novox/hq issue 416); lowering it deletes the restore points beyond the new count at the next night, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 14
},
"keep-weekly": {
"type": "number",
"description": "How many weekly restore points are kept behind the dailies, a count from 1 to 9999, refused by the night like keep-daily; lowering it deletes the restore points beyond the new count at the next night, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 8
},
"keep-monthly": {
"type": "number",
"description": "How many monthly restore points are kept behind the weeklies, a count from 1 to 9999, refused by the night like keep-daily; lowering it deletes the restore points beyond the new count at the next night, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 6
},
"keep-hand-taken-days": {
"type": "number",
"description": "How many days a restore point taken by hand (node-backup.now, or the mesh's before a module moves) is kept at least, a count from 1 to 9999; it is kept until a later good night of its module exists, and this many days in any case, so the next thinning never takes the one taken against a risky change (novox/hq issue 453). Lowering it lets go of the older ones taken by hand at the next thinning, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 7
}
"config": {
"keep-daily": {
"type": "number",
"description": "How many nightly restore points are kept, a count from 1 to 9999: two weeks undo a mistake noticed within a fortnight. Read by the night, which thins nothing while it does not read (novox/hq issue 416); lowering it deletes the restore points beyond the new count at the next night, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 14
},
"keep-weekly": {
"type": "number",
"description": "How many weekly restore points are kept behind the dailies, a count from 1 to 9999, refused by the night like keep-daily; lowering it deletes the restore points beyond the new count at the next night, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 8
},
"keep-monthly": {
"type": "number",
"description": "How many monthly restore points are kept behind the weeklies, a count from 1 to 9999, refused by the night like keep-daily; lowering it deletes the restore points beyond the new count at the next night, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 6
},
"keep-hand-taken-days": {
"type": "number",
"description": "How many days a restore point taken by hand (node-backup.now, or the mesh's before a module moves) is kept at least, a count from 1 to 9999; it is kept until a later good night of its module exists, and this many days in any case, so the next thinning never takes the one taken against a risky change (novox/hq issue 453). Lowering it lets go of the older ones taken by hand at the next thinning, and that cannot be undone.",
"minimum": 1,
"maximum": 9999,
"trusted": true,
"default": 7
},
"put-off-bound": {
"type": "number",
"description": "minutes an item put off for a restore of the recovery module is waited for before the finding backup-waits is written and the wait ends, so the night never holds its lock without a bound; timed by a bound key of the state put-off (design 47 G sections 561, 557, A-155).",
"minimum": 1,
"maximum": 10080,
"trusted": false,
"default": 60
}
},
"resources": [
{
"id": "state",
@@ -108,6 +133,13 @@
"trusted": true,
"template": "files/retention.conf"
},
{
"id": "put-off-bound",
"type": "file",
"path": "${dir:state}/put-off-bound",
"mode": "0600",
"template": "files/put-off-bound"
},
{
"id": "tool",
"type": "package",
@@ -133,7 +165,32 @@
"MESH_BACKUP_REPOSITORY": "${dir:repository}",
"MESH_BACKUP_PASSWORD_FILE": "${dir:state}/repository.secret",
"MESH_BACKUP_STATE": "${dir:state}",
"MESH_BACKUP_DATA": "${dir:state}/data.conf"
"MESH_BACKUP_DATA": "${dir:state}/data.conf",
"MESH_BROKER_FILE": "${dir:state}/broker",
"MESH_BACKUP_PUT_OFF_BOUND_FILE": "${dir:state}/put-off-bound"
},
"health": {
"kind": "unit"
}
},
{
"id": "awake",
"type": "process",
"name": "restic-awake",
"artifact": "tools",
"run": [
"./restic-backups",
"awake"
],
"user": "${machine:account}",
"env": {
"MESH_BACKUP_DECLARED": "${dir:state}/backups.conf",
"MESH_BACKUP_REPOSITORY": "${dir:repository}",
"MESH_BACKUP_PASSWORD_FILE": "${dir:state}/repository.secret",
"MESH_BACKUP_STATE": "${dir:state}",
"MESH_BACKUP_DATA": "${dir:state}/data.conf",
"MESH_BROKER_FILE": "${dir:state}/broker",
"MESH_BACKUP_PUT_OFF_BOUND_FILE": "${dir:state}/put-off-bound"
},
"health": {
"kind": "tool",
@@ -143,27 +200,6 @@
"looks": 2,
"grace": "60s"
}
},
{
"id": "measure",
"type": "process",
"name": "restic-measure",
"artifact": "tools",
"run": [
"./restic-backups",
"measure"
],
"user": "${machine:account}",
"env": {
"MESH_BACKUP_DECLARED": "${dir:state}/backups.conf",
"MESH_BACKUP_REPOSITORY": "${dir:repository}",
"MESH_BACKUP_PASSWORD_FILE": "${dir:state}/repository.secret",
"MESH_BACKUP_STATE": "${dir:state}",
"MESH_BACKUP_DATA": "${dir:state}/data.conf"
},
"health": {
"kind": "unit"
}
}
],
"build": {
@@ -183,7 +219,8 @@
"MESH_BACKUP_REPOSITORY": "${dir:repository}",
"MESH_BACKUP_PASSWORD_FILE": "${dir:state}/repository.secret",
"MESH_BACKUP_STATE": "${dir:state}",
"MESH_BACKUP_DATA": "${dir:state}/data.conf"
"MESH_BACKUP_DATA": "${dir:state}/data.conf",
"MESH_BACKUP_PUT_OFF_BOUND_FILE": "${dir:state}/put-off-bound"
}
},
{
@@ -192,5 +229,40 @@
"from": "files"
}
]
}
},
"reads": [
"disk-load.readings"
],
"state": [
"good"
],
"requires": [
{
"name": "put-off",
"storage": "key-value",
"template": "state",
"options": {
"key-ttl": true
}
},
{
"name": "findings",
"storage": "key-value",
"template": "state"
},
{
"name": "finding-events",
"storage": "stream",
"template": "events",
"options": {
"events": [
"finding-written.*",
"finding-cleared.*",
"findings-stated.*"
],
"max-age-days": 7,
"max-mib": 16
}
}
]
}