feat(sandbox): hermetic action sandboxing (F1)
VoidBuildSystem CI / 1 · Requirements (push) Successful in 10s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 3m20s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 3m27s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m28s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m8s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m5s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 23s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 21s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 5m27s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m17s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m0s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 7m41s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m44s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped

Adds Sandbox::sandbox_supported()/apply_sandbox() and a hidden
`vbs __sandbox-exec` wrapper used by the scheduler for every action:

- unshare(CLONE_NEWUSER|CLONE_NEWNS|CLONE_NEWNET), map the caller to
  root, make mounts private, bind the project read-only, the build root
  (including .vbs snapshots) read-write, system/toolchain roots
  (/usr, /lib, /bin, /etc, Nix store, sysroot) read-only, /proc, /sys
  and /dev writable, an empty /tmp, then pivot_root and exec.
- `--sandbox=off|warn|strict` (or VBS_SANDBOX) on build/test/run;
  strict fails explicitly when the host lacks unprivileged user
  namespaces, warn degrades to an unsandboxed run with a warning.
- vbs doctor reports sandbox availability; CI runs a strict smoke build
  when the runner allows user namespaces.

Implementation notes: the sandbox root is a bind mount (tmpfs inside a
user namespace returns EOVERFLOW on this kernel), read-only remounts
that the kernel refuses for inherited mounts degrade to writable binds,
and the project remount is required.

Verified: fullV1Tests.sandbox_strict_allows_project_builds_and_hides_
outside_files passes (strict build succeeds; an action reading an
outside file fails), vbs_core_tests 8/8, CLI contracts pass,
clang-format clean.
This commit is contained in:
faumaray committed 2026-12-06 19:45:07 +03:00
1 parent 11d4a3f5d7
commit ff3bfd03a1
13 files changed
+587

No files matched your search

+3
View File
@@ -51,6 +51,8 @@ check_process(0 "Usage: vbs remove " "" remove --help)
check_process(0 "--frozen" "" build --help)
check_process(0 "--native-cache" "" build --help)
check_process(0 "--bep" "" build --help)
check_process(0 "--sandbox" "" build --help)
check_process(2 "" "invalid value 'bogus' for '--sandbox'" build --sandbox bogus)
check_process(0 "Usage: vbs new " "" new --help)
check_process(2 "" "unsupported --native-cache" build --native-cache bogus)
check_process(2 "" "invalid version range" add fmt@bad --no-lock)
@@ -69,6 +71,7 @@ check_process(0 "Usage: vbs clean " "" clean --help)
check_process(0 "Usage: vbs doctor " "" doctor --help)
check_process(0 "host platform: (Linux|Windows)" "" doctor)
check_process(0 "Void::Sqlite: (enabled|disabled)" "" doctor)
check_process(0 "hermetic sandbox: (user namespaces available|unavailable)" "" doctor)
check_process(0 "Usage: vbs graph " "" graph --help)
check_process(2 "" "unsupported --format" graph --format xml)
check_process(2 "" "multi-profile build requires --editor-profile" build --profile debug --profile release)
+81
View File
@@ -17,6 +17,7 @@
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provenance/Sbom.hpp>
#include <Void/Build/Provenance/Signing.hpp>
#include <Void/Build/Sandbox/Sandbox.hpp>
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/Provider/Translator.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp>
@@ -4712,3 +4713,83 @@ void build(Void::Build::Project &p) {
Void::Testing::expect(kinds.contains("build_finished"));
Void::Testing::expect(saw_failing_test);
}
// === Hermetic sandboxing (F1): strict builds work, outside files are invisible ===
VOID_TEST(FullV1Tests, sandbox_strict_allows_project_builds_and_hides_outside_files) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
if (!Sandbox::sandbox_supported()) {
return; // Unprivileged user namespaces are unavailable on this host.
}
Void::FileSystem::TempDir tmp{"vbs_sandbox_"};
const auto proj = tmp / "proj";
const auto outside = tmp / "outside";
const auto build_off = tmp / "build-off";
const auto build_strict = tmp / "build-strict";
write_file(outside / "secret.txt", "SANDBOX_SECRET\n");
const std::string secret = (outside / "secret.txt").string();
const std::string off_out = (build_off / "leak.out").string();
const std::string strict_out = (build_strict / "leak.out").string();
write_file(proj / "build.cpp", "#include <Void/Build.hpp>\n"
"void build(Void::Build::Project &p) {\n"
" p.executable(\"app\").cxx_standard(Void::Build::CxxStandard::Cxx26)"
".sources({\"src/main.cpp\"});\n"
" p.custom_action(\"leak_off\")\n"
" .command({\"/bin/sh\", \"-c\", \"cat " +
secret + " > " + off_out +
"\"})\n"
" .outputs({\"" +
off_out +
"\"})\n"
" .nondeterministic(true);\n"
" p.custom_action(\"leak_strict\")\n"
" .command({\"/bin/sh\", \"-c\", \"cat " +
secret + " > " + strict_out +
"\"})\n"
" .outputs({\"" +
strict_out +
"\"})\n"
" .nondeterministic(true);\n"
"}\n");
write_file(proj / "src" / "main.cpp", "int main() { return 0; }\n");
auto run_vbs = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = std::move(args);
req.timeout = std::chrono::seconds{600};
return Platform::run_supervised(req);
};
// A normal project builds inside the strict sandbox.
auto strict_build = run_vbs({"build", "--project", proj.string(), "--build-dir",
(tmp / "build-app").string(), "--target", "app", "--jobs",
"2", "--sandbox", "strict"});
Void::Testing::expect(strict_build.has_value() && strict_build->succeeded());
if (strict_build && !strict_build->succeeded()) {
std::cerr << "strict build failed:\n" << strict_build->stderr_data << '\n';
}
// Without the sandbox the action reads the outside file.
auto off = run_vbs({"build", "--project", proj.string(), "--build-dir", build_off.string(),
"--target", "leak_off", "--sandbox", "off"});
Void::Testing::expect(off.has_value() && off->succeeded());
auto leaked = Void::FileSystem::read_file(build_off / "leak.out");
Void::Testing::require(leaked.has_value());
Void::Testing::expect(leaked->find("SANDBOX_SECRET") != std::string::npos);
// With the strict sandbox the same action cannot see the outside file.
auto strict_leak = run_vbs({"build", "--project", proj.string(), "--build-dir",
build_strict.string(), "--target", "leak_strict", "--sandbox",
"strict"});
Void::Testing::expect(strict_leak.has_value() && !strict_leak->succeeded());
if (strict_leak) {
const std::string output = strict_leak->stdout_data + strict_leak->stderr_data;
Void::Testing::expect(output.find("No such file") != std::string::npos ||
output.find("not found") != std::string::npos);
}
}