From b4e63423c98de5e29aa0c153ebd0f1de15e18098 Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 13:10:24 +0100 Subject: [PATCH 1/4] [linux] Tests: an archive made with 'tar -C dir -czf x .' (a ./ root entry) is accepted (red: found by the systemd container test) --- crates/linux/tests/unpack.rs | 33 +++++++++++++++++++++++++++++++++ crates/protocol/tests/jobs.rs | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/crates/linux/tests/unpack.rs b/crates/linux/tests/unpack.rs index e13b7b8..fedaec3 100644 --- a/crates/linux/tests/unpack.rs +++ b/crates/linux/tests/unpack.rs @@ -129,3 +129,36 @@ fn bad_app_or_version_names_never_reach_the_disk() { ); } } + +#[test] +fn an_archive_made_with_tar_dot_is_accepted() { + // `tar -C dir -czf x.tar.gz .` puts the root itself first, as `./`. + let (_d, l) = layout(); + let mut b = tar::Builder::new(flate2::write::GzEncoder::new( + Vec::new(), + flate2::Compression::fast(), + )); + let mut dir = tar::Header::new_gnu(); + dir.set_entry_type(tar::EntryType::Directory); + dir.set_mode(0o755); + dir.set_size(0); + b.append_data(&mut dir, "./", &[][..]).unwrap(); + let mut f = tar::Header::new_gnu(); + f.set_entry_type(tar::EntryType::Regular); + f.set_mode(0o755); + f.set_size(3); + b.append_data( + &mut f, + "./run.sh", + &b"#! +"[..], + ) + .unwrap(); + let a = b.into_inner().unwrap().finish().unwrap(); + let dir = unpack(&l, "demo", "1.0.0", &a[..], "s").unwrap(); + assert_eq!( + std::fs::read(dir.join("run.sh")).unwrap(), + b"#! +" + ); +} diff --git a/crates/protocol/tests/jobs.rs b/crates/protocol/tests/jobs.rs index c64aeb3..993e399 100644 --- a/crates/protocol/tests/jobs.rs +++ b/crates/protocol/tests/jobs.rs @@ -223,6 +223,11 @@ fn archive_entries_stay_inside_the_release() { check_entry(EntryKind::File, "bin/shop", 10).unwrap(); check_entry(EntryKind::Dir, "static/", 0).unwrap(); check_entry(EntryKind::File, "./README", 10).unwrap(); + // `tar -C dir -czf x.tar.gz .` writes the root itself as `./`: allowed, and it names nothing. + assert!(check_entry(EntryKind::Dir, "./", 0).unwrap().is_empty()); + assert!(check_entry(EntryKind::Dir, ".", 0).unwrap().is_empty()); + assert!(check_entry(EntryKind::File, "./", 0).is_err()); + assert!(check_entry(EntryKind::File, ".", 0).is_err()); for (kind, path) in [ (EntryKind::File, "/etc/passwd"), (EntryKind::File, "../outside"), From 5999847bceafeac41ce4a73ef01c7f4e945a4a0e Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 13:12:53 +0100 Subject: [PATCH 2/4] [protocol] Archive: the release's own root (./) is an allowed directory entry --- crates/protocol/src/archive.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/protocol/src/archive.rs b/crates/protocol/src/archive.rs index 6a1a901..5f79dfe 100644 --- a/crates/protocol/src/archive.rs +++ b/crates/protocol/src/archive.rs @@ -52,7 +52,7 @@ impl ArchiveError { } } -/// Check one entry and return its path as plain components (no `.`, never empty). +/// Check one entry and return its path as plain components (no `.`; empty only for the root dir). pub fn check_entry(kind: EntryKind, path: &str, size: u64) -> Result, ArchiveError> { match kind { EntryKind::File | EntryKind::Dir => {} @@ -78,7 +78,9 @@ pub fn check_entry(kind: EntryKind, path: &str, size: u64) -> Result c => parts.push(c.to_owned()), } } - if parts.is_empty() { + // The release's own root (`./`, as `tar -C dir -czf x .` writes it) names nothing: allowed for a + // directory, refused for anything else. + if parts.is_empty() && kind != EntryKind::Dir { return Err(ArchiveError::Path); } Ok(parts) From a67acb2886610cd0ea38a8602ee1d108590f355b Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 13:12:54 +0100 Subject: [PATCH 3/4] [linux] Container test: sources through the build context (no host mounts), Docker or Podman, cleans up its image --- .dockerignore | 3 +++ tests/linux/Containerfile | 14 +++++++++++++- tests/linux/run.sh | 33 +++++++++++++++++---------------- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5e07117 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +target/ +.git/ +**/target/ diff --git a/tests/linux/Containerfile b/tests/linux/Containerfile index 520f5f4..09d3d7a 100644 --- a/tests/linux/Containerfile +++ b/tests/linux/Containerfile @@ -1,8 +1,20 @@ -# The Linux target's integration test: Debian with real systemd as PID 1. +# The Linux target's integration test: Debian with real systemd as PID 1 and the test-only +# `deploy` example. Built from the repository root (tests/linux/run.sh); the sources go in through the +# build context, so no host folder is mounted. + +FROM docker.io/library/rust:1-slim-trixie AS build +WORKDIR /src +COPY Cargo.toml Cargo.lock ./ +COPY crates crates +RUN cargo build --locked --example deploy -p legatus-linux \ + && cp target/debug/examples/deploy /legatus-deploy-test + FROM docker.io/library/debian:trixie-slim RUN apt-get update \ && apt-get install -y --no-install-recommends systemd systemd-sysv python3 curl ca-certificates \ && rm -rf /var/lib/apt/lists/* \ && systemctl mask systemd-logind.service getty.target console-getty.service +COPY --from=build /legatus-deploy-test /usr/local/bin/legatus-deploy-test +COPY tests/linux/scenario.sh /scenario.sh STOPSIGNAL SIGRTMIN+3 CMD ["/sbin/init"] diff --git a/tests/linux/run.sh b/tests/linux/run.sh index e9f57ef..d64a08a 100644 --- a/tests/linux/run.sh +++ b/tests/linux/run.sh @@ -1,34 +1,35 @@ #!/bin/sh # SPDX-License-Identifier: MPL-2.0 # The Linux target against real systemd, in a container (Docker or Podman). -# tests/linux/run.sh # from the repo root -# Builds the test-only `deploy` example in a Rust container, starts Debian with systemd as PID 1, -# and runs scenario.sh in it. On Mark's PC the container engine keeps its data on D:. +# tests/linux/run.sh # from anywhere in the repo +# Builds the test-only `deploy` example and a Debian image with systemd as PID 1 (Containerfile, from +# the repo root as build context: no host folder is mounted), starts it, runs scenario.sh in it, and +# removes the container. KEEP_IMAGE=1 keeps the image. set -eu ENGINE=${ENGINE:-$(command -v podman || command -v docker || true)} [ -n "$ENGINE" ] || { echo "run.sh: needs podman or docker" >&2; exit 2; } REPO=$(cd "$(dirname "$0")/../.." && pwd) +# Git Bash on Windows: the engine's CLI reads the build context from a Windows path. +if pwd -W >/dev/null 2>&1; then REPO=$(cd "$REPO" && pwd -W); fi NAME=legatus-linux-it -RUST_IMAGE=${RUST_IMAGE:-docker.io/library/rust:1.89-slim-trixie} +IMAGE=legatus-systemd-it +# Git Bash on Windows: MSYS must not rewrite the container-side paths below. +export MSYS_NO_PATHCONV=1 -cleanup() { "$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true; } +cleanup() { + "$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true + [ "${KEEP_IMAGE:-0}" = 1 ] || "$ENGINE" rmi "$IMAGE" >/dev/null 2>&1 || true +} trap cleanup EXIT -echo "== building the test driver" -"$ENGINE" volume create legatus-it-cargo >/dev/null -"$ENGINE" run --rm -v "$REPO:/src:ro" -v legatus-it-cargo:/cargo -e CARGO_HOME=/cargo/home \ - -e CARGO_TARGET_DIR=/cargo/target -w /src "$RUST_IMAGE" \ - sh -c 'cargo build --locked --example deploy -p legatus-linux && cp /cargo/target/debug/examples/deploy /cargo/legatus-deploy-test' +echo "== building (the test driver, then Debian with systemd)" +"$ENGINE" build -q -t "$IMAGE" -f "$REPO/tests/linux/Containerfile" "$REPO" >/dev/null echo "== starting systemd" -"$ENGINE" build -q -t legatus-systemd "$REPO/tests/linux" >/dev/null -cleanup +"$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true "$ENGINE" run -d --name "$NAME" --privileged --cgroupns=host \ - --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ - -v legatus-it-cargo:/cargo:ro legatus-systemd >/dev/null -"$ENGINE" exec "$NAME" install -m 755 /cargo/legatus-deploy-test /usr/local/bin/legatus-deploy-test -"$ENGINE" cp "$REPO/tests/linux/scenario.sh" "$NAME:/scenario.sh" + --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw "$IMAGE" >/dev/null echo "== scenario" "$ENGINE" exec "$NAME" sh /scenario.sh From e5fe77d4941d1c5d222633853c365115c94f9754 Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 13:12:55 +0100 Subject: [PATCH 4/4] [repo] Version: 0.1.1 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6de30f..1d0fbba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,7 +368,7 @@ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" [[package]] name = "legatus" -version = "0.1.0" +version = "0.1.1" dependencies = [ "domi-pki", "flate2", @@ -389,7 +389,7 @@ dependencies = [ [[package]] name = "legatus-linux" -version = "0.1.0" +version = "0.1.1" dependencies = [ "flate2", "legatus-protocol", @@ -400,7 +400,7 @@ dependencies = [ [[package]] name = "legatus-protocol" -version = "0.1.0" +version = "0.1.1" dependencies = [ "data-encoding", "domi-pki", diff --git a/Cargo.toml b/Cargo.toml index a4500be..f157c2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/protocol", "crates/linux", "crates/agent"] [workspace.package] -version = "0.1.0" +version = "0.1.1" edition = "2024" rust-version = "1.89" license = "MPL-2.0"