1 import ../make-test-python.nix ({ pkgs, lib, ... }:
4 testOnlySSHCredentials = pkgs.runCommand "pam-ussh-test-ca" {
5 nativeBuildInputs = [ pkgs.openssh ];
8 ssh-keygen -t ed25519 -N "" -f $out/ca
10 ssh-keygen -t ed25519 -N "" -f $out/alice
11 ssh-keygen -s $out/ca -I "alice user key" -n "alice,root" -V 19700101:forever $out/alice.pub
13 ssh-keygen -t ed25519 -N "" -f $out/bob
14 ssh-keygen -s $out/ca -I "bob user key" -n "bob" -V 19700101:forever $out/bob.pub
16 makeTestScript = user: pkgs.writeShellScript "pam-ussh-${user}-test-script" ''
19 eval $(${pkgs.openssh}/bin/ssh-agent)
23 cp ${testOnlySSHCredentials}/${user}{,.pub,-cert.pub} $HOME/.ssh
24 chmod 600 $HOME/.ssh/${user}
25 chmod 644 $HOME/.ssh/${user}{,-cert}.pub
29 ${pkgs.openssh}/bin/ssh-add $HOME/.ssh/${user}
30 ${pkgs.openssh}/bin/ssh-add -l &>2
36 meta.maintainers = with lib.maintainers; [ lukegb ];
41 users.users.alice = { isNormalUser = true; extraGroups = [ "wheel" ]; };
42 users.users.bob = { isNormalUser = true; extraGroups = [ "wheel" ]; };
46 authorizedPrincipals = "root";
47 caFile = "${testOnlySSHCredentials}/ca.pub";
53 Defaults lecture="never"
60 with subtest("alice should be allowed to escalate to root"):
62 'su -c "${makeTestScript "alice"}" -l alice | grep root'
65 with subtest("bob should not be allowed to escalate to root"):
67 'su -c "${makeTestScript "bob"}" -l bob | grep root'