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

@@ -1,6 +1,7 @@
#pragma once
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Sandbox/Sandbox.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
@@ -48,6 +49,12 @@ struct ExecutionOptions {
bool use_cache{true};
std::vector<std::string> selected_targets;
std::chrono::milliseconds action_timeout{0};
// Hermetic sandboxing (Linux): compile/link actions run through `vbs __sandbox-exec`, which
// unshares user/mount/network namespaces and pivots into a root containing only the project,
// the profile build directory and the toolchain/system roots.
Sandbox::SandboxMode sandbox_mode{Sandbox::SandboxMode::Off};
Sandbox::SandboxOptions sandbox_options;
std::filesystem::path sandbox_executable;
std::function<void(const ExecutionEvent &)> on_event;
};
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Sandbox {
enum class SandboxMode { Off, Warn, Strict };
[[nodiscard]] std::string_view sandbox_mode_name(SandboxMode mode) noexcept;
[[nodiscard]] bool parse_sandbox_mode(std::string_view text, SandboxMode &out) noexcept;
struct SandboxOptions {
std::filesystem::path project_root;
std::filesystem::path build_root;
// Additional read-only roots (system/toolchain paths). /usr, /lib, /bin, /etc, /dev and /proc
// are added by the backends automatically; these are extra roots such as a sysroot or the
// Nix store.
std::vector<std::filesystem::path> read_only_roots;
bool allow_network{false};
};
// Probes whether unprivileged user+mount namespaces are available on this host.
[[nodiscard]] bool sandbox_supported();
// Applies the sandbox to the *current* process (mount namespace, pivot root, bind mounts).
// Used by the hidden `vbs __sandbox-exec` wrapper just before exec. Never called in the parent.
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
apply_sandbox(const SandboxOptions &options);
// Hidden wrapper mode: `vbs __sandbox-exec -- <executable> [args...]`.
// Reads VBS_SANDBOX_PROJECT, VBS_SANDBOX_BUILD, VBS_SANDBOX_ROOTS (colon-separated) and
// VBS_SANDBOX_NET from the environment, applies the sandbox and execs the command.
[[nodiscard]] int run_sandbox_exec(int argc, char **argv);
} // namespace Void::Build::Sandbox