Skip to content

feat(cli): --allow-path / --allow-read-path for per-session filesystem grants#100

Merged
tito merged 5 commits into
mainfrom
feat/new-command-line-opt-0qr
May 22, 2026
Merged

feat(cli): --allow-path / --allow-read-path for per-session filesystem grants#100
tito merged 5 commits into
mainfrom
feat/new-command-line-opt-0qr

Conversation

@tito
Copy link
Copy Markdown
Contributor

@tito tito commented May 22, 2026

Summary

Greywall is deny-by-default for the filesystem: a sandboxed command can only touch the current working directory (plus system paths). Granting one extra directory or file previously required authoring a profile. These two repeatable flags grant that access for a single session, with nothing persisted to disk:

  • --allow-path <path> — grants read+write (appended to AllowRead + AllowWrite)
  • --allow-read-path <path> — grants read-only (appended to AllowRead only)

Since the sandbox is deny-by-default, no --deny-* flags are needed.

Why

A common need is a scratch/temp dir, a sibling project, or a reference dataset for one run — without the ceremony of writing and maintaining a profile. These flags cover that case ergonomically.

How it works

Both flags accept either a directory or a file, and reuse the existing per-session AllowRead/AllowWrite plumbing, so they work on Linux (bubblewrap + Landlock) and macOS (Seatbelt) with no sandbox-layer changes. Paths may be absolute, relative (resolved against CWD), or ~-prefixed. Grants are applied after profile merge and watch overrides so they always take effect; non-existent paths are tolerated, matching --allow.

greywall --allow-path /tmp/work -- mytool                       # rw scratch dir
greywall --allow-read-path /data/reference.csv -- mytool        # ro single file
greywall --allow-read-path /data/refs --allow-path /tmp/out -- mytool   # mixed

Validation

  • Unit test for the flag-merge helper (applySessionAllowPaths)
  • macOS Seatbelt rule test: read-write vs read-only, including a single-file case (no write rule)
  • Linux bind-mount test: --bind (rw) vs --ro-bind (ro), including a file
  • Smoke tests: write-allowed, read-only (write denied), and a negative control
  • Manual end-to-end QA on macOS: happy path, single-file scoping (siblings stay denied), relative/~/non-existent/empty paths, repeatable + mixed flags, and confirmed an explicit profile denyWrite still wins over --allow-path

Checklist

  • make fmt && make lint clean
  • make test passing
  • Docs updated (docs/cli-reference.md)
  • Nothing persisted; session-scoped only

tito added 3 commits May 22, 2026 16:48
…m grants

Add two repeatable flags that grant filesystem access to an extra
directory or file for a single session, without authoring a profile:

  --allow-path       read+write (appended to AllowRead + AllowWrite)
  --allow-read-path  read-only  (appended to AllowRead only)

Both accept a directory or a file and reuse the existing per-session
AllowRead/AllowWrite plumbing, so they work on Linux (bubblewrap +
Landlock) and macOS (Seatbelt) with no sandbox-layer changes. Grants
are applied after profile merge and watch overrides, and nothing is
persisted. Non-existent paths are tolerated, matching --allow.

Tests: unit test for the flag-merge helper, macOS Seatbelt rule test
(rw vs read-only, incl. a file case), Linux bind-mount test, and smoke
tests covering write-allowed, read-only (write denied), and a negative
control.
…-opt-0qr

# Conflicts:
#	cmd/greywall/main_test.go
The Linux test asserted buildDenyByDefaultMounts emits a writable --bind for
--allow-path, but that function only does read-only binds; the writable --bind
for AllowWrite lives in WrapCommandLinuxWithOptions. Extract that inline logic
into writableBindArgs so the test can verify both layers (read --ro-bind for
all grants, writable --bind only for --allow-path). Also fix gosec G301 by
tightening test dir perms to 0o750.
@tito tito marked this pull request as ready for review May 22, 2026 23:48
@tito tito merged commit 1ab2de3 into main May 22, 2026
4 checks passed
@tito tito deleted the feat/new-command-line-opt-0qr branch May 22, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant