test: Deploy a built profile to a second box

The test repository gets two commits of a profile the builder can
build from a static busybox, without nixpkgs, whose `activate-rs`
leaves a mark, and a second VM, `box`, as a node with a store of its
own. The test deploys to `box` and the broker's own box at once, whose
profiles are the same derivation, then the second commit to `box`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-29 13:27:48 +00:00
1 parent d157ff278a
commit c33a28c8b8
2 files changed
+99 -24

No files matched your search

+56 -24
View File
@@ -1,8 +1,9 @@
# Runs the broker through the `services.slop-broker` module, with its real service hardening, over
# vsock loopback, against a local sshd. Build it as `checks.x86_64-linux.vm` (see `README.md`).
#
# `machine` runs the broker, its builder and the requesters, and is also the deploy node `local`
# (and `other` and `denied`), with a container, `web`.
# - `machine` runs the broker, its builder and the requesters, and is also the deploy node `local`
# (and `other` and `denied`), with a container, `web`.
# - `box` is a second deploy node with a store of its own.
{ pkgs, slop-broker }:
let
inherit (pkgs) lib;
@@ -16,29 +17,24 @@ let
# The broker's key at runtime: not a store path, as the module requires
keyFile = "/etc/slop-broker-test/key";
# The builder's repository: a flake whose deploy-rs nodes are the broker's SSH targets
# The builder's repository: a flake whose deploy-rs nodes are the broker's SSH targets, with a
# profile it can build without nixpkgs. Two commits, `one` and `two`, differ only in the profile.
repository = pkgs.runCommand "test-repository" { nativeBuildInputs = [ pkgs.git ]; } ''
mkdir $out
cat > $out/flake.nix <<'EOF'
{
outputs = _: {
deploy.sshUser = "deploy";
deploy.nodes = {
# Profiles aren't built here; their names say which containers there are
local = { hostname = "localhost"; profiles = { system = { }; container-web = { }; }; };
other.hostname = "localhost";
denied.hostname = "localhost";
};
};
}
EOF
install -m755 ${pkgs.pkgsStatic.busybox}/bin/busybox $out/busybox
git -C $out init --quiet --initial-branch=master
git -C $out add flake.nix
git -C $out -c user.name=test -c user.email=test@example.org commit --quiet -m "Add nodes"
for version in one two; do
sed "s/@version@/$version/g" ${./vm-test/flake.nix} > $out/flake.nix
git -C $out add flake.nix busybox
git -C $out -c user.name=test -c user.email=test@example.org commit --quiet -m "Profile $version"
git -C $out rev-parse HEAD > $out/commit-$version
done
'';
# A deploy node: the broker logs in as `deploy`, which may use `sudo` (for container commands)
# A deploy node: the broker logs in as `deploy`, which may use `sudo` (for activation and
# container commands) and copy unsigned paths into the store. Nothing is substituted, since the
# test is offline: everything is built or already in the store.
deployNode = {
services.openssh.enable = true;
@@ -50,11 +46,20 @@ let
users = [ "deploy" ];
commands = [{ command = "ALL"; options = [ "NOPASSWD" ]; }];
}];
nix.settings = {
trusted-users = [ "deploy" ];
substituters = lib.mkForce [ ];
};
};
in
pkgs.testers.runNixOSTest {
name = "slop-broker";
nodes.box = { ... }: {
imports = [ deployNode ];
};
nodes.machine = { ... }: {
imports = [ deployNode ./modules/nixos/broker.nix ./modules/nixos/builder.nix ];
@@ -85,9 +90,11 @@ pkgs.testers.runNixOSTest {
package = slop-broker;
approvers = [ "reviewer" ];
# Queries run without asking; `slop ssh` tests the approvals
# Everything runs without asking except `slop ssh`, which tests the approvals
policies.agent.ops = {
query.action = "auto";
builder.action = "auto";
deploy.action = "auto";
ssh = {
action = "ask";
leases = [ "5m" ];
@@ -267,7 +274,7 @@ pkgs.testers.runNixOSTest {
machine.succeed("su reviewer -c 'SLOP_APPROVE=ssh:slop@localhost slop-approve once'")
machine.wait_until_succeeds("grep -q 'remote approval' /tmp/out4")
# The builder
# Deploys
# A builder with a store of its own serves it to the broker's key as `nix-daemon --stdio`
machine.succeed("install -m600 ${keyFile} /root/builder-key")
@@ -276,12 +283,37 @@ pkgs.testers.runNixOSTest {
out = machine.succeed(f"nix --extra-experimental-features nix-command path-info --store '{store}' {system}")
assert out.strip() == system, out
# Deploys build, copy, compare and activate, on both nodes at once, though their profiles are
# the same derivation. Copying to `box` fills a store of its own: the profile and busybox.
box.wait_for_unit("sshd.service")
repository = "/var/lib/slop-test-repository"
one = machine.succeed(f"cat {repository}/commit-one").strip()
two = machine.succeed(f"cat {repository}/commit-two").strip()
status, out = try_slop(f"deploy box.system local.system --commit {one}")
print(out)
assert status == 0, (status, out)
for line in ["[box.system] activating one", "[local.system] activating one"]:
assert line in out, (line, out)
box.succeed("test -e /tmp/slop-activated-one")
machine.succeed("test -e /tmp/slop-activated-one")
profile = box.succeed("ls -d /nix/store/*-test-profile-one").strip()
out = box.succeed(f"nix --extra-experimental-features nix-command path-info -r {profile}")
assert len(out.split()) == 2, out
# The second commit, with its build's log
status, out = try_slop(f"deploy box.system --commit {two}")
print(out)
assert status == 0 and "build line two" in out, (status, out)
box.succeed("test -e /tmp/slop-activated-two")
# The audit log
# It has the answers
audit = approve("log")
# It has the answers and the outcomes; the default 50 records don't reach back far enough
audit = approve("log -n 200")
print(audit)
assert "agent asks: ssh local" in audit and "answered 5m by reviewer" in audit, audit
assert "answered once by laptop (ssh)" in audit, audit
assert "finished with exit status 0" in audit, audit
'';
}
+43
View File
@@ -0,0 +1,43 @@
# The VM test's repository, committed once for each version of its profile (`@version@`).
{
outputs = _:
let
# A stand-in for deploy-rs's activation wrapper, built with only a static busybox, whose
# `activate-rs` leaves a mark. It refers to busybox, so its closure is two paths.
profile = derivation {
name = "test-profile-@version@";
system = "x86_64-linux";
builder = ./busybox;
args = [
"sh"
"-c"
''
b=${./busybox}
echo "build line @version@"
$b mkdir $out
printf '#!/bin/sh\n# %s\necho activating @version@\ntouch /tmp/slop-activated-@version@\n' $b > $out/activate-rs
$b chmod +x $out/activate-rs
''
];
};
# Its own profile path, so comparing doesn't take in the box's own system
system = { path = profile; profilePath = "/nix/var/nix/profiles/slop-test"; };
in
{
deploy.sshUser = "deploy";
deploy.nodes = {
local = {
hostname = "localhost";
profiles = {
inherit system;
# Only its name is used: it says which containers there are
container-web = { };
};
};
# Another box, with a store of its own to copy to
box = { hostname = "box"; profiles = { inherit system; }; };
other.hostname = "localhost";
denied.hostname = "localhost";
};
};
}