Repository navigation
fix(shell): record an answered stat, lstat, or access as a response - #144
Conversation
|
Issue (governance): This change alters what Issue (docs): Suggestion: Update |
|
Assessment: Comment The fix is well-targeted and the engine-level backstop in Review themes
Nicely scoped change with tests that each pin a distinct part of the fix — thank you for the clear decision notes in the description. |
1ab7d52 to
4f3e94c
Compare
|
Thanks for the review. All points are addressed in 4f3e94c:
|
|
Assessment: Approve Thanks for the thorough follow-up — I re-reviewed at
The new |
4f3e94c to
79f6dab
Compare
ferdingler
left a comment
There was a problem hiding this comment.
I think there’s a real accounting defect here, but I’d like us to separate that from the severity assessment and the proposed fix.
The reproduction shows that negative metadata answers don’t consume a response-based budget. It doesn’t demonstrate a containment escape, access beyond the authored grants, or credential disclosure. Positive probes still consume the budget. The broader reconnaissance scenario is explicitly untested, so “the operator gets no protection” is overstating what was demonstrated.
Also, the quoted guidance says to key a precondition on ::response. That makes sense when a later operation requires evidence that an earlier operation happened. A cap on attempted probes has a different requirement. Why isn’t counting ::request the right policy for that? A request-based cap passed targeted tests against
I’m particularly concerned about the suggested defense in depth. Converting every failed metadata operation into a completed response also converts reach-floor refusals into completions. That can satisfy a later permission rule. We reproduced that regression with this PR, so this part of the fix can weaken policy enforcement.
Can we reassess the ticket classification against the demonstrated impact and mitigation? I’d support a focused correction to how answered probes are recorded,
with real refusals preserved. I don’t think this ticket justifies the blanket conversion in the policy engine or the additional changes to executable checks and glob enumeration.
|
@ferdingler, thank you for the review. I agree with each point. Severity. The reproduction shows an accounting defect: a "no" answer to a metadata check does not charge a
Defense in depth. Agreed, and thank you for reproducing it. The conversion in Proposed scope for this PR:
Does this scope match what you would support? I will push it when you confirm. |
79f6dab to
fce43b1
Compare
|
Assessment update: Request Changes (superseding my earlier Approve) The head commit moved to The reason I'm withdrawing the approval is the defense-in-depth point in the discussion above, which I agree is valid in the current code:
Your proposed scope resolves both cleanly:
That scope has my support. I'll re-review once it's pushed. |
ferdingler
left a comment
There was a problem hiding this comment.
So this is the current status:
File not found checks should count as completed:
Correctly fixed by this PR.
Actual refusals must not count as completed checks:
Broken by this PR. It converts those too.
Basically, we still need to make Shell distinguish “missing file” from an internal safety refusal.
fce43b1 to
acba0de
Compare
|
@ferdingler, thank you.
What changed:
One change from my earlier proposal: I took Python out of this PR completely, instead of narrowing it. The ticket names only the Shell. In Python, the swap guard and a real "not a directory" answer return the same error code, so a correct fix needs more work. Python keeps its behaviour on main, and I will track it as a separate change. Tests, each of which fails without its part of the change:
The workspace suite passes (4,324 tests), and |
## Problem
A metadata probe that the workload asks and that gets the answer "no" was
recorded as a failed effect. In the hosted Shell, `stat`, `lstat`, `access`,
`is_executable`, and `glob` reported a "no" answer as
`EffectResult::Failed(NotFound)`. In Monty, `os.stat` of a missing path
recorded `FsResult::Failed`. The policy engine wrote each one to history as
`fs:read::error`.
The workload still received the answer, so the effect occurred. A temporal
budget keyed on `fs:read::response{read_metadata}`, which `crates/policy/AGENTS.md`
recommends, counted only the "yes" answers. A workload could therefore test
any number of absent or inaccessible paths under a policy that limits
enumeration.
## Solution
- `crates/shell`: `Mediated::report_probe` records `EffectResult::Completed`
for each answered probe. A denied probe still records no outcome. The
divergence is in `crates/shell/UPSTREAM.md`.
- `crates/box`: the Monty `Stat` effect records `FsResult::Completed` when the
path is missing. The script still gets the exception.
- `crates/policy`: `outcome_event` records a failed `ReadMetadata` outcome as
a completed one, for every PEP. A regression in one PEP cannot remove a
probe from a `::response` budget again.
- Docs: `docs/user/policy/actions.md`, `docs/design/policy.md`, and
`crates/policy/README.md` state that an answered `read_metadata` records
a `::response`. The `docs/design/decisions.md` entry
`temporal-rules-are-enforced-against-recorded-history` records the
decision and its cost, and `answered` cites it.
Observable change: a negative metadata probe now records
`fs:read::response` with `output.result = completed`, not `fs:read::error`.
Also a negative `is_executable` probe and a `glob` with no match record a
response. A rule keyed on `fs:read::error{read_metadata}` no longer matches a
probe. Each change adds events to `::response`, so a budget or a forbid
counts more, not less. The action names and the fields do not change.
## Tests
- `crates/shell/tests/kernel_effect_interception.rs::an_answered_probe_reports_a_completed_effect`
pins that `test -e` and `test -r` of an absent path report `Completed`.
- `crates/policy/src/adapters/shell.rs::a_failed_metadata_read_records_a_response`
pins the engine backstop: a `Failed` metadata outcome charges a
`::response` rule, and a `Failed` content read does not.
- `crates/policy/tests/temporal_shell_record_kinds_e2e.rs`:
`a_metadata_probe_answered_no_records_a_response` and
`a_read_metadata_budget_counts_probes_of_absent_paths` pin the box-level
result through the hosted Shell. `a_metadata_probe_that_finds_the_path_records_a_response`
keeps the positive case.
- `crates/box/src/run/broker/python/effects.rs::a_stat_of_a_missing_path_records_completed`
pins the Monty side.
Each new test failed before its fix. With the Shell fix alone or the engine
backstop alone, the e2e tests pass.
Ran on macOS, on `main` at `0b31256`: `cargo test --workspace --all-features`
(4,291 passed, 0 failed), `cargo fmt --all --check`, the CI clippy gate, and
`test-integ/run.sh` (121 passed, 0 failed, 8 skipped Linux-only cases; two
harness timing tests failed under load and passed when run again).
`crates/box/src/run/broker/python/effects.rs::an_ancestor_swapped_for_a_link_after_approval_is_never_followed`
still holds: a Monty `Stat` that the swap guard refuses reports `Failed`.
The engine still records it as a response, which a budget counts.
Not run: the Linux runtime. `list_dir` of a missing directory still records
`fs:read::error{enumerate}`, and this change does not touch it.
…revert the other probe changes
The first commit recorded every answered metadata probe as a response. It
also recorded refusals as responses: the policy engine converted every failed
metadata read, and the Shell kernel turned an admission-window refusal into a
"no" answer. A refused check could then satisfy a later `::response` rule.
This commit keeps the answered "no" as a response for `stat`, `lstat`, and
`access`, and records each refusal as an error:
- `crates/shell`: `Kernel` gains `stat_answer`, `lstat_answer`, and
`access_answer`, which return an admission-window refusal as an error.
They have no default, so each kernel must forward them. `VfsKernel`
implements them, `CallKernel` and the test kernel forward them, and
`Mediated::report_answer` records `Completed` for an answer and `Failed`
for a refusal.
- `crates/policy`: the conversion in `outcome_event` is removed, so a
reach-floor refusal stays `fs:read::error`.
- `is_executable`, `find_in_path`, and `glob` go back to `main`.
- Python (Monty) goes back to `main`. The ticket names only the Shell.
- Docs describe the Shell checks only, and say to count `fs:read::request`
for a cap on attempts.
What each case records in the policy history. After an admitted check,
the box records one outcome event:
- `fs:read::response`: the check happened and the workload got an answer,
yes or no. A rule keyed on `::response` counts it, for example a cap of
5 checks per hour, or "allow X only after a file check".
- `fs:read::error`: the check did not happen. Box refused it, or it failed
before it gave an answer. A rule keyed on `::response` does not count it.
- No outcome: policy denied the check, so only `fs:read::request` is
recorded.
In the table, `response` is `fs:read::response`, `error` is `fs:read::error`,
and `request only` means policy denied the check. A mark shows whether the
record is right for that case.
| Case | Example | main | Commit 1 | Commit 2 |
|---|---|---|---|---|
| File does not exist | `test -e missing.txt` | error ✗ | response ✓ | response ✓ |
| Parent folder does not exist | `test -e nodir/f.txt` | error ✗ | response ✓ | response ✓ |
| Parent is a regular file | `test -e notes.txt/child` | error ✗ | response ✓ | response ✓ |
| Host says "no access" | `test -r ~/locked` | error ✗ | response ✓ | response ✓ |
| Link check of a missing path | `test -L missing-link` | error ✗ | response ✓ | response ✓ |
| Policy denies the check | a `forbid` on the path | request only ✓ | request only ✓ | request only ✓ |
| Reach floor refuses | a metadata read of `<box_dir>/private/secret.txt` with `fs:read` permitted | error ✓ | response ✗ (engine conversion) | error ✓ |
| Admission-window guard refuses | `test -e present.txt` while the workload creates and deletes a folder | error ✓ | response ✗ (`report_probe`) | error ✓ (`stat_answer`) |
| Run a program by path that is not executable | `./notes.txt` | error | response | error, as on main |
| Glob with no match | `ls *.zzz` | error | response | error, as on main |
| Python stat of a missing path | `os.stat("missing.txt")` | error | response | error, as on main |
| Python stat refused | `os.stat("locked.txt")` raises `PermissionError` | error ✓ | response ✗ | error ✓ |
Tests:
- `an_answered_probe_reports_a_completed_effect` now also runs `test -L`
of a missing path, and fails with the `lstat` of `main`.
- `a_probe_the_admission_window_refuses_reports_a_failure` runs
`test -e`, `test -L`, and `test -r` while the namespace changes. It fails
when a refusal records `Completed`, for each of the three.
- `a_metadata_read_the_floor_refuses_meets_no_response_precondition` fails
with the conversion in `outcome_event`.
- `a_failed_metadata_read_records_an_error` replaces the test that relied on
that conversion.
- The Monty test `a_stat_of_a_missing_path_records_completed` is removed
with the Monty change.
Ran on macOS, on `main` at `78d822b`: `cargo test --workspace
--all-features` (4,324 passed, 0 failed), `cargo fmt --all --check`, the CI
clippy gate, and `test-integ/run.sh` (121 passed, 0 failed, 8 skipped
Linux-only cases).
Not run: the Linux runtime.
93fa441 to
6992dee
Compare
|
Assessment: Approve (replaces my Request Changes on I re-reviewed at Cases traced through
|
Summary
Problem: An operator can cap how many files the agent may check. When the agent checked a file that does not exist, the Shell recorded the check as an error, and a cap keyed on
fs:read::responsedoes not count errors. So the agent could check any number of missing files.Fix: The Shell now records an answered
test -e,test -L, ortest -ras a response, whether the answer is "yes" or "no". A check that Box itself refuses stays an error.Description
What the history records. After an admitted check, the box records
fs:read::responsewhen the check happened and the agent got an answer, orfs:read::errorwhen it did not happen. A check that policy denies records onlyfs:read::request.test -e missing.txttest -e nodir/f.txttest -r ~/locked<box_dir>/private/secret.txttest -e present.txtwhile the namespace changesforbidon the path./notes.txt,ls *.zzzHow.
Kernelgainsstat_answer,lstat_answer, andaccess_answer. They return an admission-window refusal as an error, so the Shell can tell a missing file from its own refusal. They have no default, so each kernel must forward them.MediatedrecordsCompletedfor an answer andFailedfor a refusal, forstat,lstat, andaccessonly.is_executable,find_in_path, andglobdo not change.fs:read::error.Interface change, approved by the operator. This changes what
when temporalobserves. A rule keyed onfs:read::error{read_metadata}no longer matches an answeredtest -e,test -L, ortest -rof a missing path. A cap on attempts should countfs:read::request, which also counts denied attempts.docs/user/policy/actions.md,docs/design/policy.md,crates/policy/README.md, anddocs/design/decisions.mddescribe the new behaviour.Commits. The first commit fixed this broadly, and it also recorded refusals as responses. The second commit narrows it to the above, after review.
Not in this PR. Python (
os.stat(),Path.exists()and the other predicates) keeps its behaviour on main. It needs its own change, because its swap guard and a real "not a directory" answer return the same error code.Related Issues
None
Type of Change
Bug fix
Testing
a_read_metadata_budget_counts_probes_of_absent_paths).an_answered_probe_reports_a_completed_effect:test -e,test -r, andtest -Lof a missing path recordCompleted.a_probe_the_admission_window_refuses_reports_a_failure: under namespace churn, only checks that answered recordCompleted, fortest -e,test -L, andtest -r.a_metadata_read_the_floor_refuses_meets_no_response_precondition: a reach-floor refusal does not satisfy a::responseprecondition, and an answered check does.cargo test --workspace --all-features(4,324 passed, 0 failed), andtest-integ/run.shon macOS (GREEN, 8 Linux-only skips).cargo fmt --all --checkand the CI clippy gate. No new warnings.Not run locally: Linux. CI covers it.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.