git.iko.soy/typeable/nixpkgs
on master help sign in
initrd-ssh: Use initrd secrets for host keys
commit3a26d09e1542494770ff2f3f571d3b0e94d21218 authorShea Levy <shea@shealevy.com> dateSun 2 Apr 2017, 15:35 (10 years ago) parentb09490a
1 file changed+17−16
nixos/modules/system/boot/initrd-ssh.nix+17−16
nixos/modules/system/boot/initrd-ssh.nix+17−16
@@ -44,9 +44,10 @@ in
4444 description = ''
4545 RSA SSH private key file in the Dropbear format.
4646
47− WARNING: This key is contained insecurely in the global Nix store. Do NOT
48− use your regular SSH host private keys for this purpose or you'll expose
49− them to regular users!
47+ WARNING: Unless your bootloader supports initrd secrets, this key is
48+ contained insecurely in the global Nix store. Do NOT use your regular
49+ SSH host private keys for this purpose or you'll expose them to
50+ regular users!
5051 '';
5152 };
5253
@@ -56,9 +57,10 @@ in
5657 description = ''
5758 DSS SSH private key file in the Dropbear format.
5859
59− WARNING: This key is contained insecurely in the global Nix store. Do NOT
60− use your regular SSH host private keys for this purpose or you'll expose
61− them to regular users!
60+ WARNING: Unless your bootloader supports initrd secrets, this key is
61+ contained insecurely in the global Nix store. Do NOT use your regular
62+ SSH host private keys for this purpose or you'll expose them to
63+ regular users!
6264 '';
6365 };
6466
@@ -68,9 +70,10 @@ in
6870 description = ''
6971 ECDSA SSH private key file in the Dropbear format.
7072
71− WARNING: This key is contained insecurely in the global Nix store. Do NOT
72− use your regular SSH host private keys for this purpose or you'll expose
73− them to regular users!
73+ WARNING: Unless your bootloader supports initrd secrets, this key is
74+ contained insecurely in the global Nix store. Do NOT use your regular
75+ SSH host private keys for this purpose or you'll expose them to
76+ regular users!
7477 '';
7578 };
7679
@@ -97,10 +100,6 @@ in
97100 boot.initrd.extraUtilsCommands = ''
98101 copy_bin_and_libs ${pkgs.dropbear}/bin/dropbear
99102 cp -pv ${pkgs.glibc.out}/lib/libnss_files.so.* $out/lib
100−
101− ${optionalString (cfg.hostRSAKey != null) "install -D ${cfg.hostRSAKey} $out/etc/dropbear/dropbear_rsa_host_key"}
102− ${optionalString (cfg.hostDSSKey != null) "install -D ${cfg.hostDSSKey} $out/etc/dropbear/dropbear_dss_host_key"}
103− ${optionalString (cfg.hostECDSAKey != null) "install -D ${cfg.hostECDSAKey} $out/etc/dropbear/dropbear_ecdsa_host_key"}
104103 '';
105104
106105 boot.initrd.extraUtilsCommandsTest = ''
@@ -116,9 +115,6 @@ in
116115 touch /var/log/lastlog
117116
118117 mkdir -p /etc/dropbear
119− ${optionalString (cfg.hostRSAKey != null) "ln -s $extraUtils/etc/dropbear/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key"}
120− ${optionalString (cfg.hostDSSKey != null) "ln -s $extraUtils/etc/dropbear/dropbear_dss_host_key /etc/dropbear/dropbear_dss_host_key"}
121− ${optionalString (cfg.hostECDSAKey != null) "ln -s $extraUtils/etc/dropbear/dropbear_ecdsa_host_key /etc/dropbear/dropbear_ecdsa_host_key"}
122118
123119 mkdir -p /root/.ssh
124120 ${concatStrings (map (key: ''
@@ -128,6 +124,11 @@ in
128124 dropbear -s -j -k -E -m -p ${toString cfg.port}
129125 '';
130126
127+ boot.initrd.secrets =
128+ (optionalAttrs (cfg.hostRSAKey != null) { "/etc/dropbear/dropbear_rsa_host_key" = cfg.hostRSAKey; }) //
129+ (optionalAttrs (cfg.hostDSSKey != null) { "/etc/dropbear/dropbear_dss_host_key" = cfg.hostDSSKey; }) //
130+ (optionalAttrs (cfg.hostECDSAKey != null) { "/etc/dropbear/dropbear_ecdsa_host_key" = cfg.hostECDSAKey; });
131+
131132 };
132133
133134}