Skip to content

fix(macos): honor -f/--forward port forwarding#99

Merged
tito merged 1 commit into
mainfrom
feat/check-port-foward-on-78z
May 22, 2026
Merged

fix(macos): honor -f/--forward port forwarding#99
tito merged 1 commit into
mainfrom
feat/check-port-foward-on-78z

Conversation

@tito
Copy link
Copy Markdown
Contributor

@tito tito commented May 22, 2026

Problem

On macOS, -f/--forward (and the forwardPorts config field) was silently ignored. A sandboxed process could not reach a forwarded host localhost port:

greywall -- curl localhost:42000          # blocked (expected — deny by default)
greywall -f 42000 -- curl localhost:42000 # ALSO blocked (the bug)

The forwarding logic (NewForwardBridge) lived entirely inside the Linux branch of manager.go, and WrapCommandMacOS never read cfg.Network.ForwardPorts.

Fix

Linux needs a socat bridge because the sandbox runs in an isolated network namespace. macOS shares the host network stack, so forwarding just needs a Seatbelt allow rule. For each forwarded port we now emit:

(allow network-outbound (remote ip "localhost:<port>"))

skipped when allowLocalOutbound already opens all localhost ports. This is narrower than allowLocalOutbound (which opens all host localhost ports), preserving deny-by-default.

Verification (real listener on macOS)

Command Result
curl localhost:PORT (no -f) denied ✓
-f PORT -- curl localhost:PORT succeeds ✓
-f PORT then curl a different port denied ✓ (port-specific)
  • Adds TestMacOS_ProfileForwardPorts.
  • Updates docs that incorrectly described forwarding as Linux-only.
  • make fmt && make lint clean; sandbox/config/cmd tests pass.

Closes #98

On macOS the -f/--forward flag (and forwardPorts config) was silently
ignored: the forwarding logic only ran inside the Linux branch and
WrapCommandMacOS never read cfg.Network.ForwardPorts.

macOS shares the host network stack, so no socat bridge is needed.
Emit a targeted Seatbelt rule per forwarded port:

  (allow network-outbound (remote ip "localhost:<port>"))

skipped when allowLocalOutbound already opens all localhost ports.
This is narrower than allowLocalOutbound, keeping deny-by-default intact.

Adds TestMacOS_ProfileForwardPorts and updates docs that incorrectly
described forwarding as Linux-only.

Closes #98
@tito tito merged commit 32daa9f into main May 22, 2026
4 checks passed
@tito tito deleted the feat/check-port-foward-on-78z branch May 22, 2026 22:03
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.

macOS: -f/--forward port forwarding is ignored

1 participant