Repository navigation
fix(security): under an agent session a flag or TOLE_TRUST may only narrow the owner's policy lists (#865) - #871
Merged
Conversation
…arrow the owner's policy lists (#865) A process with TOLE_UNDER_SESSION and no child marker, off serve, acp and mcp, is refused when its --allow, --trust, TOLE_TRUST or hook flags would loosen a key the user config sets: allow and trust entries must be exact entries of the user's (user denies kept), hook lists must keep every user hook. Children tole itself starts, the project config and --config are not inputs. Same environment marker as #867: not a boundary.
| let set = |k: &str| env(k).is_some_and(|v| !v.trim().is_empty()); | ||
| Context { | ||
| session_marker: set(child_env::UNDER_SESSION), | ||
| child_marker: [ |
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
…rrow-only guard (#865) TOLE_UNDER_SESSION is set only by run_command and job_start, so a child tole itself starts does not carry it and needs no exemption, while a script a child agent's run_command started carries it together with the inherited TOLE_AGENT_DEPTH and is guarded.
…rker, profiles and --yes are not covered (#865)
5 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Option B2 of #865 (chosen by the owner; B as first written was withdrawn, see Why). A process that carries
TOLE_UNDER_SESSIONand is notserve,acpormcpis refused at start-up when its flags orTOLE_TRUSTwould loosen a policy list the USER config sets. Closes #865.Why
The resolved lists follow
flag > env > configand a higher layer replaces the whole list below it. So a script thatrun_commandorjob_startran could runtole run --allow '*',--trust workspace,TOLE_TRUST=workspaceor--on-turnend x.shand replace the owner'sallow,trustor hook lists (dropping the stop gate and the deny patterns). Item 3 of the not-fixed list of #858.The first design (compare every session process with the user config) was reported and withdrawn because it breaks legitimate flows, verified in the code: an
agent_startchild gets--allowpatterns that are glob-covered by the PARENT's resolved allow list (children/agents.rs,list_covers(parent_allows), every parent deny inherited), which can be wider than the user config after an owner's--allow; a delegated child takes allow and trust from its flags alone (config/apply.rs, thedelegatedbranch); a trusted project config replaces the user's hook lists by design (config::layered); and an owner'sTOLE_TRUSTis inherited by children. B2 therefore exempts tole-started children and does not look at the project layer.How the child exemption is done (corrected after Cora's review of the first head):
TOLE_UNDER_SESSIONis set bysession_guard::mark, whose only callers arerun_commandandjob_start, and by nothing else. A child tole itself starts (agent_start, delegation) therefore does not carry it of its own and needs no special case. The first head exempted any process with a child variable (TOLE_AGENT_DEPTH, ...), but those are inherited by every process a child's ownrun_commandstarts, so a script at depth 1 carried both and escaped; the child variables are not an exemption any more.Known limits, stated plainly (also in the module doc,
Context, design note §6.2, the threat-model row and the CHANGELOG):agent_startand delegation scrub secrets only (children/agents.rs, around line 878), so a marked process's children carryTOLE_UNDER_SESSION. A child in a chain that already contains a script-started tole is therefore guarded too, and if its flags are glob-covered by the parent but not exact entries of the user config (a script runstole run --allow 'read_*'and its model callsagent_startwithallow=["read_file"]) it is refused. That fails safe and only happens in chains that already contain a marked process. No new marker is added.--profile(a profile'sallowreplaces the allow list when no--allowflag is given, and a user config that sets a key only under a profile is unconstrained here),--yes(auto-approve), the MCP server flags and--workspace. Profiles live in the user config and are an owner choice; the rest are separate surfaces.Changes
tole-cli/src/narrow_guard.rs(next tono_config_guard;tole-coreis untouched):Context::from_env,Inputs::from_flags, and onecheck(user, inputs, ctx). Applies only whenTOLE_UNDER_SESSIONis set (non-blank) and the subcommand is notserve,acpormcp(sandbox_flag_class(..).0). For keys the USER config actually sets:allowentries must be exact entries of the user's list, and every user deny pattern (!x) must be kept when--allowis given (a flag may add its own deny);trustpresets (the flag, elseTOLE_TRUST: the effective input) exact entries of the user's;on_pretool,on_posttool,on_turnendmust contain every user hook (adding is fine).plan_modehas no off switch on the command line or in the environment (checked by a unit test throughSettings::resolve), so nothing needs refusing. The refusal names the key, the user-config value, what is extra or dropped, and the way out ("change the user config yourself, or run this from a terminal (issue security: flags, env and --config replace the owner's policy lists instead of merging or being refused #865)").main.rs: one call beforeSettings::resolve, with the raw user config (cloned before the layered one is built), the flags and the environment; a refusal is a startup error.lib.rs,tests/layering.rs: the module registered as a face module likeno_config_guard.--config(owner-trust-gated bytole config trust),--profile.[sandbox.consumers] run_command = "required"masks the data dir).Delegated child verification, as asked: the child's scope is derived from the parent's, not from the user config.
agent_startcomputes the child's--allowas the parent's own resolved list or the requested patterns each covered by it (children/agents.rsaround lines 745-775,list_covers),delegate.rsbuilds the delegated child withwith_parent_allows(spec.allow), and the child resolves allow and trust from those flags only. That is why narrowing against the user config would refuse a legitimate child, and why this PR exempts it (it lacks the marker of its own, unless its parent was marked): the bound is already enforced in the parent, before spawn.Callers and impact (grep, each checked):
narrow_guard::checkhas one caller (main.rs, startup);session_guard::markhas two callers (run_command.rs,jobs.rs), which is what makes the marker precise;Settings::resolveand the flag/env resolution are unchanged;config_flags(&cli)is only read; theno_config_guardandsandbox_flagsguards are untouched. Behaviour change: a script started byrun_commandorjob_start(at any depth) that runs tole with a wider--allow,--trust,TOLE_TRUSTor fewer hooks than a key the user config sets is now refused; nothing changes for an owner at a terminal, for children tole starts from an unmarked parent, for serve/acp/mcp, or when the user config does not set the key. Tests to rerun:narrow_guard_e2e,no_config_guard_e2e,config_apply,config_check,sandbox_flags_cli,delegated_approval_e2e,serve_delegation_e2e,owner_only_e2e,layering.Testing
narrow_guard_e2e(real binary, scrubbed environment, no provider,TOLE_UNDER_SESSION=1) with the guard neutered by hand (the check given no user config): the three refusal tests FAILED (wider--allow, a dropped deny,--trustandTOLE_TRUSTwider, fewer hooks on--on-pretooland a replaced--on-turnend); restored, they pass. The depth-1 script test (a_descendant_script_of_a_child_agent_is_guarded_despite_the_inherited_child_variables) fails on the first head by construction (it exempted any child variable) and passes now.--allow; a process with only child variables (TOLE_AGENT_DEPTH,TOLE_AGENT_ID,TOLE_DELEGATION_NODE,TOLE_DELEGATION_LOG: what a child tole started by an unmarked parent carries) with a wider--allow;tole acp --allowunder the session marker. Refused: the same child variables TOGETHER withTOLE_UNDER_SESSION(a script a child'srun_commandstarted, or a child of a marked parent). Unit tests (narrow_guard.rs): the marker read from the environment (a blank one is none, child variables alone are not the marker, both together are guarded), the exact-subset rules (a narrower-looking glob that is not listed is refused, an empty user list refuses any entry), flag-first-then-environment for trust, hook superset, andplan_modehaving no off switch.shell-tools(the hook keys need it: without it the user config is refused earlier by the unsupported-key check); the unit tests run in every profile.3e32661(the last commit,a71f7e5, only changes comments, the design note, the threat model and the CHANGELOG):cargo fmt --all --check;cargo clippy --workspace --all-targets --all-features -- -D warnings;cargo clippy -p tole-core -p tole-cli -p tole-tui --no-default-features --all-targets -- -D warnings;cargo clippy -p tole-cli --no-default-features --features shell-tools --all-targets -- -D warnings;cargo check -p tole-core --no-default-features --tests;cargo testof tole-core and tole-cli (default), of tole-core, tole-cli, tole-tui with--no-default-features, and of tole-cli with--no-default-features --features shell-tools, withTOLE_REQUIRE_BWRAP=1and--no-fail-fast: green. After the docs commit: fmt check and a clippy of tole-cli with all features. The attribution grep overorigin/develop..HEADis empty.scripts/review-local.shcannot run (cora is not installed here: exit 1, not a pass), so I self-reviewedgit diff origin/develop...HEADas an adversarial reviewer; Cora found the inherited-variable exemption (fixed in3e32661) and the independent review found the two doc inaccuracies this head corrects. The guard reads the raw USER config (not the layered one, which cannot tell the lists apart); only exact text matches count, so no glob reasoning is trusted; every refusal path returns before any config is applied or any provider is touched; the flag and environment effective input follows the same precedence asSettings::resolve(trust: flag else env). The documented limit is the marker (security: the session marker is an environment variable; a child can clear or forge it #867). An independent reviewer reviewed the code head.