docs: describe the implemented sandbox architecture
CI / build (push) Successful in 1m40s
CI / test (push) Skipped
CI / publish (push) Skipped
CI / snap (push) Successful in 2m39s
CI / release (push) Skipped

Update the design doc to the shipped shape: the public API, the module
layout, the crate-private Unshare constructors and what the conformance
tests actually cover. Refresh the AGENTS.md scope list and the test
mode wording in the README and CLI.

Rename the last context-named helpers (new_with_base,
unshare_test_sandbox, RunEnv) and the comments that still described the
old abstraction.
This commit is contained in:
vhaudiquet committed 2026-11-24 18:35:17 +01:00
1 parent d5bf2ceeb3
commit 674b99b00b
17 files changed
+207 -214

No files matched your search

+26 -29
View File
@@ -217,7 +217,7 @@ pub struct DebBuildOptions<'a> {
/// (.deb paths, archive names or PPA packages).
pub inject: Vec<String>,
/// Parallel build jobs; defaults to the core count available in the
/// build context.
/// build sandbox.
pub jobs: Option<usize>,
/// Incremental request (`pkh deb --incremental [<id>]`): which
/// record to fork as the base of this build's staged tree, and
@@ -459,9 +459,9 @@ async fn build_binary_package_impl(
tee_log: true,
});
// Create an ephemeral unshare context for all Local builds. It is kept in
// this scope so it outlives the guarded section below and is only dropped
// once the live view has been cleared.
// Create the build's unshare sandbox. It stays in this scope so it
// outlives the guarded section below and is only dropped once the live
// view has been cleared.
//
// Every build runs in its own record under the sessions directory
// (forked from a previous one with `--incremental`, thrown away
@@ -500,7 +500,7 @@ async fn build_binary_package_impl(
// inherit the terminal — the wrapper removes that fallback, so the
// raw lines are written by a terminal sink instead, and --verbose
// keeps showing raw output. A record-less build (non-local base
// context) keeps the plain view.
// record) keeps the plain view.
let record_log: Option<Result<Arc<session::RecordLogSink>, std::io::Error>> =
session.as_ref().map(|s| {
session::RecordLogSink::new(
@@ -547,7 +547,7 @@ async fn build_binary_package_impl(
))
} else {
Some(Arc::new(
Unshare::new_with_context(
Unshare::new_with_base(
series,
chroot_arch,
mirror_arg,
@@ -559,11 +559,9 @@ async fn build_binary_package_impl(
))
};
// Determine the build context explicitly: for Local builds it is the
// ephemeral context the guard just created (taken from the guard itself,
// never from the process-global, which concurrent builds may have
// re-pointed at their own chroot); otherwise the base context is used
// directly.
// The build runs in the unshare sandbox the guard created, taken from
// the guard itself rather than any global that concurrent builds could
// re-point at their own chroot.
let build_ctx: Arc<dyn Sandbox> = match guard.as_ref() {
Some(g) => Arc::clone(g) as Arc<dyn Sandbox>,
None => base_ctx.clone(),
@@ -704,7 +702,7 @@ async fn build_binary_package_impl(
session.as_ref(),
build_resume,
ccache,
// Rootless builds: only a context pkh controls (the
// Rootless builds: only a sandbox pkh controls (the
// ephemeral chroot) can carry the on-demand build user.
Some(local::BUILD_USER),
&mut timings,
@@ -1060,9 +1058,9 @@ pub(crate) fn find_package_directory(
let entries = ctx.list_files(package_parent)?;
let mut found_dirs = Vec::new();
for entry in entries {
// list_files yields context-relative paths (e.g. rooted inside
// the chroot for an unshare context): classify through the
// context, a host-side stat would miss every entry.
// list_files yields sandbox-relative paths (e.g. rooted inside
// the chroot for an unshare sandbox): classify through the
// sandbox, a host-side stat would miss every entry.
let is_dir = ctx.is_dir(&entry)?;
log::debug!(" - {}", entry.display());
if is_dir && let Some(file_name) = entry.file_name() {
@@ -1101,7 +1099,7 @@ fn find_dsc_file(
let dsc_name = format!("{}_{}.dsc", package, version_without_epoch);
let dsc_path = PathBuf::from(build_root).join(&dsc_name);
// Check if the .dsc file exists in context
// Check if the .dsc file exists in the sandbox
if !ctx.exists(&dsc_path)? {
return Err(format!("Could not find .dsc file at {}", dsc_path.display()).into());
}
@@ -1231,24 +1229,23 @@ mod tests {
assert!(profiler.finish().is_empty());
}
/// An unshare context mapped over `chroot_root`, parented on a local
/// context like the ephemeral build contexts are: exists/list_files/
/// is_dir answer through the path mapping, no namespace privileges
/// needed.
fn unshare_test_context(chroot_root: &Path) -> Arc<dyn Sandbox> {
/// An unshare sandbox mapped over `chroot_root` on a host base:
/// exists/list_files/is_dir answer through the path mapping, no
/// namespace privileges needed.
fn unshare_test_sandbox(chroot_root: &Path) -> Arc<dyn Sandbox> {
Arc::new(crate::sandbox::unshare::UnshareDriver::new(
chroot_root.to_path_buf(),
Arc::new(Host::new()),
))
}
/// The staging-area listing must classify entries through the context:
/// an unshare context returns build-root-relative paths that a host-side
/// The staging-area listing must classify entries through the sandbox:
/// an unshare sandbox returns build-root-relative paths that a host-side
/// stat never sees (they live under the chroot root on the host), which
/// used to silently empty the 'Found directories' list of the search
/// failure message — and with it every hint about the actual layout.
#[test]
fn find_package_directory_lists_staged_directories_through_the_context() {
fn find_package_directory_lists_staged_directories_through_the_sandbox() {
let chroot = tempfile::tempdir().unwrap();
// Staged tree holding a single nested checkout whose name matches
// none of the search patterns (the embedded-caller layout:
@@ -1256,7 +1253,7 @@ mod tests {
let staged_tree = chroot.path().join("tmp/pkh-build-1/j-42");
std::fs::create_dir_all(staged_tree.join("tree/debian")).unwrap();
let ctx = unshare_test_context(chroot.path());
let ctx = unshare_test_sandbox(chroot.path());
let err = find_package_directory(
Path::new("/tmp/pkh-build-1/j-42"),
"bc",
@@ -1269,7 +1266,7 @@ mod tests {
let message = err.to_string();
assert!(
message.contains("Found directories: tree"),
"error should list the staged directories through the context: {message}"
"error should list the staged directories through the sandbox: {message}"
);
}
@@ -1283,7 +1280,7 @@ mod tests {
let staged_tree = chroot.path().join("tmp/pkh-build-1/tree");
std::fs::create_dir_all(staged_tree.join("debian/source")).unwrap();
let ctx = unshare_test_context(chroot.path());
let ctx = unshare_test_sandbox(chroot.path());
let resolved = resolve_package_directory(
Path::new("/tmp/pkh-build-1/tree"),
"bc",
@@ -1307,7 +1304,7 @@ mod tests {
// <pkg>/<pkg>-<origversion>
std::fs::create_dir_all(staged_tree.join("bc/bc-1.07.1/debian")).unwrap();
let ctx = unshare_test_context(chroot.path());
let ctx = unshare_test_sandbox(chroot.path());
let resolved = resolve_package_directory(
Path::new("/tmp/pkh-build-1/checkout"),
"bc",
@@ -1427,7 +1424,7 @@ mod tests {
}
// Tests no longer need to be 'serial' since each test uses its own
// explicit context instead of shared global state.
// explicit sandbox instead of shared global state.
#[tokio::test]
#[test_log::test]
async fn test_deb_hello_ubuntu_end_to_end() {