| author | |
| committer | |
| log | 12e0e05ea6505d47807eb7f08e12f9458b0c786a |
| tree | 95c4b488976256ee336c734af966a4effe1d9fc3 |
| parent | 42cb7282cfc609f4f765d92eca82e7a33bb9ef37 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Keep the container store and home encrypted, and stop binding the retired shared workspace.
Assisted-by: gpt-6.1-terra4 files changed, 83 insertions(+), 17 deletions(-)
nixos/knife-linux.Containerfile+1-1| ... | @@ -29,5 +29,5 @@ ARG GID | ... | @@ -29,5 +29,5 @@ ARG GID |
| 29 | RUN groupadd --gid "$GID" chloe && useradd --uid "$UID" --gid "$GID" --no-create-home --home-dir /home/clo clo | 29 | RUN groupadd --gid "$GID" chloe && useradd --uid "$UID" --gid "$GID" --no-create-home --home-dir /home/clo clo |
| 30 | USER clo | 30 | USER clo |
| 31 | ENV HOME=/home/clo LANG=C.UTF-8 PATH=/home/clo/.local/bin:/usr/local/bin:/usr/bin:/bin | 31 | ENV HOME=/home/clo LANG=C.UTF-8 PATH=/home/clo/.local/bin:/usr/local/bin:/usr/bin:/bin |
| 32 | WORKDIR /Volumes/Code/project | 32 | WORKDIR /work/knife |
| 33 | ENTRYPOINT ["/home/clo/.local/bin/knife", "start", "--mode", "desktop", "--host", "127.0.0.1", "--port", "3773", "--no-browser"] | 33 | ENTRYPOINT ["/home/clo/.local/bin/knife", "start", "--mode", "desktop", "--host", "127.0.0.1", "--port", "3773", "--no-browser"] |
nixos/knife-linux.nix+27-5| ... | @@ -1,6 +1,5 @@ | ... | @@ -1,6 +1,5 @@ |
| 1 | { config, lib, pkgs, ... }: | 1 | { config, lib, pkgs, ... }: |
| 2 | let | 2 | let |
| 3 | sandbox = (builtins.fromJSON (builtins.readFile ../config/mac-studio-sandbox.json)).mountPoint; | ||
| 4 | root = "/srv/knife-linux"; | 3 | root = "/srv/knife-linux"; |
| 5 | uid = toString config.users.users.clo.uid; | 4 | uid = toString config.users.users.clo.uid; |
| 6 | gid = toString config.users.groups.chloe.gid; | 5 | gid = toString config.users.groups.chloe.gid; |
| ... | @@ -23,19 +22,43 @@ in | ... | @@ -23,19 +22,43 @@ in |
| 23 | { | 22 | { |
| 24 | environment.systemPackages = [ podman ]; | 23 | environment.systemPackages = [ podman ]; |
| 25 | 24 | ||
| 25 | systemd.services.knife-linux-storage = { | ||
| 26 | requires = [ "zfs-import-work.service" "dev-tpmrm0.device" ]; | ||
| 27 | after = [ "zfs-import-work.service" "zfs-mount.service" "dev-tpmrm0.device" ]; | ||
| 28 | before = [ "knife-linux.service" ]; | ||
| 29 | serviceConfig = { | ||
| 30 | Type = "oneshot"; | ||
| 31 | RemainAfterExit = true; | ||
| 32 | LoadCredentialEncrypted = "zfs-clover:/etc/credstore.encrypted/zfs-clover"; | ||
| 33 | }; | ||
| 34 | script = '' | ||
| 35 | test "$(${pkgs.zfs}/bin/zfs get -H -o value encryptionroot work/knife-linux)" = work/knife-linux | ||
| 36 | test "$(${pkgs.zfs}/bin/zfs get -H -o value mountpoint work/knife-linux)" = ${root} | ||
| 37 | if test "$(${pkgs.zfs}/bin/zfs get -H -o value keystatus work/knife-linux)" = unavailable; then | ||
| 38 | ${pkgs.zfs}/bin/zfs load-key -L "file://$CREDENTIALS_DIRECTORY/zfs-clover" work/knife-linux | ||
| 39 | fi | ||
| 40 | if test "$(${pkgs.zfs}/bin/zfs get -H -o value mounted work/knife-linux)" != yes; then | ||
| 41 | ${pkgs.zfs}/bin/zfs mount work/knife-linux | ||
| 42 | fi | ||
| 43 | test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint ${root})" = work/knife-linux | ||
| 44 | ''; | ||
| 45 | }; | ||
| 46 | |||
| 26 | systemd.services.knife-linux = { | 47 | systemd.services.knife-linux = { |
| 27 | description = "The Knife Linux agent container"; | 48 | description = "The Knife Linux agent container"; |
| 28 | wantedBy = [ "multi-user.target" ]; | 49 | wantedBy = [ "multi-user.target" ]; |
| 29 | wants = [ "network-online.target" ]; | 50 | wants = [ "network-online.target" ]; |
| 30 | after = [ "network-online.target" "mac-studio-sandbox.service" "zfs-import-work.service" "zfs-mount.service" ]; | 51 | after = [ "network-online.target" "knife-linux-storage.service" ]; |
| 31 | requires = [ "mac-studio-sandbox.service" "zfs-import-work.service" ]; | 52 | requires = [ "knife-linux-storage.service" ]; |
| 32 | # Restarting stops every running agent, so changes wait for a manual restart. | 53 | # Restarting stops every running agent, so changes wait for a manual restart. |
| 33 | restartIfChanged = false; | 54 | restartIfChanged = false; |
| 34 | serviceConfig = { | 55 | serviceConfig = { |
| 35 | Type = "notify"; | 56 | Type = "notify"; |
| 36 | NotifyAccess = "all"; | 57 | NotifyAccess = "all"; |
| 37 | ExecStartPre = [ | 58 | ExecStartPre = [ |
| 38 | "${pkgs.util-linux}/bin/mountpoint -q ${root}" | 59 | (pkgs.writeShellScript "check-knife-root" '' |
| 60 | test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint ${root})" = work/knife-linux | ||
| 61 | '') | ||
| 39 | checkWork | 62 | checkWork |
| 40 | "${run} build --quiet --build-arg=UID=${uid} --build-arg=GID=${gid} --tag=localhost/knife-linux --file=${./knife-linux.Containerfile} /var/empty" | 63 | "${run} build --quiet --build-arg=UID=${uid} --build-arg=GID=${gid} --tag=localhost/knife-linux --file=${./knife-linux.Containerfile} /var/empty" |
| 41 | ]; | 64 | ]; |
| ... | @@ -45,7 +68,6 @@ in | ... | @@ -45,7 +68,6 @@ in |
| 45 | "--user=${uid}:${gid} --umask=0077 --cap-drop=ALL --security-opt=no-new-privileges" | 68 | "--user=${uid}:${gid} --umask=0077 --cap-drop=ALL --security-opt=no-new-privileges" |
| 46 | "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman" | 69 | "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman" |
| 47 | "--volume=${root}/home:/home/clo" | 70 | "--volume=${root}/home:/home/clo" |
| 48 | "--volume=${sandbox}:/Volumes/Code" | ||
| 49 | "--volume=/srv/work:/work" | 71 | "--volume=/srv/work:/work" |
| 50 | "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro" | 72 | "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro" |
| 51 | "--device=/dev/kvm" | 73 | "--device=/dev/kvm" |
nixos/tests/knife-linux-storage.nix created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | { pkgs }: | ||
| 2 | pkgs.testers.runNixOSTest { | ||
| 3 | name = "knife-linux-storage"; | ||
| 4 | nodes.machine = { lib, ... }: { | ||
| 5 | imports = [ ../knife-linux.nix ]; | ||
| 6 | virtualisation = { memorySize = 2048; cores = 2; emptyDiskImages = [ 2048 2048 ]; }; | ||
| 7 | networking.hostId = "a1b2c3d4"; | ||
| 8 | boot.supportedFilesystems = [ "zfs" ]; | ||
| 9 | boot.zfs.forceImportRoot = false; | ||
| 10 | users.groups.chloe.gid = 3000; | ||
| 11 | users.users.clo = { isSystemUser = true; uid = 3000; group = "chloe"; }; | ||
| 12 | environment.systemPackages = [ pkgs.zfs pkgs.util-linux pkgs.rsync pkgs.acl pkgs.attr ]; | ||
| 13 | systemd.services.knife-linux.wantedBy = lib.mkForce [ ]; | ||
| 14 | systemd.services.knife-linux-storage = { | ||
| 15 | requires = lib.mkForce [ ]; | ||
| 16 | after = lib.mkForce [ ]; | ||
| 17 | serviceConfig = { | ||
| 18 | LoadCredentialEncrypted = lib.mkForce [ ]; | ||
| 19 | LoadCredential = "zfs-clover:/run/test-key"; | ||
| 20 | }; | ||
| 21 | }; | ||
| 22 | }; | ||
| 23 | testScript = '' | ||
| 24 | start_all() | ||
| 25 | machine.succeed("head -c 32 /dev/urandom | od -An -v -tx1 | tr -d ' \\n' > /run/test-key; chmod 600 /run/test-key") | ||
| 26 | machine.succeed("zpool create -O mountpoint=none globe /dev/vdb") | ||
| 27 | machine.succeed("zpool create -O mountpoint=none work /dev/vdc") | ||
| 28 | machine.succeed("zfs create -o encryption=aes-256-gcm -o keyformat=hex -o keylocation=file:///run/test-key -o mountpoint=/source globe/clover") | ||
| 29 | machine.succeed("zfs create -o mountpoint=/srv/knife-linux -o casesensitivity=sensitive -o acltype=posix -o xattr=sa globe/clover/knife-linux") | ||
| 30 | machine.succeed("mkdir -p /srv/knife-linux/home/.knife/userdata /srv/knife-linux/home/.local/bin; echo initial > /srv/knife-linux/home/.knife/userdata/state; echo launcher > /srv/knife-linux/home/.local/bin/knife; echo excluded > /srv/knife-linux/home/excluded") | ||
| 31 | machine.succeed("chown 3000:3000 /srv/knife-linux/home/.knife/userdata/state; setfacl -m u:3000:rw /srv/knife-linux/home/.knife/userdata/state; setfattr -n user.fixture -v retained /srv/knife-linux/home/.knife/userdata/state") | ||
| 32 | machine.succeed("zfs create -o encryption=aes-256-gcm -o keyformat=hex -o keylocation=file:///run/test-key -o mountpoint=/target -o casesensitivity=sensitive -o acltype=posix -o xattr=sa work/knife-linux") | ||
| 33 | machine.succeed("mkdir -p /target/home/.local/bin; rsync -aAX --numeric-ids --no-specials /srv/knife-linux/home/.knife /target/home/; rsync -aAX --numeric-ids --no-specials /srv/knife-linux/home/.local/bin/knife /target/home/.local/bin/") | ||
| 34 | machine.succeed("echo final > /srv/knife-linux/home/.knife/userdata/state; rsync -aAX --numeric-ids --no-specials /srv/knife-linux/home/.knife /target/home/") | ||
| 35 | machine.succeed("zfs unmount globe/clover/knife-linux; zfs set mountpoint=none globe/clover/knife-linux; zfs unmount work/knife-linux; zfs unload-key work/knife-linux; zfs set mountpoint=/srv/knife-linux work/knife-linux") | ||
| 36 | assert machine.succeed("zfs get -H -o value encryptionroot work/knife-linux").strip() == "work/knife-linux" | ||
| 37 | machine.succeed("systemctl start knife-linux-storage.service") | ||
| 38 | assert machine.succeed("cat /srv/knife-linux/home/.knife/userdata/state").strip() == "final" | ||
| 39 | assert machine.succeed("stat -c '%u:%g' /srv/knife-linux/home/.knife/userdata/state").strip() == "3000:3000" | ||
| 40 | assert machine.succeed("getfattr -n user.fixture --only-values /srv/knife-linux/home/.knife/userdata/state").strip() == "retained" | ||
| 41 | assert "user:clo:rw-" in machine.succeed("getfacl /srv/knife-linux/home/.knife/userdata/state") | ||
| 42 | machine.fail("test -e /srv/knife-linux/home/excluded") | ||
| 43 | assert machine.succeed("findmnt -n -o SOURCE --mountpoint /srv/knife-linux").strip() == "work/knife-linux" | ||
| 44 | machine.succeed("systemctl stop knife-linux-storage.service; zfs unmount work/knife-linux; zfs unload-key work/knife-linux") | ||
| 45 | machine.succeed("systemctl start knife-linux-storage.service") | ||
| 46 | assert machine.succeed("cat /srv/knife-linux/home/.knife/userdata/state").strip() == "final" | ||
| 47 | machine.succeed("systemctl stop knife-linux-storage.service; zfs unmount work/knife-linux; zfs set mountpoint=/wrong work/knife-linux") | ||
| 48 | machine.fail("systemctl start knife-linux-storage.service") | ||
| 49 | ''; | ||
| 50 | } | ||
tools/knife-linux.md+5-11| ... | @@ -23,21 +23,15 @@ added to the running container. | ... | @@ -23,21 +23,15 @@ added to the running container. |
| 23 | 23 | ||
| 24 | | Container path | Host source | | 24 | | Container path | Host source | |
| 25 | | --- | --- | | 25 | | --- | --- | |
| 26 | | `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` | | ||
| 27 | | `/work` | the unencrypted, uncompressed `work` SSD pool, `/srv/work` | | 26 | | `/work` | the unencrypted, uncompressed `work` SSD pool, `/srv/work` | |
| 28 | | `/home/clo` | `/srv/knife-linux/home` on `globe/clover/knife-linux` | | 27 | | `/home/clo` | `/srv/knife-linux/home` on encrypted `work/knife-linux` | |
| 29 | | `/usr/local/bin/jj` | the storage host's `jj-real`, read-only | | 28 | | `/usr/local/bin/jj` | the storage host's `jj-real`, read-only | |
| 30 | 29 | ||
| 31 | Projects keep the Mac VM's paths, so jj workspaces, Knife project paths, and | 30 | jj per-repo configs in `~/.config/jj/repos` are copies of the Mac VM's, keyed |
| 32 | Claude memory keys match on both. A workspace's `node_modules` serves one OS at | 31 | by each repository's `config-id`. |
| 33 | a time; run `vp i` after moving a workspace between them. pnpm's global config | ||
| 34 | uses the storage host's `/Volumes/Code/cache/pnpm12` store and `files` index | ||
| 35 | format. jj per-repo configs in `~/.config/jj/repos` are copies of the Mac VM's, | ||
| 36 | keyed by each repository's `config-id`. | ||
| 37 | 32 | ||
| 38 | `globe/clover/knife-linux` must stay case-sensitive. Its parent is not, and | 33 | `work/knife-linux` must stay case-sensitive for Fedora packages and overlay |
| 39 | Fedora packages and overlay layers fail under case folding. Podman's store lives | 34 | layers. `knife-linux-podman` is the |
| 40 | on this dataset because the root NVMe is nearly full. `knife-linux-podman` is the | ||
| 41 | only entry point to that store: it pins a separate temp directory and file locks, | 35 | only entry point to that store: it pins a separate temp directory and file locks, |
| 42 | because a second rootful store sharing Nomad's lock segment would free the other | 36 | because a second rootful store sharing Nomad's lock segment would free the other |
| 43 | store's locks during its post-reboot refresh. | 37 | store's locks during its post-reboot refresh. |