Repository navigation
fix(box): record an answered Python metadata check as a response - #268
Conversation
… a refused one as an error
## Problem
The hosted Shell records an answered `stat`, `lstat`, or `access` as
`fs:read::response`, also when the answer is "no", and records a check that
Box refuses as `fs:read::error`. Python (Monty) did not follow this rule, in
two directions:
- `os.stat()` of a missing file recorded `fs:read::error`. The script got its
answer (`OSError`), but a budget keyed on
`fs:read::response{read_metadata}` did not count it. So a workload could
probe any number of missing files through the `python3` alias.
- `Path.exists()`, `is_file()`, `is_dir()`, and `is_symlink()` recorded
`Completed` for every failure to reach the parent, also when the swap
guard refused a symbolic link that was swapped into the path after
approval. So a refused check could satisfy a `::response` precondition.
## Solution
- `crates/box/src/run/broker/held.rs`: `HeldPath::reach` holds the parent of
an approved path, or returns `Unreached`. A step of the walk that fails is
an answer when the component is missing, when the host refuses it for
permission, or when the component is not a directory and not a symbolic
link. It is a refusal when the component is a symbolic link, or when the
path is not canonical. `fstatat` with `AT_SYMLINK_NOFOLLOW` on the held
parent tells the kinds apart, because a symbolic link and a regular file
both fail the walk with `ENOTDIR`. `HeldPath::of` keeps its behaviour for
every other caller.
- `crates/box/src/run/broker/python/effects.rs`: `os.stat()` and the four
predicates record `Completed` for an answer and `Failed` for a refusal.
A `stat` of the leaf that fails because the leaf is missing, or for
permission, records `Completed`. The script sees the same return values
and exceptions as before.
- Docs: `docs/user/policy/actions.md`, `docs/design/policy.md`,
`crates/policy/README.md`, and the `docs/design/decisions.md` entry
`temporal-rules-are-enforced-against-recorded-history` state the rule for
Python too.
This changes what `when temporal` observes for Python `read_metadata`. The
operator approved it. A host permission refusal is an answer, as in the
Shell.
## Tests
- `held.rs`: `a_missing_component_is_an_answer`,
`a_regular_file_component_is_an_answer`,
`a_directory_the_host_will_not_search_is_an_answer`,
`a_symbolic_link_component_is_a_refusal`,
`a_dangling_symbolic_link_component_is_a_refusal`,
`a_relative_path_is_a_refusal`, `of_refuses_every_unreached_path`, and
`a_walk_to_an_existing_parent_holds_it`.
- `effects.rs`: `a_stat_of_a_missing_path_records_completed`,
`a_stat_the_host_refuses_for_permission_records_completed`,
`a_predicate_refused_by_an_ancestor_swap_records_failed`,
`a_predicate_of_a_missing_path_records_completed`, and
`a_read_metadata_budget_counts_stats_of_missing_paths`. The existing
`an_ancestor_swapped_for_a_link_after_approval_is_never_followed` still
holds.
- `test-integ`: `MO-PROBE-BUDGET`, `MO-PROBE-PREDICATES`, `SH-PROBE-SHARED`,
and `SH-PROBE-PERMISSION` run a real box. `MO-PROBE-BUDGET` and
`SH-PROBE-SHARED` fail with the `effects.rs` and `held.rs` of `main`.
- With the symbolic-link rule removed, the two symbolic-link tests, the
predicate swap test, and `an_ancestor_swapped_for_a_link_after_approval_is_never_followed`
fail. The two permission tests skip as root.
Ran on macOS, on `main` at `a916050`: `cargo test --workspace
--all-features` (4,373 passed, 0 failed), `cargo fmt --all --check`, the CI
clippy gate, and `test-integ/run.sh` (125 passed, 0 failed, 8 skipped
Linux-only cases).
Not run: the Linux runtime. The `fstatat` failure branch is reached only on
Linux. Still different from the Shell: the reach floor refuses a Python path
whose parent folder does not exist, before this code runs, so that check
records `fs:read::error`.
|
Assessment: Request Changes The walk classification in Checked and held
The |
…the probe tests to what users see - A Python metadata read whose leaf turned into a symbolic link after approval now records `Failed`, as the Shell's identity guard does. Approval admits no link at the leaf, so a link there proves a swap. `a_metadata_read_of_a_leaf_swapped_for_a_link_records_failed` pins it. - The direct `perform` tests keep only paths the reach floor admits. New guard tests drive `admit_and_perform`: a path under this box's own state and a path outside the reachable set spend no metadata budget. - Docs and the decisions entry state the rule per route and with the cases it covers: an answered check of a missing file in an existing folder, or of a file in a folder the host will not search, is a response, and a check that Box refuses is an error. Ran on macOS: `cargo test --workspace --all-features` (4,376 passed, 0 failed), the CI clippy gate, `cargo fmt --check`, and `test-integ/run.sh` (125 passed, 0 failed, 8 skipped Linux-only cases).
|
Assessment: Request Changes Re-reviewed at 9c27de9. The test fix holds: the direct Checked and held
|
Summary
Problem: This is the Python follow-up to #144. #144 made the Shell record a file check that got an answer as
fs:read::response, and a check that Box refuses asfs:read::error. Python did not follow that rule.os.stat()of a missing file was recorded as an error, so a probe cap did not count it, and the agent could probe missing files without limit throughpython3. AndPath.exists()and its siblings recorded a symlink-swap refusal as completed, so a refused check could satisfy a::responserule.Fix: Python now records an answered check as a response and a refused one as an error, the same way the Shell does.
Description
os.stat("missing.txt")os.stat("notes.txt/child")Path("locked/f.txt").exists()Path("dir/f.txt").exists()False)os.stat("f.txt")How.
HeldPath::reachreturns why a walk stopped. A missing component, a permission refusal, or a regular file is an answer. A symlink is a refusal.fstatattells the two apart, because a symlink and a regular file both fail the walk withENOTDIR.HeldPath::ofdoes not change for other callers.os.stat()and the four predicates record the outcome from that. What the script sees does not change.Interface change, approved by the operator. This changes what
when temporalobserves for Pythonread_metadata.docs/user/policy/actions.md,docs/design/policy.md,crates/policy/README.md, anddocs/design/decisions.mddescribe it.Related Issues
Follow-up to #144, which made the same change for the Shell and left Python as a separate change.
Type of Change
Bug fix
Testing
MO-PROBE-BUDGET(3 missing-filestat()calls trip a cap of 3, and 2 do not),SH-PROBE-SHARED(a Shelltest -eand a Pythonstat()share one budget),SH-PROBE-PERMISSION(a permission refusal is an answer through both routes), andMO-PROBE-PREDICATES.MO-PROBE-BUDGETandSH-PROBE-SHAREDfail on main.held.rs, and forstat()and the predicates ineffects.rs, through the reach floor where it applies (admit_and_perform). With the symlink rule removed, the swap tests fail, includingan_ancestor_swapped_for_a_link_after_approval_is_never_followed.cargo test --workspace --all-features(4,376 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.