Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(security/policy): add README for security policy module

Steven Enamakeladbdc59ee346
diff --git a/crates/openhuman-core/src/security/policy/README.md b/crates/openhuman-core/src/security/policy/README.md
index 1137af788a..5e68da6f66 100644
--- a/crates/openhuman-core/src/security/policy/README.md
+++ b/crates/openhuman-core/src/security/policy/README.md
@@ -28,7 +28,7 @@ trusted roots, and the per-hour action budget.
| `path_checks.rs` | `is_workspace_internal_path`, `is_always_forbidden`, `check_cross_profile`, `is_within_trusted_root`, `is_resolved_path_allowed[_for]`, `check_resolved_against_forbidden` |
| `command_checks.rs` | `classify_command`, `gate_decision`, `check_gated_command`, `is_command_allowed`, `command_risk_level`, `parse_declared_class`, `is_command_executor`, `split_unquoted_segments` |
| `enforcement.rs` | `can_act`, `enforce_write_tier`, `enforce_tool_operation`, `record_action`/`is_rate_limited`, `from_config`, `with_active_profile`/`with_privacy_mode`, `openhuman_scratch_dir`/`ensure_openhuman_scratch_dir`, `validate_path_within_root` |
-| `policy_command.rs` (`policy_command_part_01.rs`, `policy_command_part_02.rs` via `#[path]`) | Command-allowlist matching split across parts for file-size hygiene |
+| `policy_command.rs` (`include!`s `policy_command_part_01.rs`, `policy_command_part_02.rs`) | Shell-parsing helpers behind the command checks: `split_unquoted_segments`, `skip_env_assignments`, `normalized_command_name`, `is_command_executor`, `classify_segment`, `has_hidden_execution`, `contains_unquoted_char` |
## Public surface
@@ -39,12 +39,15 @@ Re-exported through `policy/mod.rs` and then through `security/mod.rs`:
`POLICY_DENIED_MARKER`, `validate_path_within_root`,
`ensure_openhuman_scratch_dir`, `openhuman_scratch_dir`.
-`live_policy.rs` (`security/live_policy.rs`, a sibling of this directory)
-holds the hot-swappable *current* `SecurityPolicy` in a process-global cell so
-a runtime `[autonomy]` config change is observed by new sessions immediately
-instead of only at the next full policy rebuild. `security_for_tool_context`
-clones the live policy with its `action_dir` overridden to a profile's own
-directory when a turn runs under a dedicated-workspace profile.
+`security/live_policy.rs` (a sibling of this directory) holds the *current*
+`SecurityPolicy` in a process-global cell: new sessions `install` the latest
+policy and `reload_from` / `reload_privacy` swap it the moment the config is
+saved. `security_for_tool_context` (`tools/impl/filesystem/mod.rs`,
+`tools/impl/system/mod.rs`) clones a tool's policy per call and, when the run
+carries a workspace descriptor, sets `action_dir` to that root and pushes it
+as a `ReadWrite` `TrustedRoot`; `is_always_forbidden` and
+`is_workspace_internal_path` are evaluated before any trusted-root shortcut,
+so the grant cannot widen them.
## Invariants
@@ -55,13 +58,13 @@ Each of these must not be weakened to make a feature work:
`workspace_dir` holds core-internal state (memory DBs, sessions, tokens) and
is never reachable from an agent tool call. Kept as two separate fields on
`SecurityPolicy` (`types.rs`) specifically so the two roots can diverge.
-- **`is_workspace_internal_path`** (`path_checks.rs:420`) — true for any path
+- **`is_workspace_internal_path`** (`path_checks.rs`) — true for any path
whose first component under `workspace_dir` is in `WORKSPACE_INTERNAL_DIRS`
- (`types.rs:173`) or `WORKSPACE_INTERNAL_FILES` (`types.rs:211`), or starts
+ or `WORKSPACE_INTERNAL_FILES` (`types.rs`), or starts
with `memory-`, `memory_tree-`, or `session_raw-`. Checked against the
canonicalized form of both paths when possible, falling back to the raw
paths for not-yet-existing targets.
-- **`is_always_forbidden`** (`path_checks.rs:471`) — case-insensitive,
+- **`is_always_forbidden`** (`path_checks.rs`) — case-insensitive,
segment-based match against `SENSITIVE_COMPONENTS` (`.ssh`, `.gnupg`,
`.aws`, `.azure`, `.kube`, `keychains`, Windows DPAPI dirs) plus a prefix
match against `SYSTEM_PREFIXES` (`/etc`, `/root`, `/boot`, `/proc`, `/sys`,
@@ -70,14 +73,15 @@ Each of these must not be weakened to make a feature work:
directories (`/usr`, `/opt`, `/var`, `~/Library`) deliberately stay in the
user-overridable `forbidden_paths` list instead, so a grant can still reach
e.g. `/usr/local/...`.
-- **`classify_command`'s fail-closed floor** (`command_checks.rs:126`) — a
+- **`classify_command`'s fail-closed floor** (`command_checks.rs`) — a
command that is not provably read-only (and not a recognized
network/destructive command) is at least `CommandClass::Write`. The highest
class across `;`/`|`/`&&`/`||`/newline-separated segments wins, and any
unquoted redirect (`>`, `>>`) or `tee` lifts the whole command to at least
`Write`. An LLM-declared category (`parse_declared_class`) is
- escalate-only: callers combine it as `gate = classify_command(cmd).max(declared)`,
- so the model can raise the gate but never lower what the runtime determined.
+ escalate-only: `agent/tinyagents/host/security_gate.rs` combines it as
+ `class = check_gated_command(cmd)?.max(declared)`, so the model can raise
+ the gate but never lower what the runtime determined.
- **Approval gate default-on, marker semantics.** `POLICY_BLOCKED_MARKER`
(`[policy-blocked]`) prefixes a *permanent* rejection — the identical call
can never succeed in the current tier (read-only blocking a write, a
@@ -88,7 +92,7 @@ Each of these must not be weakened to make a feature work:
verbatim repeat instead of reiterating a provably-futile call. See
[`../approval/README.md`](../approval/README.md) for the gate itself and its
10-minute default TTL.
-- **Hourly action budget.** `ActionTracker` (`types.rs:124`) is a sliding
+- **Hourly action budget.** `ActionTracker` (`types.rs`) is a sliding
one-hour window; `enforce_tool_operation`'s `Act` arm
(`enforcement.rs`) calls `record_action` and refuses once the count exceeds
`max_actions_per_hour`. `enforce_write_tier` alone (tier only, no budget) is
@@ -100,5 +104,5 @@ Each of these must not be weakened to make a feature work:
- `policy_tests.rs` plus `policy_tests_part_01..05_tests.rs` — behavior tests
for classification, path checks, and tier enforcement.
- `proptest_tests.rs` — property tests over command classification.
-- `enforcement_scratch_dir_tests_tests.rs` — `openhuman_scratch_dir`/
- `ensure_openhuman_scratch_dir` symlink/TOCTOU hardening.
+- `enforcement_scratch_dir_tests_tests.rs` — `openhuman_scratch_dir` is
+ namespaced on every platform and `ensure_openhuman_scratch_dir` creates it.