# `checks.module-eval-agent-ssh-target` — see ./lib.nix for the shared # rationale (why this suite exists, naming convention, "evaluates # not executes"). # # ../target-modules/agent-ssh.nix, the module for a machine agents SSH into. It # needs a fixture of its own: it is not a hive host or an agent, and the # agent-side cases in ./agent-forge-bao.nix cannot evaluate it. { pkgs, lib, self, nixosSystem, }: let inherit (import ./lib.nix { inherit pkgs lib self nixosSystem ; }) runGroup ; caKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOHfYeWemIBqSc5Ac51ecuhi0G9LTN+57DFRq6mFKKk0"; machine = extra: (nixosSystem { system = pkgs.stdenv.hostPlatform.system; modules = [ self.nixosModules.agent-ssh-target { fileSystems."/" = { device = "/dev/null"; fsType = "tmpfs"; }; boot.loader.grub.enable = false; system.stateVersion = "25.11"; users.users.test.isNormalUser = true; users.users.ops.isNormalUser = true; } extra ]; }).config; trusting = machine { services.hyperhive.agentSshTarget = { enable = true; # The command's output ends in a newline. caPublicKey = "${caKey}\n"; principals.test = [ "atlas" "maia" ]; }; }; # The module imported and left off. untouched = machine { }; # Enabled with nobody listed. nobody = machine { services.hyperhive.agentSshTarget = { enable = true; caPublicKey = caKey; }; }; principalsOf = m: user: m.environment.etc."ssh/authorized_principals.d/${user}".text; cases = [ { name = "an enabled target trusts the CA's public key and ties sshd to the per-user principals file"; ok = trusting.services.openssh.enable && trusting.services.openssh.settings.TrustedUserCAKeys == "/etc/ssh/hyperhive-agent-ssh-ca.pub" && trusting.environment.etc."ssh/hyperhive-agent-ssh-ca.pub".text == "${caKey}\n" && trusting.services.openssh.settings.AuthorizedPrincipalsFile == "/etc/ssh/authorized_principals.d/%u"; } { # `ops` is a real account on the machine that no agent was listed for. name = "only the listed agents are principals of the listed user, and an unlisted user has no principals file"; ok = principalsOf trusting "test" == "atlas\nmaia" && !(trusting.environment.etc ? "ssh/authorized_principals.d/ops"); } { # No key is ever copied: the module writes none for any user. name = "the target module writes no authorized key"; ok = trusting.users.users.test.openssh.authorizedKeys.keys == [ ] && trusting.users.users.test.openssh.authorizedKeys.keyFiles == [ ]; } { # The absence arm, and the control that makes the cases above able to # fail: the same module, imported and not enabled, changes nothing. name = "an imported but disabled target trusts no CA"; ok = !(untouched.services.openssh.settings ? TrustedUserCAKeys) && !(untouched.environment.etc ? "ssh/hyperhive-agent-ssh-ca.pub") && untouched.services.openssh.settings.AuthorizedPrincipalsFile == "none" && !untouched.services.openssh.enable; } { name = "an enabled target that lists no agent is refused"; ok = let refuses = m: lib.any (a: !a.assertion && lib.hasInfix "agentSshTarget.principals" a.message) m.assertions; in refuses nobody && !(refuses trusting); } ]; in runGroup "agent-ssh-target" cases