package provider import ( "io/fs" "os" "path/filepath" "regexp" "slices" "strings" "syscall" ) func (l *AccountLease) validateRuntimeEntries() error { reason := func(category string) error { if l.source.Provider == "claude" { return accountContainment("runtime_claude_" + category) } return accountContainment("runtime_" + category) } allowed := map[string]bool{IdentityFile: true, credentialName(l.source.Provider): true, ".claude.json": true, "history.jsonl": true, "sessions": true, "archived_sessions": true, "session_index.jsonl": true, "shell_snapshots": true, "log": true, "logs": true, "debug": true, "projects": true, "todos": true, "tasks": true, "plans": true, "backups": true, "file-history": true, "telemetry": true, "statsig": true, "paste-cache": true, "downloads": true, "stats-cache.json": true, "models_cache.json": true, "version.json": true, ".last_migration": true, ".codex-global-state.json": true, "equipo-read-sentinel": true} return filepath.WalkDir(l.runtime, func(path string, d fs.DirEntry, err error) error { if err != nil { return reason("walk") } if path == l.runtime { return nil } name := d.Name() rel, err := filepath.Rel(l.runtime, path) if err != nil { return reason("walk") } entryReason := reason if l.source.Provider == "codex" { entryReason = func(category string) error { if known := codexRuntimeCategory(rel); known != "" { return accountContainment("runtime_codex_" + known) } return reason(category) } if strings.HasPrefix(rel, ".tmp/plugins") { return entryReason("policy_entry") } if codexArg0Link.MatchString(rel) && d.Type()&os.ModeSymlink == 0 { return entryReason("special_entry") } } if l.source.Provider == "claude" && (name == claudeRemoteSettings || name == claudeRemoteSyncedAt) { return l.claudeRemoteSettingsEntry(rel) } if d.Type()&os.ModeSymlink != 0 { info, statErr := d.Info() if statErr == nil && l.codexRuntimeLink(path, rel, info) { return nil } return entryReason("special_entry") } if d.Type()&(os.ModeSocket|os.ModeDevice|os.ModeNamedPipe) != 0 { return entryReason("special_entry") } claudeShell := l.source.Provider == "claude" && l.source.Expected.ProviderVersion == ClaudeVersion && (rel == "shell-snapshots" || rel == "session-env") if runtimePolicyEntry(name) && !claudeShell { return entryReason("policy_entry") } if filepath.Dir(path) == l.runtime && ProviderHomeTarget("selected-home", "/home/runner/"+name) { info, err := d.Info() if err != nil || !runtimeEntryMetadata(info) || !info.Mode().IsRegular() || info.Mode().Perm() != 0600 || info.Size() < 1 || info.Size() > 4096 { return reason("marker_metadata") } return nil } top := strings.SplitN(rel, string(filepath.Separator), 2)[0] if l.source.Provider == "claude" { info, e := d.Info() if e != nil || !runtimeEntryMetadata(info) { return reason("metadata") } if handled, e := l.claudeRuntimeEntry(rel, info); handled { return e } } if l.source.Provider == "codex" && l.source.Expected.ProviderVersion == CodexVersion { if top == ".sandbox_migration" || top == "thread-writer-locks" || top == ".sqlite-maintenance.lock" { info, err := d.Info() if err != nil { return entryReason("metadata") } return codexTurnEntry(rel, info) } scratch := top == ".tmp" || top == "tmp" if scratch || codexRuntimeState(top) { info, err := d.Info() if err != nil || !runtimeEntryMetadata(info) { return entryReason("metadata") } if (scratch && rel == top && !info.IsDir()) || (!scratch && !info.Mode().IsRegular()) { return entryReason("kind") } return nil } } if filepath.Dir(path) == l.runtime && !allowed[name] && !strings.HasPrefix(name, "state_") && !strings.HasPrefix(name, "logs_") { return entryReason("unexpected_entry:" + knownEntry(name)) } return nil }) } // knownEntries are names the pinned CLIs are known to write in a home // (2.1.312's own list and its sandbox's protected dotfiles). A refusal // names only these: any other name could be text the session chose. var knownEntries = strings.Fields(`.claude.json.backup .session_ingress_token ide hfi-auth.json daemon jobs teams usage-data shares state uploads feedback feedback-bundles cache mcp-discovery-cache mcp-needs-auth-cache.json gh-pr-status-cache.json local antproto.json ccr bridge-spawn active-time.json loop.md server-sessions.json image-cache file-transfers mcp-skill-archives computer-use.lock server.lock api-dumps chrome local-settings project-settings remote remote-control scratch storage-v2 systemd agent-memory cowork_plugins dump-prompts traces startup-perf keybindings.json .gitmodules .zprofile .zshenv .zlogin .zlogout .bash_login .bash_logout .envrc .ripgreprc .git-credentials .pypirc .pgpass .bash_history .zsh_history .python_history .node_repl_history`) func knownEntry(name string) string { if slices.Contains(knownEntries, name) || claudeScrubStub[name] != 0 { return name } return "unlisted" } // These are startup state in the staged home, never source-home inputs. func codexRuntimeState(name string) bool { switch name { case "installation_id", "goals_1.sqlite", "goals_1.sqlite-shm", "goals_1.sqlite-wal", "memories_1.sqlite", "memories_1.sqlite-shm", "memories_1.sqlite-wal", "queue_1.sqlite", "queue_1.sqlite-shm", "queue_1.sqlite-wal", "thread_history_1.sqlite", "thread_history_1.sqlite-shm", "thread_history_1.sqlite-wal": return true } return false } func runtimeEntryMetadata(info os.FileInfo) bool { stat, ok := info.Sys().(*syscall.Stat_t) return ok && stat.Uid == uint32(os.Getuid()) && info.Mode()&(os.ModeSetuid|os.ModeSetgid) == 0 && (info.IsDir() || (info.Mode().IsRegular() && stat.Nlink == 1)) } // The CLI points these launch shims at its pinned mount inside the namespace. // Readlink compares the text only; the host must never resolve /opt/codex. var codexArg0Link = regexp.MustCompile(`^tmp/arg0-linux/codex-arg0[A-Za-z0-9]{6}/(apply_patch|applypatch|codex-linux-sandbox)$`) func (l *AccountLease) codexRuntimeLink(path, rel string, info os.FileInfo) bool { if l.source.Provider != "codex" || l.source.Expected.ProviderVersion != CodexVersion || !codexArg0Link.MatchString(rel) { return false } stat, ok := info.Sys().(*syscall.Stat_t) if !ok || stat.Uid != uint32(os.Getuid()) || info.Mode()&os.ModeSymlink == 0 || info.Mode()&(os.ModeSetuid|os.ModeSetgid) != 0 { return false } target, err := os.Readlink(path) return err == nil && target == "/opt/codex" } func codexRuntimeCategory(rel string) string { if strings.HasPrefix(rel, ".tmp/plugins") { return "plugins" } if strings.HasPrefix(rel, "tmp/arg0-linux") { return "arg0" } top := strings.SplitN(rel, "/", 2)[0] switch top { case ".tmp": return "dot_tmp" case "tmp": return "tmp" case "skills", "plugins", "installation_id": return top } for _, state := range []string{"goals", "memories", "queue"} { if strings.HasPrefix(top, state+"_") { return state } } return "" }