sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

Feature: write-only / append-only filesystem grants (fs_write_only / fs_append)

Open dzerik opened this issue 4 months ago • 1 comments

Summary

Add write-only (and ideally append-only) filesystem grants to the public API, e.g. fs_write_only(path) / fs_append(path), in addition to the existing fs_read/fs_write`.

Today fs_write grants read and write: a path passed to fs_write is also readable (the write mask is built as READ_ACCESS | write/create/delete flags). There is no way to let a sandboxed process write to a location it cannot read back, nor to enforce append-only (no truncate/overwrite of existing content).

Motivation

A supervisor/host frequently needs to hand a sandboxed workload a location for significant or audit-relevant output — logs, audit records, telemetry, a drop-box — that the workload must be able to append to but must not be able to:

  • read back (confidentiality / no exfiltration of other tenants' or prior records that share the sink), or
  • overwrite / truncate existing records (tamper-evidence — the workload cannot rewrite history).

With the current read+write grant, sandboxed code that knows the path can open the sink for reading or O_TRUNC and destroy/alter earlier records. For a product exposed to untrusted external code, a tamper-evident audit trail is a common requirement, and today it can only be approximated by writing the sink through a separate privileged channel rather than the filesystem.

Why this is a good fit for Landlock

Landlock already models these as distinct rights, and sandlock already computes per-grant masks (crates/sandlock-core/src/landlock.rs):

  • write-only: LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_WRITE_FILE (+ directory traversal to reach the path), without READ_FILE / READ_DIR. open(path, O_RDONLY) from the sandbox then fails with EACCES.
  • append-only: additionally withhold LANDLOCK_ACCESS_FS_TRUNCATE so the sandbox cannot O_TRUNC/ftruncate existing content (combined with the host opening/handing the sink such that writes are appends).

So the enforcement is kernel-backed and needs no new supervisor logic — only a new grant constructor that emits the narrower mask instead of the current read+write one.

Proposed API (sketch)

// builder
.fs_write_only(path)   // MAKE_REG + WRITE_FILE (+ traversal), no READ_FILE/READ_DIR
.fs_append(path)       // as write_only, also no TRUNCATE

with the same surfaced through the Python/Go bindings (a write_only / append list alongside fs_readable / fs_writable).

Notes

  • Independent of #149 (the run() stdout-capture deadlock); this is a separate confinement-granularity feature.
  • A sandboxed process that opened the file itself still holds whatever fd it opened, so write-only is meaningful primarily for sinks the process must open fresh (it cannot obtain a read fd) or that the supervisor pre-creates — the point is that the path grants no read/truncate right, so no read/rewind/ truncate is possible via the filesystem.

dzerik avatar Jul 17 '26 15:07 dzerik

Thanks, the motivation is sound and the core observation checks out: the write mask in landlock.rs is built as READ_ACCESS | write flags, so today there is no way to grant write without read. Some thoughts on the shape of the fix:

Prefer orthogonal grants over new constructors. Rather than adding fs_write_only, I'd make the existing axes independent: fs_read(path) grants read only, fs_write(path) grants write/create only, and both together grant RW. This mirrors Landlock's own union semantics, maps onto the existing fs_readable / fs_writable binding lists with no new surface (a path only in fs_writable becomes write-only), and avoids a growing constructor zoo. It is a behavioral break for callers who expect fs_write to imply read, but pre-1.0 we prefer hard breaks; we should make it loud (rename to fs_read_write alongside the new pure fs_write in one commit) rather than silent.

fs_append overpromises, and a path grant cannot fix it. Withholding TRUNCATE blocks O_TRUNC/ftruncate, but WRITE_FILE still permits open(O_WRONLY) + pwrite over existing bytes, and TRUNCATE is Landlock ABI v3+ anyway. Landlock has no bit meaning "writes must land at EOF", so anything expressed as a path rule tops out at "no truncate", which is not tamper-evidence. For the audit-sink use case the right mechanism is supervisor-side: pre-open the sink with O_WRONLY | O_APPEND | O_CREAT, hand the fd into the sandbox, and grant nothing on the path. Then open(sink, ...) fails inside the sandbox, read(2) on the fd fails, and every write(2) lands at EOF. Litmus test: a workload doing open(sink); pwrite(fd, junk, len, 0) to corrupt the oldest record succeeds under fs_append but fails at the open under fd handoff. (Known caveat: fcntl(F_SETFL) can clear O_APPEND; closing that needs the seccomp on-behalf machinery we already want for #111, or a pipe through the supervisor.) I'd drop fs_append from this issue and track the fd-handoff sink as a separate feature.

One diagnostic worth including: warn when a write-only path is nested under a broader read grant, since rule union makes the narrower grant silently decorative there. That's the failure mode users will actually hit.

congwang-mk avatar Jul 28 '26 23:07 congwang-mk