Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.2.0] Fix sandboxing hermetic tmp to take into account sandbox_base #22450

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ private ImmutableSet<Path> collectPathsToMountUnderHermeticTmp(CommandEnvironmen
// into the sandbox when using hermetic /tmp. We attempt to collect an over-approximation of
// these paths, as the main goal of hermetic /tmp is to avoid inheriting any direct
// or well-known children of /tmp from the host.
// TODO(bazel-team): Review all flags whose path may have to be considered here.
return Stream.concat(
Stream.of(cmdEnv.getOutputBase()),
Stream.of(sandboxBase, cmdEnv.getOutputBase()),
cmdEnv.getPackageLocator().getPathEntries().stream().map(Root::asPath))
.filter(p -> p.startsWith(slashTmp))
// For any path /tmp/dir1/dir2 we encounter, we instead mount /tmp/dir1 (first two
Expand Down
11 changes: 11 additions & 0 deletions src/test/shell/integration/sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,17 @@ EOF
bazel shutdown
}

function test_hermetic_tmp_with_tmp_sandbox_base() {
mkdir pkg
cat >pkg/BUILD <<EOF
genrule(name = "pkg", outs = ["pkg.out"], cmd = "echo >\$@")
EOF
mkdir /tmp/sandbox_base
bazel build --incompatible_sandbox_hermetic_tmp \
--sandbox_base=/tmp/sandbox_base //pkg >"${TEST_log}" 2>&1 \
|| fail "Expected build to succeed"
}

function test_runfiles_from_tests_get_reused_and_tmp_clean() {
mkdir pkg
touch pkg/file.txt
Expand Down
Loading