]> Git — Sourcephile - sourcephile-nix.git/blob - machines/losurdo/security.nix
ssh: add reverse ssh giving access to losurdo from mermet
[sourcephile-nix.git] / machines / losurdo / security.nix
1 { pkgs, lib, config, machineName, ... }:
2 let
3 inherit (config.security) gnupg;
4 rootKey = "root/key";
5 initrdKey = "initrd/ssh.key";
6 keygrip = "9AA84E6F6D71F9163C46BF396B141A0806219077";
7 in
8 {
9 imports = [
10 <nixpkgs/nixos/modules/profiles/hardened.nix>
11 ];
12 security.gnupg.store = builtins.getEnv "PASSWORD_STORE_DIR" + "/machines/${machineName}";
13 services.openssh.extraConfig = ''
14 StreamLocalBindUnlink yes
15 '';
16 installer.ssh-nixos = {
17 PATH = [pkgs.gnupg pkgs.openssh];
18 sshFlags = [
19 #"-R" "/var/lib/gnupg/S.gpg-agent.extra:/run/user/1000/gnupg/d.w1sj57hx3zfcwadyxpr6wko9/S.gpg-agent.extra"
20 #"-o" "StreamLocalBindUnlink=yes"
21 ];
22 script = lib.mkMerge [
23 (lib.mkBefore ''
24 # Send the SSH key of the initrd
25 gpg --decrypt '${gnupg.store}/${initrdKey}.gpg' |
26 ssh '${config.installer.ssh-nixos.target}' \
27 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
28 '')
29 (lib.mkBefore ''
30 ssh '${config.installer.ssh-nixos.target}' \
31 gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
32 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
33 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
34 # Send the rootKey
35 gpg --decrypt '${gnupg.store}/${rootKey}.pass.gpg' |
36 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
37 ssh '${config.installer.ssh-nixos.target}' \
38 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
39
40 # Send the rootKey's passphrase
41 gpg --decrypt '${gnupg.store}/${rootKey}.pass.gpg' |
42 ssh '${config.installer.ssh-nixos.target}' \
43 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
44 }
45 '')
46 ];
47 /*
48 # Send the rootKey
49 gpg --decrypt '${gnupg.store}/${rootKey}.pass.gpg' |
50 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
51 ssh '${config.installer.ssh-nixos.target}' \
52 gpg --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
53
54 gpg --batch --export @root@${machineName} |
55 ssh '${config.installer.ssh-nixos.target}' \
56 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
57 */
58
59 };
60 boot.initrd.network.ssh.hostKeys = [ "/root/${initrdKey}" ];
61 }