The box VM holds the cache's store in a `cache` account, set up by `services.slop-broker-cache`, and the demo's broker pushes to it, so `slop build` can be tried by hand. The broker's key is only known at boot, so the module exposes its forced command for keys it can't list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
38236f05f7
commit
5b525bc637
4 files changed
+64
-6
No files matched your search
+12
@@ -81,6 +81,10 @@ let
|
||||
action = "ask";
|
||||
leases = [ "5m" ];
|
||||
};
|
||||
build = {
|
||||
action = "ask";
|
||||
leases = [ "5m" ];
|
||||
};
|
||||
# Approvals show whether the file and its recipients match `master`; reading always asks
|
||||
secret = {
|
||||
action = "ask";
|
||||
@@ -106,6 +110,14 @@ let
|
||||
cache = "${state}/nix-cache";
|
||||
};
|
||||
|
||||
# The box VM's `cache` account, which holds the binary cache's store
|
||||
cache = {
|
||||
hostname = "localhost";
|
||||
user = "cache";
|
||||
ssh_opts = [ "-p" (toString demo.ports.boxSsh) ];
|
||||
key = "${state}/broker-key";
|
||||
};
|
||||
|
||||
secrets = {
|
||||
identity = "${state}/broker-age.key";
|
||||
names.dev = "@dev@";
|
||||
|
||||
+24
-3
@@ -40,6 +40,7 @@ flowchart TB
|
||||
|
||||
subgraph boxvm["Box VM"]
|
||||
sshd["sshd, as box<br>(nodes web, router, vault, box)"]
|
||||
cache["sshd, as cache<br>(the binary cache's store)"]
|
||||
end
|
||||
|
||||
slop -- "vsock" --> broker
|
||||
@@ -50,6 +51,7 @@ flowchart TB
|
||||
shell -- "moves master" --> repo
|
||||
broker -- "SSH, through a wrapper" --> builder -- "fetches" --> repo
|
||||
broker -- "SSH, localhost:2222" --> sshd
|
||||
broker -- "SSH, localhost:2222" --> cache
|
||||
```
|
||||
|
||||
| Part | Where | Runs |
|
||||
@@ -57,7 +59,7 @@ flowchart TB
|
||||
| Broker, from this checkout (`cargo run`) | Host | `devenv up` (process `slop-broker`) |
|
||||
| Web app | <http://localhost:8095> | Part of the broker |
|
||||
| [Pocket ID](https://pocket-id.org), for approvers to sign in | <http://localhost:1411> | `devenv up` (process `pocket-id`) |
|
||||
| Box VM ([`box.nix`](../nix/demo/box.nix)): `sshd` for the targets, and the deploy target | `localhost:2222`, as `box` | `devenv up` (process `box`) |
|
||||
| Box VM ([`box.nix`](../nix/demo/box.nix)): `sshd` for the targets, the deploy target and the binary cache | `localhost:2222`, as `box`, and as `cache` for the cache | `devenv up` (process `box`) |
|
||||
| Agents' VM ([`agent.nix`](../nix/demo/agent.nix)), signed in as `agent` | Your terminal | `demo` |
|
||||
| The repository, seeded from [`repo/`](../nix/demo/repo) | `.devenv/state/slop-demo/git/repo.git` | `git daemon`, one per connection from the agents' VM |
|
||||
| The builder (`slop-broker builder`, from this checkout) | Host | The broker, through its `ssh` |
|
||||
@@ -81,8 +83,8 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
|
||||
- `slop ssh vault` is denied.
|
||||
- `slop secret keys` runs without asking; the other secret requests ask, with a 5-minute
|
||||
lease, except reading, which asks every time.
|
||||
- Using the builder asks, with leases, except for commits already on `master`; deploys ask.
|
||||
There's no binary cache, so `slop build` says it isn't configured.
|
||||
- Using the builder asks, with leases, except for commits already on `master`; deploys and
|
||||
builds into the binary cache ask, with a 5-minute lease.
|
||||
|
||||
## Approving
|
||||
|
||||
@@ -164,6 +166,25 @@ profile). `demo-box cat /run/demo/version` on the host shows what's active.
|
||||
The box VM lets `box` use `sudo` without a password and copy unsigned paths into its store, which
|
||||
lives in memory, like everything else in the VMs.
|
||||
|
||||
### The binary cache
|
||||
|
||||
The box VM holds the binary cache's store, at `/var/lib/slop-cache`, owned by its `cache`
|
||||
account, as [`services.slop-broker-cache`](../nix/modules/nixos/cache.nix) sets it up: the
|
||||
broker's key may only run `nix-daemon --stdio` on that store and add GC roots. Nothing serves it
|
||||
to other boxes; it's for seeing what `slop build` pushes. In `~/repo` on the agents' VM:
|
||||
|
||||
```sh
|
||||
slop build packages.x86_64-linux.default </dev/null &
|
||||
```
|
||||
|
||||
As with a deploy, the builder's use is approved first (or covered by a lease), then the build
|
||||
request shows the outputs and their closure sizes, and once approved the broker pushes them and
|
||||
prints their paths. To see them on the host:
|
||||
|
||||
```sh
|
||||
demo-box ls /var/lib/slop-cache/nix/var/nix/gcroots/slop-broker
|
||||
```
|
||||
|
||||
## The box VM
|
||||
|
||||
`demo-box` in the devenv shell logs in to the box VM as `box`, with the broker's key, to see what
|
||||
|
||||
+21
-2
@@ -1,5 +1,6 @@
|
||||
# The box the demo's SSH targets reach: `sshd` with a `box` account for the broker's key, which may
|
||||
# use `sudo` and copy store paths, so the broker can deploy to it. `devenv up` runs it with
|
||||
# use `sudo` and copy store paths, so the broker can deploy to it, and a `cache` account holding
|
||||
# the binary cache's store, which `slop build` pushes to. `devenv up` runs it with
|
||||
# `SHARED_DIR` holding the broker's public key and the box's host key, which it keeps between runs
|
||||
# so the broker's `known_hosts` stays valid.
|
||||
{ pkgs }:
|
||||
@@ -9,7 +10,7 @@ let
|
||||
hostKey = "/etc/ssh/ssh_host_ed25519_key";
|
||||
in
|
||||
(pkgs.nixos ({ config, modulesPath, ... }: {
|
||||
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
|
||||
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ../modules/nixos/cache.nix ];
|
||||
|
||||
system.stateVersion = lib.trivial.release;
|
||||
networking.hostName = "slop-demo-box";
|
||||
@@ -38,6 +39,18 @@ in
|
||||
trusted-users = [ "root" "box" ];
|
||||
substituters = lib.mkForce [ ];
|
||||
};
|
||||
|
||||
# The binary cache: a store of its own, at `/var/lib/slop-cache`. The broker's key is authorized
|
||||
# at boot, below.
|
||||
users.users.cache = { isNormalUser = true; home = "/var/lib/slop-cache-home"; createHome = true; };
|
||||
systemd.tmpfiles.rules = [ "d /var/lib/slop-cache 0755 cache users -" ];
|
||||
services.slop-broker-cache = {
|
||||
enable = true;
|
||||
user = "cache";
|
||||
store = "/var/lib/slop-cache";
|
||||
home = "/var/lib/slop-cache-home";
|
||||
};
|
||||
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
hostKeys = [{ path = hostKey; type = "ed25519"; }];
|
||||
@@ -54,6 +67,12 @@ in
|
||||
install -m 600 /tmp/shared/host-key ${hostKey}
|
||||
install -d -m 700 -o box -g users ${config.users.users.box.home}/.ssh
|
||||
install -m 600 -o box -g users /tmp/shared/broker.pub ${config.users.users.box.home}/.ssh/authorized_keys
|
||||
|
||||
cache=${config.users.users.cache.home}/.ssh
|
||||
install -d -m 700 -o cache -g users $cache
|
||||
echo "restrict,command=\"${config.services.slop-broker-cache.forcedCommand}\" $(cat /tmp/shared/broker.pub)" > $cache/authorized_keys
|
||||
chown cache:users $cache/authorized_keys
|
||||
chmod 600 $cache/authorized_keys
|
||||
'';
|
||||
};
|
||||
})).vm
|
||||
@@ -51,6 +51,12 @@ in
|
||||
home = mkOpt' str null "`HOME` for the store's commands; a directory `user` can write to.";
|
||||
keepDays = mkOpt' ints.positive 14 "Days a pushed path stays rooted after its last push.";
|
||||
brokerKeys = mkOpt' (listOf str) [ ] "SSH public keys of brokers that may push.";
|
||||
forcedCommand = lib.mkOption {
|
||||
type = path;
|
||||
default = forcedCommand;
|
||||
readOnly = true;
|
||||
description = "The forced command for brokers' keys, for keys `brokerKeys` can't list, such as ones made at boot.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
@@ -62,7 +68,7 @@ in
|
||||
];
|
||||
|
||||
users.users.${cfg.user}.openssh.authorizedKeys.keys =
|
||||
map (k: ''restrict,command="${forcedCommand}" ${k}'') cfg.brokerKeys;
|
||||
map (k: ''restrict,command="${cfg.forcedCommand}" ${k}'') cfg.brokerKeys;
|
||||
|
||||
# Expired roots go daily; the store's own garbage collection then takes their paths
|
||||
systemd = {
|
||||
|
||||
Reference in new issue
Block a user