···9696 <option>systemd.services.supybot.serviceConfig</option>.
9797 </para>
9898 </listitem>
9999+ <listitem>
100100+ <para>
101101+ The <literal>security.duosec.skey</literal> option, which stored a secret in the
102102+ nix store, has been replaced by a new
103103+ <link linkend="opt-security.duosec.secretKeyFile">security.duosec.secretKeyFile</link>
104104+ option for better security.
105105+ </para>
106106+ <para>
107107+ <literal>security.duosec.ikey</literal> has been renamed to
108108+ <link linkend="opt-security.duosec.integrationKey">security.duosec.integrationKey</link>.
109109+ </para>
110110+ </listitem>
99111 </itemizedlist>
100112 </section>
101113
+56-36
nixos/modules/security/duosec.nix
···991010 configFilePam = ''
1111 [duo]
1212- ikey=${cfg.ikey}
1313- skey=${cfg.skey}
1212+ ikey=${cfg.integrationKey}
1413 host=${cfg.host}
1514 ${optionalString (cfg.groups != "") ("groups="+cfg.groups)}
1615 failmode=${cfg.failmode}
···2423 motd=${boolToStr cfg.motd}
2524 accept_env_factor=${boolToStr cfg.acceptEnvFactor}
2625 '';
2727-2828- loginCfgFile = optionalAttrs cfg.ssh.enable {
2929- "duo/login_duo.conf" =
3030- { source = pkgs.writeText "login_duo.conf" configFileLogin;
3131- mode = "0600";
3232- user = "sshd";
3333- };
3434- };
3535-3636- pamCfgFile = optional cfg.pam.enable {
3737- "duo/pam_duo.conf" =
3838- { source = pkgs.writeText "pam_duo.conf" configFilePam;
3939- mode = "0600";
4040- user = "sshd";
4141- };
4242- };
4326in
4427{
4528 imports = [
4629 (mkRenamedOptionModule [ "security" "duosec" "group" ] [ "security" "duosec" "groups" ])
3030+ (mkRenamedOptionModule [ "security" "duosec" "ikey" ] [ "security" "duosec" "integrationKey" ])
3131+ (mkRemovedOptionModule [ "security" "duosec" "skey" ] "The insecure security.duosec.skey option has been replaced by a new security.duosec.secretKeyFile option. Use this new option to store a secure copy of your key instead.")
4732 ];
48334934 options = {
···6045 description = "If enabled, protect logins with Duo Security using PAM support.";
6146 };
62476363- ikey = mkOption {
4848+ integrationKey = mkOption {
6449 type = types.str;
6550 description = "Integration key.";
6651 };
67526868- skey = mkOption {
6969- type = types.str;
7070- description = "Secret key.";
5353+ secretKeyFile = mkOption {
5454+ type = types.path;
5555+ default = null;
5656+ description = ''
5757+ A file containing your secret key. The security of your Duo application is tied to the security of your secret key.
5858+ '';
5959+ example = "/run/keys/duo-skey";
7160 };
72617362 host = mkOption {
···195184 };
196185197186 config = mkIf (cfg.ssh.enable || cfg.pam.enable) {
198198- environment.systemPackages = [ pkgs.duo-unix ];
187187+ environment.systemPackages = [ pkgs.duo-unix ];
188188+189189+ security.wrappers.login_duo.source = "${pkgs.duo-unix.out}/bin/login_duo";
190190+191191+ system.activationScripts = {
192192+ login_duo = mkIf cfg.ssh.enable ''
193193+ if test -f "${cfg.secretKeyFile}"; then
194194+ mkdir -m 0755 -p /etc/duo
195195+196196+ umask 0077
197197+ conf="$(mktemp)"
198198+ {
199199+ cat ${pkgs.writeText "login_duo.conf" configFileLogin}
200200+ printf 'skey = %s\n' "$(cat ${cfg.secretKeyFile})"
201201+ } >"$conf"
202202+203203+ chown sshd "$conf"
204204+ mv -fT "$conf" /etc/duo/login_duo.conf
205205+ fi
206206+ '';
207207+ pam_duo = mkIf cfg.pam.enable ''
208208+ if test -f "${cfg.secretKeyFile}"; then
209209+ mkdir -m 0755 -p /etc/duo
210210+211211+ umask 0077
212212+ conf="$(mktemp)"
213213+ {
214214+ cat ${pkgs.writeText "login_duo.conf" configFilePam}
215215+ printf 'skey = %s\n' "$(cat ${cfg.secretKeyFile})"
216216+ } >"$conf"
199217200200- security.wrappers.login_duo.source = "${pkgs.duo-unix.out}/bin/login_duo";
201201- environment.etc = loginCfgFile // pamCfgFile;
218218+ mv -fT "$conf" /etc/duo/pam_duo.conf
219219+ fi
220220+ '';
221221+ };
202222203203- /* If PAM *and* SSH are enabled, then don't do anything special.
204204- If PAM isn't used, set the default SSH-only options. */
205205- services.openssh.extraConfig = mkIf (cfg.ssh.enable || cfg.pam.enable) (
206206- if cfg.pam.enable then "UseDNS no" else ''
207207- # Duo Security configuration
208208- ForceCommand ${config.security.wrapperDir}/login_duo
209209- PermitTunnel no
210210- ${optionalString (!cfg.allowTcpForwarding) ''
211211- AllowTcpForwarding no
212212- ''}
213213- '');
223223+ /* If PAM *and* SSH are enabled, then don't do anything special.
224224+ If PAM isn't used, set the default SSH-only options. */
225225+ services.openssh.extraConfig = mkIf (cfg.ssh.enable || cfg.pam.enable) (
226226+ if cfg.pam.enable then "UseDNS no" else ''
227227+ # Duo Security configuration
228228+ ForceCommand ${config.security.wrapperDir}/login_duo
229229+ PermitTunnel no
230230+ ${optionalString (!cfg.allowTcpForwarding) ''
231231+ AllowTcpForwarding no
232232+ ''}
233233+ '');
214234 };
215235}