Skip to content

fix(seatbelt): let a sandbox listen without surrendering proxy confinement - #1166

Merged
Branden Bonaby (bbonaby) merged 1 commit into
mainfrom
darwin-egress-proxy
Sep 16, 2026
Merged

Branden Bonaby (bbonaby) merged 1 commit into
mainfrom
darwin-egress-proxy

Conversation

@caarlos0

@caarlos0 Carlos Alexandro Becker (caarlos0) commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

📖 Description

A sandbox under a runtime proxy could not run a listener on macOS.
python3 -m http.server 8080 --bind 127.0.0.1 failed with EPERM, and no
setting fixed it, because the two things a caller needs were welded together.

bind()/listen() require (allow network-inbound (local ip)), which only
ingress.default: "allow" emits, and validate refused any hostLoopback
differing from ingress.default. So asking for a listener also forced
hostLoopback: "allow", which under a denied egress default emits
(allow network-outbound (remote ip "localhost:*")) — every port on the host. A
client that ignores HTTP_PROXY then reaches host-local services directly,
which is precisely the confinement a proxy exists to provide. Callers had to
give one of the two up.

Only one of the two divergent ingress pairs is actually inexpressible, so
validate now says that instead of rejecting both.

  • hostLoopback: "allow" under default: "deny" stays rejected. It promises
    inbound host-loopback connectivity, and the only rule that could carry it is
    the blanket inbound grant that default: "deny" withholds. Accepting it would
    advertise a grant the profile never makes.
  • hostLoopback: "deny" under default: "allow" is now accepted:
(deny default)
(allow network-outbound (remote ip "localhost:9000"))   ;; the proxy, only
(allow network-inbound  (local ip))                     ;; bind + listen

write_host_loopback_rules needed no change — it already emitted nothing when
loopback is denied under a denied egress default (the (deny default) baseline
carries it) and the explicit localhost:* deny when egress is allowed. Both
newly-reachable cells gained tests instead.

Limitations, stated up front

The container→host half of hostLoopback: "deny" is fully enforced. The
host→container half is not
: (local ip) cannot exclude a loopback peer, so a
host process can connect to the sandbox's listeners, and a workload that binds
0.0.0.0 rather than 127.0.0.1 is reachable on that port from the LAN.
Seatbelt cannot express a local-address filter — a literal
(local ip "127.0.0.1:8080") is a profile syntax error, host must be * or localhost, exactly as for remote. --bind 127.0.0.1 is a convention the
workload follows, not one the sandbox can enforce.

This is documented rather than implied, in both the backend doc and the 0.8
networking spec. It is strictly narrower than the alternative it replaces:
reaching a listener through hostLoopback: "allow" surrenders the
container→host direction as well.

Documentation

Also fixes the fact that made this look unfixable. Under a denied egress
default, bind() comes from ingress.default, not from the egress arm:
(allow network-inbound (local ip)) grants bind() and listen(), while
(allow network-bind (local ip)) grants bind() but not listen(). The
network policy table named network-bind only under egress.default: "allow",
which reads as "a denied egress default denies bind()" and invites widening
the deny posture to "fix" it.

🔗 References

Related to #1032 (not resolved here), and reviewers should know about one
interaction with it. This config was rejected before and is accepted
now:

{ "network": { "egress": { "default": "deny" },
               "ingress": { "default": "allow" } } }

An omitted hostLoopback parses as deny, so it is now a valid posture and
loopback is silently closed. Previously the symmetric check rejected it with a
message that said so explicitly ("an omitted hostLoopback is deny, not an
inherit of default"), which incidentally served as a diagnostic for the
ambiguity #1032 describes. That diagnostic is gone for this shape. Resolving
#1032 (inherit vs. absolute deny) is the right place to decide whether an
omitted hostLoopback under default: "allow" should instead be refused as
under-specified.

🔍 Validation

Automated, on macOS 26.6.2 (aarch64):

Command Result
bash tests/scripts/run_seatbelt_network_test.sh 21 assertions passed (6 new)
cargo test --locked --release --target aarch64-apple-darwin -p mxc_darwin -p seatbelt_common -p wxc_common -p wxc_e2e_tests -p mxc_engine green (133 / 995 / 110 + e2e)
cargo fmt --all -- --check clean
cargo clippy --target aarch64-apple-darwin --locked --release -p mxc_darwin -p seatbelt_common -- -D warnings clean
shellcheck -S warning tests/scripts/run_seatbelt_network_test.sh clean

New coverage: two profile_builder tests for the newly-reachable cells (denied
and allowed egress default), two seatbelt_runner tests (the rejected pair
keeps its message, the accepted pair validates), and two live-suite configs.
The pre-existing rejects_mismatched_ingress_default_and_host_loopback was
rewritten rather than deleted, so it now pins the narrower rejection.

The live suite also gains the egress deny + ingress allow cell, asserting
both the behavior and that no standalone network-bind rule is emitted —
without the second assertion, a change that re-granted bind() from the egress
side would keep the behavioral assertions green while widening the deny posture.

Manual, against real Seatbelt, with a loopback proxy and a separate host-local
origin listener, under egress: deny + ingress: {default: allow, hostLoopback: deny}:

BIND_LISTEN_8080     = OK
PROXY_PORT           = REACHABLE(PROXYOK)
HOST_ORIGIN_DIRECT   = BLOCKED(EPERM)      <- no bypass
EXTERNAL             = BLOCKED(EPERM)

python3 -m http.server 8080 --bind 127.0.0.1  ->  host curl: HTTP 200

Review-feedback commits on top of the original change, each re-validated with
cargo fmt --all -- --check, cargo test -p seatbelt_common (133 passed),
cargo check -p wxc_e2e_tests --tests, and shellcheck -S warning:

Commit Change
40130b19 The rule-order assertion compared Option<usize> positions without first asserting the broad (allow network-outbound) exists, so Some(deny) > None kept it green if that rule disappeared.
3df4fa0a The backend-guide rejection table and schema-updates.md still said every differing hostLoopback/ingress.default pair is rejected.
6374c499 Same stale claim in local_network_allowed's rustdoc, the rejections-suite case label, the e2e characterization comment, and the Copilot instructions. The rejection fixture itself was already the correct pair; only its label was wrong.

Schema 0.9.0-alpha

Since #1145 completed the directional cutover, both decisions were re-verified
against the exact v0.9 contract, end to end with a release mxc-exec-mac:

v0.9 config Result
ingress: {default: allow, hostLoopback: deny} runs; LISTEN_OK
ingress: {default: deny, hostLoopback: allow} rejected, backend_error, exit 255

With a host listener on 127.0.0.1:8099 (reachable from the host, HTTP 200),
the accepted pair under egress.default: "deny" gives
HOSTLOOPBACK_BLOCKED / EXTERNAL_BLOCKED / LISTEN_OK — identical to 0.8, so
the container-to-host confinement holds under v0.9.

Two seatbelt_runner tests now pin this through the real parser rather than a
hand-built ContainerPolicy. The rejection test is the guard: an adapter that
dropped ingress would make validate return Ok and fail it, while every
policy-level test in that module stayed green.

Not verified: only macOS 26.6.2 arm64 was exercised. hostLoopback validation
here is Seatbelt-specific, so other backends are untouched.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

@caarlos0
Carlos Alexandro Becker (caarlos0) requested review from a team and a balanced review from Copilot September 15, 2026 04:51
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The accepted posture only partially enforces an explicit bidirectional deny, and related documentation and an ordering assertion remain inconsistent.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Enables Seatbelt listeners while preserving proxy-confined outbound traffic.

Changes:

  • Allows ingress-default allow with host-loopback deny.
  • Adds profile, validation, and live network tests.
  • Documents Seatbelt’s asymmetric enforcement limitations.
File Description
tests/​scripts/​run_seatbelt_network_test.sh Adds directional network assertions.
tests/​configs/​seatbelt_net_ingress_allow_loopback_deny.json Adds asymmetric ingress test config.
tests/​configs/​seatbelt_net_egress_deny_ingress_allow.json Adds bind/listen test config.
src/​core/​wxc_common/​src/​config_parser.rs Updates parser inventory counts.
src/​backends/​seatbelt/​common/​src/​seatbelt_runner.rs Tests validation behavior.
src/​backends/​seatbelt/​common/​src/​seatbelt_policy.rs Narrows divergent-policy rejection.
src/​backends/​seatbelt/​common/​src/​profile_builder.rs Adds profile-generation tests and guidance.
docs/​seatbelt/​seatbelt-backend.md Documents listener and loopback behavior.
docs/​sandbox-policy/​0.8.0/​networking/​networking.md Updates Seatbelt networking caveats.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/seatbelt/seatbelt-backend.md Resolved
@richiemsft

Richie Gomez (richiemsft) commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The accepted configuration reports a bidirectional host-loopback deny while leaving inbound host and LAN connectivity unenforced.

Review tier: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
Previously missed (2)

In code that hasn't changed since last review

Low severity Update the stale local-network rustdoc

src/​backends/​seatbelt/​common/​src/​seatbelt_policy.rs:176

The local_network_allowed rustdoc at lines 56-58 still states that hostLoopback must match default, which is no longer true after this validation change. Update it to explain that the inbound rule follows ingress.default and that only allow-under-deny remains rejected.

Low severity Correct the fixture-delta explanation

src/​core/​wxc_common/​src/​config_parser.rs:4484

These fixtures do not differ from seatbelt_net_egress_deny.json only by an ingress block: both also change the process probe, and the loopback-deny fixture changes its output markers and listener helper substantially. Clarify that those process differences do not affect parsing rather than claiming they do not exist.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Several repository comments, tests, and contributor instructions still state that all divergent Seatbelt loopback postures are rejected.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (3)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation and coverage are coherent; only a minor inaccurate test comment remains.

Review tier: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Low severity Correct the claimed fixture-only difference

src/​core/​wxc_common/​src/​config_parser.rs:4485

These fixtures do not differ from seatbelt_net_egress_deny.json only by an ingress block: both also use different process.commandLine probes and marker names. The inventory conclusion is still valid, but this explanation should avoid asserting a comparison the files do not satisfy.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The validation change is narrowly scoped, consistently documented, and covered by unit and live behavioral tests.

Review tier: Balanced
Findings: None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The behavior is consistently implemented, tested, and documented; the remaining corpus-comment correction is non-blocking.

Review tier: Balanced
Findings: 1 Low severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The validation change is narrowly scoped, consistently documented, and covered by unit and live macOS tests.

Review tier: Balanced
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 15, 2026 15:30
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Sep 15, 2026
Copilot AI review requested due to automatic review settings September 15, 2026 21:20
@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Attention Requires attention or a decision from the MXC maintainers. and removed Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. labels Sep 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation and coverage are coherent; remaining feedback concerns minor documentation alignment.

Review tier: Balanced
Findings: 2 Low severity

Open (2)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The backend guide retains two contradictory security and configuration statements about the newly accepted partial-enforcement posture.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 2 Low severity

Open (2)
Resolved since last review (2)

Comment thread docs/seatbelt/seatbelt-backend.md Resolved
Comment thread docs/seatbelt/seatbelt-backend.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It intentionally relaxes a security-policy validation boundary with asymmetric enforcement and was validated on only one macOS architecture/version.

Review tier: Balanced
Findings: None

Resolved since last review (2)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The change intentionally permits partial enforcement of a bidirectional security policy and warrants final human security review.

Review tier: Balanced
Findings: None

…ement

A sandbox under a runtime proxy could not run a listener on macOS.
`python3 -m http.server 8080 --bind 127.0.0.1` failed with EPERM, and no
setting fixed it, because the two things a caller needs were welded together.

`bind()`/`listen()` require `(allow network-inbound (local ip))`, which only
`ingress.default: "allow"` emits, and `validate` refused any `hostLoopback`
differing from `ingress.default`. So asking for a listener also forced
`hostLoopback: "allow"`, which under a denied egress default emits
`(allow network-outbound (remote ip "localhost:*"))` -- every port on the
host. A client that ignores HTTP_PROXY then reaches host-local services
directly, which is precisely the confinement a proxy exists to provide.

Only one of the two divergent ingress pairs is actually inexpressible, so
`validate` now says that instead of rejecting both:

- `hostLoopback: "allow"` under `default: "deny"` stays rejected; the only
  rule that could carry it is the blanket inbound grant that `deny` withholds.
- `hostLoopback: "deny"` under `default: "allow"` is accepted, enforcing the
  container-to-host half. The blanket inbound grant over-permits the
  host-to-container half, which Seatbelt cannot express and which the backend
  guide and the 0.8 networking spec now document.

`write_host_loopback_rules` needed no change. The docs also stop saying that a
denied egress default denies `bind()`: under `(deny default)`, `bind()` comes
from `ingress.default`, not from the egress arm.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fa9c67fe-4054-45cc-9901-da0b06ab7b5d
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The validation change is consistent with profile generation and is covered by focused unit, parser, and live-backend tests.

Review effort: Balanced
Findings: None

@bbonaby
Branden Bonaby (bbonaby) merged commit 27a89d9 into main Sep 16, 2026
27 checks passed
@bbonaby
Branden Bonaby (bbonaby) deleted the darwin-egress-proxy branch September 16, 2026 17:47
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Needs-Attention Requires attention or a decision from the MXC maintainers. label Sep 16, 2026
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.

5 participants