Repository navigation
Description
Version
develop at 584d63a. Item 1 of the not-fixed list of #858. DESIGN DECISION: options and my recommendation below; I will not implement before the owner answers.
Operating system
Any.
What happened?
Every guard that distinguishes "an agent session started this process" from "the owner at a terminal" keys on child_env::under_session(env): TOLE_UNDER_SESSION set (non-blank) or TOLE_AGENT_DEPTH >= 1 (children/child_env.rs). session_guard::mark sets the marker on every process run_command and job_start start. Guards using it (grep): config/owner_only.rs (cron create|resume|edit, plugin approve, skills approve, config trust), sandbox_flags.rs (--sandbox/--no-sandbox), no_config_guard.rs (--no-config, #855), plugin/cmd.rs, cron/mod.rs, skill/approve.rs, skill/drafts.rs, sandbox_cmd.rs, config/project_trust.rs.
An environment variable is controlled by the process that owns it. A script an unsandboxed run_command/job_start starts can env -u TOLE_UNDER_SESSION -u TOLE_AGENT_DEPTH (or env -i, sudo, a clean exec) and then run a copy of the tole binary: every guard above sees "owner". session_guard::check_session_argv stops the model from naming the marker or the tole binary in its argv, but not what a script it writes does. All of this is already stated as "defense in depth, not a boundary" (threat-model.md, session_guard.rs); the boundary is the command sandbox, which masks the data dir ([sandbox.consumers] run_command = required). Nothing here is new; the owner asked to look at it again.
What did you expect to happen?
An agent-reachable process cannot take the owner's identity by clearing one variable.
Options
A. Document only (the current position), and point owners at the sandbox. Nothing to build. Honest, but leaves the unsandboxed default open.
B. A non-environment marker. Examples: an inherited file descriptor (survives env -i; Linux/Unix only; a process that deliberately closes it, or a sandbox harden that closes descriptors above 2, loses it; dup/forgery by a deliberate attacker is trivial). Defeats accidents (env -i, sudo), not an attacker who knows. Adds platform code and a fd contract between parent and child.
C. A terminal requirement for the owner-only actions. Owner-only subcommands and the policy-loosening flags require stdin AND stderr to be terminals (as --no-sandbox already does) instead of, or in addition to, the marker. A script started by run_command has no terminal (stdin is null, output piped), so clearing the env does not help. Defeated only by a deliberate pty (python -c 'import pty...'). Cost: the owner can no longer run tole cron create, plugin approve, config trust or --no-config from CI or a provisioning script; the e2e tests of these commands pass flags without a terminal today.
D. Narrow C to where it matters. Keep the owner-only subcommands as they are, but: refuse --no-config without a terminal when the user config sets [sandbox] mode other than off, any [sandbox.consumers], or any non-default [secrets] (reading the user file only to decide, like --no-sandbox reads the sandbox section). Same rule for the list-key loosening of #865. Scripted owners with no policy configured are unaffected; owners who configured a sandbox gain a guard that does not depend on the marker.
E. Ancestry check (walk /proc/<ppid> to a tole session process): Linux only, defeated by a double fork; rejected.
Recommendation
D plus A: do not add another environment-style marker. D gives a real improvement (a tty requirement that survives env -i) exactly where an owner has opted into protection, keeps scripted use working where nothing is protected, and reuses the existing --no-sandbox rule; document that the residual (a deliberate pty, a copied binary with a pty, an interpreter writing the files) is closed only by the sandbox, and recommend run_command = required in the threat model. Not B (platform code for accident-only protection), not C as a blanket rule (breaks owner scripts), not E.
Tests (if D is chosen)
Unit tests of the decision with a hand-built context (no tty + configured sandbox => refused; no tty + nothing configured => allowed; tty => allowed; marker => refused as before). Real-binary e2e: --no-config with the user config setting [sandbox] mode = "required", no tty, no marker => refused naming the config key; with [sandbox] unset => accepted. Rerun: no_config_guard_e2e.rs, sandbox_flags_cli.rs, config_check.rs, config_apply.rs, config_sensitive.rs, owner_only_e2e.rs, layering.rs. Each must fail without the fix.
Activity
fix(security): under an agent session a flag or TOLE_TRUST may only n…