Skip to main content

Crate workpen

Crate workpen 

Source
Expand description

Workpen dest-deny and a per-child process jail. The parent is trusted.

Hosts call dest-deny with an explicit DenyPolicy. There is no process-wide deny slot; a session wrapper can hold the policy:

use std::path::Path;
use workpen::{DenyPolicy, dest_deny_message, is_path_denied};

let policy = DenyPolicy::default();
assert!(is_path_denied(Path::new(".env"), &policy));
assert!(dest_deny_message(Path::new(".env"), ".env", &policy).is_some());

Leftover worktree GC is behind feature = "gc". Hosts pass leftover_dir and saved_ref_prefix on GcConfig. Set age_gc_registered to also age-gc registered worktrees that sit outside leftover_dir. workpen gc leaves that flag off.

Modules§

threat_model
Crate threat model. Not a launch README.

Structs§

CreateFiles
One directory the child may create regular files in.
DenyPolicy
Portable dest-deny policy. Same globs on every OS. Hosts hold this value. There is no process-wide default slot. Clone is cheap.
DestDeny
DoctorFacts
Inputs for doctor_fails. Remount is Linux-only. WFP is Windows-only.
GcConfig
Host knobs. Bline passes leftover_dir = “.bline-worktrees”, saved_ref_prefix = “refs/bline/reclaimed”.
KernelGrant
One grant we will hand to the kernel backend.
KernelPolicy
Process-jail policy. Workspace RW, extra roots RW, existing system dirs Read.
PathGuard
Allowed roots plus an absolute-path policy.
PathGuardBuilder
Builder default policy is AbsolutePathPolicy::Reject.
PathGuardDeny
PreExecReport
Owns the reaper report for one KernelPolicy::apply_pre_exec_report.

Enums§

AbsolutePathPolicy
Policy for absolute dests. Extra roots apply to absolute inputs only.
AgentLockError
CheckDestError
Host composition error. Dest-deny vs PathGuard; do not parse messages.
DestDenyError
DestDenyKind
Why dest-deny rejected a path. Hosts branch on this; do not parse messages.
ExtraRootError
Extra-root resolution. Separate from PathGuardError so hosts can match variants.
FileGrantAttempt
Result of KernelPolicy::try_write_file or KernelPolicy::try_read_file.
FileGrantReason
Why a one-file grant did not add that path.
GcDecision
GcError
KeepReason
Why a worktree must be kept. Hosts branch on this; do not parse messages.
KernelAccess
Access granted for one path. Hosts branch on this; do not parse messages.
KernelApply
Result of applying the jail. Hosts match the variant, not English.
KernelError
Hosts match the variant, not English. New variants are breaking for exhaustive hosts even in 0.x.
PathGuardError
PathGuardKind
Why PathGuard rejected a path. Hosts branch on this; do not parse messages.
Why

Constants§

AGENT_LOCK_NAME
Committed dest-deny file name under the workspace.
VERSION
Crate version from Cargo.toml.

Functions§

check_command_argv
Dest-deny each raw argv dest under root.
check_command_dests
Join extracted command dests under root and dest-deny each.
check_dest
Dest-deny raw; if guard is Some, PathGuard; dest-deny resolved.
check_dests
Refuse if any host-extracted dest leaves the workspace.
child_env_deny_names
Names run_child strips from the child environment.
classify_dest
Classify one dest. Glob vs hardlink only. Does not jail ...
classify_for_age_gc
Age filter then classify. Untracked trees are never age-gc’d.
classify_for_age_gc_with_policy
Like classify_for_age_gc, using policy for glob-only cache name checks.
classify_worktree
Classify keep vs reclaim (age already applied by the caller when relevant).
classify_worktree_with_policy
Like classify_worktree, using policy for glob-only cache name checks.
collect_doctor_facts
Probe this machine. Uses a private temp directory, not the user workspace, and does not plant .env or start a user command.
collect_workspace_dest_denies
Existing dest-deny files and glob directories under workspace, including hardlink siblings. Each directory is read once per call, not once per hardlinked name.
collect_workspace_dest_denies_limited
Same as collect_workspace_dest_denies with a host-chosen entry cap.
default_secret_denies
v1 list is byte-identical to Bline default_secret_denies(). Do not add **/.azure/** or **/.config/gh/**.
deny_patch_dests
Refuse if any host-extracted dest is a secret glob or hardlink sibling.
deny_patch_dests_with_display
Like deny_patch_dests, with a host-chosen display string per dest.
dest_deny_glob_regex
Seatbelt regex for one dest-deny glob under an RW prefix.
dest_deny_message
dest_under_root
Join a relative dest to root. Absolute dests stay as given.
doctor_fails
Exit 1 when the kernel is missing, Linux remount is unavailable, or Windows jail setup failed. WFP skip alone is not a failure.
explain
is_denied_child_env
True when name must not be inherited by the child.
is_env_template_basename
Committed dotenv templates, not live env files.
is_path_denied
kernel_supported
Whether this OS can apply a kernel jail.
load_agent_lock
Load dest-deny globs from workspace/agent.lock.
load_agent_lock_file
Load dest-deny globs from an explicit path.
open_verified_read
check_dest, refuse directories, open for read, then verify_post_open.
parse_max_age
Parse a duration token (7d, 24h, 60m, 30s). Number must be > 0. Does not peel quotes. Hosts strip '7d' / "7d" first.
path_is_denied_glob
path_is_denied_under_root
Glob match for path relative to root when root is set.
path_matches_deny_glob
process_jail
Build a process-jail policy. Does not apply it.
process_jail_with_policy
Same as process_jail with a host DenyPolicy.
reexec_profile_creates
How many times this process created the Windows re-exec AppContainer.
reject_command_secret_path_tokens
Argv / command token scan. Does not parse a full shell.
remove_explicit
Remove one worktree after the unique-work check.
remove_explicit_with_policy
Like remove_explicit, using policy for glob-only cache name checks.
require_applied
Refuse a userspace-only inspect result on the spawn path.
require_dest_hide
Refuse a spawn when Linux dest-deny remount did not hide in-tree dests.
resolve_extra_root
Resolve one extra write dir against cwd. Fail closed on missing, not-a-dir, canonicalize failure, the current user’s home directory, or implicit escape to / or host temp unless the caller named that root explicitly. A subdirectory of home (for example ~/.cache) is still allowed.
resolve_extra_root_pair
Same as resolve_extra_root, plus the absolute path before canonicalize.
resolve_workspace_root
Resolve --root against cwd. Must exist and be a directory. A relative ../ws becomes the absolute workspace, not a PathGuard escape. Implicit canonicalize to / or the host temp root is refused unless asked.
run_gc
Age-gc registered worktrees under leftover_dir. Skip the primary checkout, locked worktrees, and a live cwd. A registered worktree outside leftover_dir is left alone unless GcConfig::age_gc_registered is set. Untracked directories under leftover_dir are Keep(UntrackedWorktree) and never removed. Untracked directories outside leftover_dir are not candidates. Dry-run uses the same live-cwd probe and does not delete. On Windows the probe reads other processes’ working directories. If that list cannot be read, the tree stays.
run_gc_with_policy
Like run_gc, using policy for glob-only cache name checks.
scrub_child_command
Remove denied inherited names. An explicit cmd.env is kept, except loaders.
shutdown_process_jail
Drop the process-wide Windows AppContainer cache.
spawn_after_setup
Call spawn only when token or job setup succeeded.
validate_deny_glob
Gitignore-style dest-deny glob subset.
verify_post_open
Unix inode/dev; Windows file index + volume serial. Re-runs hardlink dest-deny when nlink / nNumberOfLinks > 1.
with_bash_noprofile
Insert --noprofile and --norc after argv0 when the program is bash.
worktree_last_used
Newest of HEAD committer time (git log -1 --format=%ct), index mtime, and a bounded tree walk. Git CLI, not gix.
write_timeout_notice
The deadline line. A full 2>&1 pipe must not block this write.