aspect-build / aspect-build/rules_py

[FR]: Get rules_py working with the hermetic Linux sandbox

Open
#1,521 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
145
Forks
97
Avg merge
1d 1h
Merged PRs (30d)
71

Description

### What is the current behavior?

Currently `py_image_layer` appears to be incompatible with using `linux-sandbox` with `--experimental_use_hermetic_linux_sandbox`.

### Describe the feature

By default `linux-sandbox` mounts the host root filesystem read-only, so it is not very hermetic and it is very easy to escape the sandbox inadvertently. Setting `--experimental_use_hermetic_linux_sandbox` makes it much more hermetic by only mounting directories that are explicitly named.

I tried to get this working, but a handful of tests under e2e/cases/oci failed. The problem centers around the way we create image layers by calling bsdtar with an mtree spec. The hermetic sandbox tends to use hard links in places where symbolic links would otherwise be used, and bsdtar will encode these as hard links in its output. Possibly that would be a reasonable decision, except that we do not want different sandboxing strategies to produce different outputs. The naive fix is to set `nlink=1` in the mtree to tell bsdtar not to produce hard links (see https://github.com/aspect-build/rules_js/pull/2998 for example), but this is not feasible here since it would result in duplicating the roughly 55 MB Python interpreter. This seems fixable but likely requires a bit of work to figure out which files we want to treat as symlinks even though they were materialized as hard links in the sandbox.

Contributor guide

Open the contributing guide

Research direction

Start with py_image_layer and the failing tests under e2e/cases/oci; reproduce them using --experimental_use_hermetic_linux_sandbox and inspect how bsdtar consumes the mtree spec. Done means the OCI tests pass and image layers remain consistent between sandboxing strategies without duplicating the Python interpreter.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.