aft icon indicating copy to clipboard operation
aft copied to clipboard

Sandbox: enforce the deny list on Linux with default-allow, and add a network allowlist

Open iceteaSA opened this issue 1 month ago • 2 comments

Summary

The native command sandbox has no network policy, and on Linux the default-allow profile does not enforce its credential deny list. So on Linux there is no profile that is both usable for everyday work and a real boundary for secrets or network egress.

Current state (main, 92084f102, docs/config.md "Native command sandbox")

  • Linux relaxed grants broad Landlock access and only reports its read/write denies as unenforced (config.md:673): "It must not be treated as a secret or write boundary on Linux." Landlock grants are additive, so they cannot subtract ~/.ssh or a credential store from an allowed home directory.
  • Linux strict enforces an allowlist, but "TCP/DNS remain open" (config.md:678). No profile restricts network destinations on any platform.
  • sandbox.read_deny adds paths to protect, but on Linux it is enforced only under strict.

Prior art: Claude Code's sandbox has a strict network allowlist (sandbox.network.strictAllowlist, 2.1.219) and a filesystem deny list.

Proposal

  1. Linux deny list with default-allow. Add a Linux backend that can subtract paths. For example, bubblewrap with the home directory bound and each deny target replaced by an empty tmpfs or masked file, or a mount namespace that does the same. With it, relaxed on Linux would enforce the same fixed denies and read_deny entries as macOS. Keep Landlock for strict.
  2. Network allowlist. A sandbox.network setting: open (current), deny, or allow: ["github.com:443", "crates.io:443", ...]. On Linux, this can be a private network namespace plus a filtering proxy that AFT starts (HTTP CONNECT/SOCKS, set through HTTPS_PROXY / ALL_PROXY). Landlock ABI v4 can also restrict TCP connect by port, but not by host. Report what is enforced, the same way the sandbox reports unenforced denies today.
  3. Out of scope here: credential substitution at egress (the command sees a sentinel value and a proxy puts in the real one). That is credential custody, and it belongs to a custody service such as cortexkit/claustrum, not to AFT. AFT's part would be a proxy hook that such a service can plug into. This issue does not ask AFT to hold credentials.

iceteaSA avatar Oct 22 '26 17:10 iceteaSA

Update at v0.68.0, with a smaller proposal for item 1. It is for read denies only, and it adds no dependency.

Measured at v0.68.0 (Linux, Landlock ABI 11). I added a sandbox.read_deny entry for a folder that holds a planted test file. Then I ran a foreground, a background and a PTY command that read the file:

  • relaxed: AFT installs Landlock, but all three commands read the file. This agrees with sandbox_spawn.rs:2286-2288 ("Relaxed Linux grants all of / and enforces no deny") and docs/config.md:894.
  • strict: all three reads stop with Permission denied. But strict also confines the command to the project roots. Thus it is not usable for a head session that works in many folders.

Proposal. On Linux, let relaxed apply read_deny. To do this, divide the root read grant along each deny path. strict divides project reads with the same procedure today (docs/config.md:900).

For a deny path /a/b/c, grant read access to all children of / but not a. Then grant all children of /a but not b, and all children of /a/b but not c. Use the children that are there at launch. A path that does not go to a deny keeps one broad grant. Writes stay as they are today. If the same procedure can also apply the built-in read denies, that is a bonus.

Limits to put in the docs:

  • A new entry at a divided level stays unreadable to the current command. The next command calculates the grants again and can read it. An example is a new file directly in the home folder when the deny is below the home folder. The strict profile has the same limit for project roots today.
  • A Landlock right on an ancestor also applies below it. Thus, if the ancestors keep the right to list directories, a command can list the names in the denied folder. It cannot read the file contents.
  • Landlock does not control Unix-socket connections. Thus a command can tell an unconfined process, for example the service manager, to read the path. The docs say this for strict (docs/config.md:899).
  • The launch report must move the read denies that AFT applies out of unenforced=[...].

Item 2 (network) and the write denies stay open in this issue.

iceteaSA avatar Nov 27 '26 05:11 iceteaSA

Thanks for measuring this at 0.68.0, and for the smaller proposal.

Some context first. Since 0.68.0 we've built sandbox levels for shell commands (Off, Credentials, Standard and Strict; not released yet). On Linux, read denies are applied with bubblewrap mounts that hide the path when bubblewrap is installed. Without bubblewrap, the Credentials and Standard levels report the denies as unenforced, which is the same gap you found in relaxed.

Your split of the read grant closes that gap with no new dependency, and Strict already uses the same procedure for project roots. We'll add it as the fallback when bubblewrap isn't available, after the levels ship. It will cover the built-in credential denies as well as sandbox.read_deny. The docs will list the limits you described: a new entry at a split level stays unreadable until the next command, names in a denied folder can still be listed, and Unix sockets aren't controlled. The launch report will stop listing the denies it applies as unenforced.

Item 2 (network) and the write denies stay open here.

aft-alfonso[bot] avatar Nov 28 '26 21:11 aft-alfonso[bot]