Software networking with isolation for Tart
Go to file
Fedor Kororkov 08200b7a09
Add dynamic Softnet policy control (#181)
* Add dynamic Softnet policy control

* Simplify Softnet policy RPC methods

* Use jsonrpsee types for Softnet policy RPC

* Reject superseded Softnet policy revisions

* Apply Softnet policy updates only after enqueue

* Flush final Softnet response after input EOF

* Signal EOF when disabling Softnet control

* Normalize Softnet default-route isolation

* Keep policy rules on Proxy (#182)

* Simplify Softnet policy protocol

* Bound pipelined Softnet policy responses

* Keep Softnet port forwarding active on control wakes

---------

Co-authored-by: edi-oai <edi@openai.com>
2026-07-21 21:30:06 +01:00
.cargo Introduce --block in addition to --allow (#126) 2025-10-21 17:14:28 +04:00
.github Use GitHub macOS 26 runners (#176) 2026-07-07 12:59:26 -04:00
lib Add dynamic Softnet policy control (#181) 2026-07-21 21:30:06 +01:00
src Add dynamic Softnet policy control (#181) 2026-07-21 21:30:06 +01:00
.gitignore Goreleaser Fix (#30) 2024-01-24 19:09:59 +04:00
.goreleaser.yml fix(homebrew): wrap macOS version dependency in on_macos block (#169) 2026-07-07 12:40:37 -04:00
Cargo.lock Add dynamic Softnet policy control (#181) 2026-07-21 21:30:06 +01:00
Cargo.toml Add dynamic Softnet policy control (#181) 2026-07-21 21:30:06 +01:00
LICENSE Relicense under FSL-1.1-ALv2 (#166) 2026-06-05 15:37:14 -07:00
README.md Add dynamic Softnet policy control (#181) 2026-07-21 21:30:06 +01:00
rust-toolchain.toml $ cargo update (#40) 2024-07-23 14:33:31 +04:00

README.md

Softnet

Softnet is a software networking for Tart which provides better network isolation and alleviates DHCP shortage on production systems.

It is essentially a userspace packet filter which restricts the VM networking and prevents a class of security issues, such as ARP spoofing. By default, the VM will only be able to:

  • send traffic from its own MAC-address
  • send traffic from the IP-address assigned to it by the DHCP
  • send traffic to globally routable IPv4 addresses
  • send traffic to gateway IP of the vmnet bridge (this would normally be "bridge100" interface)
  • receive any incoming traffic

In addition, Softnet tunes macOS built-in DHCP server to decrease its lease time from the default 86,400 seconds (one day) to 600 seconds (10 minutes). This is especially important when you use Tart to clone and run a lot of ephemeral VMs over a period of one day.

Please check out this blog post for backstory.

Working model

Softnet solves two problems:

  1. VM network isolation
  2. DHCP exhaustion
    • macOS built-in DHCP-server allocates a /24 subnet with 86400 seconds lease time by default, which only allows for ~253 VMs a day (or 1 VM every ~6 minutes) to be spawned without causing a denial-of-service, which is pretty limiting for CI services like Cirrus CI

And assumes that:

  1. Tart gives it's VMs unique MAC-addresses
  2. macOS built-in DHCP-server won't re-use the IP-addresses from it's pool until their lease expire

...otherwise it's possible for two VMs to receive an identical IP-address from the macOS built-in DHCP-server (even in the presence of Softnet's packet filtering) and thus bypass the protections offered by Softnet.

Installing

For proper functioning, Softnet binary requires two things:

  • a SUID-bit to be set on the binary or a passwordless sudo to be configured, which effectively gives the binary root privileges
    • these privileges are needed to create vmnet.framework interface and perform DHCP-related system tweaks
    • the privileges will be dropped automatically to that of the calling user (or those represented by the --user and --group command-line arguments) once all of the initialization is completed
  • the binary to be available in PATH
    • so that the Tart will be able to find it

Running

Softnet is started and managed automatically by Tart if --net-softnet flag is provided when calling tart run.

Dynamic network policy

Softnet can update the running VM's IPv4 egress policy without restarting the VM. Pass a connected Unix stream socket as --control-fd to enable a newline-delimited JSON-RPC 2.0 control channel. The socket is duplex and must be separate from --vm-fd, which carries VM packets.

The supported methods are softnet.policy.get and softnet.policy.set. A complete policy update looks like this (each request and response occupies one line):

{"jsonrpc":"2.0","id":"42","method":"softnet.policy.set","params":{"allow":["@host","10.0.0.0/8"],"block":["0.0.0.0/0"]}}
{"jsonrpc":"2.0","id":"42","result":{"allow":["10.0.0.0/8","@host"],"block":["0.0.0.0/0"],"ruleCount":3}}

Every request must include a non-null string (at most 256 bytes) or non-negative integer id; notifications are rejected so policy changes always have an acknowledgment. Policy updates are atomic: all targets are parsed and a new prefix map is built before the active policy changes. Longest-prefix matching and block precedence for identical prefixes are preserved. Targets are normalized and deduplicated. A policy update may contain at most 4096 combined allow/block targets, and a request frame may not exceed 1 MiB.

Use block=["0.0.0.0/0"] with specific allow targets for a default-deny policy. Closing the control socket leaves the last accepted policy active.