claude-code: write the agent's home as its own account where it has one

On the control node agents are to run as an account that cannot become root
(hq ADR 0266). The runtime keeps running as the operator, so the token, the
identity and the home-scope items go to the agent's home through a helper
started as that account; the licence and the account file follow the move,
what was placed in the operator's home goes once the agent holds the licence,
and the guard refuses every tool of a session running as anyone else,
recording to the journal. An API key is taken only from the agent's home and
only when it is one, here and in the licence manager, so the tool cannot carry
off the runtime's credential. Unchanged where no agent account is named.
This commit is contained in:
jochen
2026-10-09 10:14:18 +02:00
parent 7339ce8556
commit b57e6e8144
17 changed files with 1467 additions and 102 deletions
@@ -8,7 +8,6 @@ package main
import (
"bytes"
"encoding/json"
"os"
)
// Identity is an account as the agent's state file names it.
@@ -19,7 +18,7 @@ type Identity struct {
}
func readState(path string) (map[string]any, bool) {
raw, err := os.ReadFile(path)
raw, err := fsys.ReadFile(path)
if err != nil {
return nil, false
}
@@ -54,7 +53,7 @@ func ReadIdentity(path string) *Identity {
func WriteIdentity(path string, id Identity) (bool, error) {
m, ok := readState(path)
if !ok {
if _, err := os.Stat(path); err == nil {
if _, err := fsys.Stat(path); err == nil {
return false, nil
}
m = map[string]any{}
@@ -77,8 +76,8 @@ func WriteIdentity(path string, id Identity) (bool, error) {
return false, err
}
tmp := path + ".mesh-tmp"
if err := os.WriteFile(tmp, raw, 0o600); err != nil {
if err := fsys.WriteFile(tmp, raw, 0o600); err != nil {
return false, err
}
return true, os.Rename(tmp, path)
return true, fsys.Rename(tmp, path)
}