Skip to content

Add a filesystem sandbox for source package builds on Linux - #533

Open
atheriel wants to merge 5 commits into
mainfrom
aj-sandbox-installs
Open

atheriel wants to merge 5 commits into
mainfrom
aj-sandbox-installs

Conversation

@atheriel

@atheriel atheriel commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Note: this is build in top of #530, #531, and #532, so it looks larger than it actually is.

This commit introduces a new lightweight sandboxing mechanism for source package builds on Linux, largely designed to protect the cache from malicious package installs. It includes a new --sandbox flag, defaulting to off.

CRAN policy holds that package builds must not write outside of the build directory or /tmp; this sandbox enforces that, so all well-behaved packages should work with it already. I've spot checked a few popular ones, too.

When possible we also prevent builds from connecting to Unix sockets or sending signals outside of the sandbox, too.

The sandbox mechanism is based on Landlock, which does not require elevated privileges and even works inside of containers. Debian 13, Ubuntu 24.04, and RHEL 9.6 and later all have the requisite kernel support.

Unit tests are included, as is a NEWS entry.

rig uses the package name from the package's own `DESCRIPTION` and uses
it to construct various paths. Previously a name like `../victim` or
`/tmp/x` could prompt rig to create, replace or delete from directories
than intended, so this commit adds a small guard against actively
malicious names at install time.

Unit tests are included.

Signed-off-by: Aaron Jacobs <aaron.jacobs@posit.co>
After a successful `R CMD INSTALL`, rig patches the `DESCRIPTION` file
and moves the built package into the cache. Previously a maliciously
crafted package could use symlinks (either the `DESCRIPTION` file or the
package directory itself) to make rig itself write to arbitrary
filesystem locations; this commit hardens rig against symlink misuse at
this stage.

Unfortunately, there's a lot of complexity here to prevent TOCTOU
attacks.

Unit tests are included.

Signed-off-by: Aaron Jacobs <aaron.jacobs@posit.co>
Previously a local source was copied into a deterministic location in
rig's cache during installation. As of this commit we move them into a
fresh directory for the build instead, the same approach we use for git
sources.

This sidesteps various race issues and potential pitfalls of a
partially-built packages (as discussed in #526).

Unit tests are included.

Signed-off-by: Aaron Jacobs <aaron.jacobs@posit.co>
This commit introduces a new lightweight sandboxing mechanism for source
package builds on Linux, largely designed to protect the cache from
malicious package installs. It includes a new `--sandbox` flag,
defaulting to `off`.

CRAN policy holds that package builds must not write outside of the
build directory or `/tmp`; this sandbox enforces that, so all
well-behaved packages should work with it alrady. If spot checked a few
popular ones, too.

When possible we also prevent builds from connecting to Unix sockets or
sending signals outside of the sandbox, too.

The sandbox mechanism is based on Landlock, which does not require
elevated privileges and even works inside of containers. Debian 13,
Ubuntu 24.04, and RHEL 9.6 and later all have the requisite kernel
support.

Unit tests are included, as is a NEWS entry.

Signed-off-by: Aaron Jacobs <aaron.jacobs@posit.co>
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.65248% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.36%. Comparing base (88f04e6) to head (a7e8715).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/sandbox.rs 82.12% 37 Missing ⚠️
src/install.rs 97.51% 5 Missing ⚠️
src/main.rs 0.00% 5 Missing ⚠️
src/escalate.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #533      +/-   ##
==========================================
+ Coverage   69.20%   69.36%   +0.15%     
==========================================
  Files          97       98       +1     
  Lines       55815    56212     +397     
==========================================
+ Hits        38628    38989     +361     
- Misses      17187    17223      +36     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant