git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #8602 from ts468/upstream.pam

Security: integrate pam_mount into PAM of NixOS

commitd7869f46ca107535fd6c975b6a4c91537628bfbd authorlethalman <lucabru@src.gnome.org> dateSun 5 Jul 2015, 00:40 (11 years ago) parentd1bb5177b6f279
4 files changed+98−2
nixos/modules/config/users-groups.nix+9 nixos/modules/module-list.nix+1 nixos/modules/security/pam.nix+16−2 nixos/modules/security/pam_mount.nix+72
nixos/modules/config/users-groups.nix+9
@@ -108,6 +108,15 @@ let
108108 description = "The user's home directory.";
109109 };
110110
111+ cryptHomeLuks = mkOption {
112+ type = with types; nullOr str;
113+ default = null;
114+ description = ''
115+ Path to encrypted luks device that contains
116+ the user's home directory.
117+ '';
118+ };
119+
111120 shell = mkOption {
112121 type = types.str;
113122 default = "/run/current-system/sw/bin/nologin";
nixos/modules/module-list.nix+1
@@ -84,6 +84,7 @@
8484 ./security/grsecurity.nix
8585 ./security/pam.nix
8686 ./security/pam_usb.nix
87+ ./security/pam_mount.nix
8788 ./security/polkit.nix
8889 ./security/prey.nix
8990 ./security/rngd.nix
nixos/modules/security/pam.nix+16−2
@@ -126,6 +126,14 @@ let
126126 '';
127127 };
128128
129+ pamMount = mkOption {
130+ default = config.security.pam.mount.enable;
131+ type = types.bool;
132+ description = ''
133+ Enable PAM mount (pam_mount) system to mount fileystems on user login.
134+ '';
135+ };
136+
129137 allowNullPassword = mkOption {
130138 default = false;
131139 type = types.bool;
@@ -224,7 +232,9 @@ let
224232 ${optionalString cfg.usbAuth
225233 "auth sufficient ${pkgs.pam_usb}/lib/security/pam_usb.so"}
226234 ${optionalString cfg.unixAuth
227− "auth ${if config.security.pam.enableEcryptfs then "required" else "sufficient"} pam_unix.so ${optionalString cfg.allowNullPassword "nullok"} likeauth"}
235+ "auth ${if (config.security.pam.enableEcryptfs || cfg.pamMount) then "required" else "sufficient"} pam_unix.so ${optionalString cfg.allowNullPassword "nullok"} likeauth"}
236+ ${optionalString cfg.pamMount
237+ "auth optional ${pkgs.pam_mount}/lib/security/pam_mount.so"}
228238 ${optionalString config.security.pam.enableEcryptfs
229239 "auth required ${pkgs.ecryptfs}/lib/security/pam_ecryptfs.so unwrap"}
230240 ${optionalString cfg.otpwAuth
@@ -238,12 +248,14 @@ let
238248 auth [default=die success=done] ${pam_ccreds}/lib/security/pam_ccreds.so action=validate use_first_pass
239249 auth sufficient ${pam_ccreds}/lib/security/pam_ccreds.so action=store use_first_pass
240250 ''}
241− ${optionalString (! config.security.pam.enableEcryptfs) "auth required pam_deny.so"}
251+ ${optionalString (!(config.security.pam.enableEcryptfs || cfg.pamMount)) "auth required pam_deny.so"}
242252
243253 # Password management.
244254 ${optionalString config.security.pam.enableEcryptfs
245255 "password optional ${pkgs.ecryptfs}/lib/security/pam_ecryptfs.so"}
246256 password requisite pam_unix.so nullok sha512
257+ ${optionalString cfg.pamMount
258+ "password optional ${pkgs.pam_mount}/lib/security/pam_mount.so"}
247259 ${optionalString config.users.ldap.enable
248260 "password sufficient ${pam_ldap}/lib/security/pam_ldap.so"}
249261 ${optionalString config.krb5.enable
@@ -280,6 +292,8 @@ let
280292 "session required ${pkgs.pam}/lib/security/pam_limits.so conf=${makeLimitsConf cfg.limits}"}
281293 ${optionalString (cfg.showMotd && config.users.motd != null)
282294 "session optional ${pkgs.pam}/lib/security/pam_motd.so motd=${motd}"}
295+ ${optionalString cfg.pamMount
296+ "session optional ${pkgs.pam_mount}/lib/security/pam_mount.so"}
283297 '';
284298 };
285299
nixos/modules/security/pam_mount.nixnew file+72
@@ -0,0 +1,72 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.security.pam.mount;
7+
8+ anyPamMount = any (attrByPath ["pamMount"] false) (attrValues config.security.pam.services);
9+in
10+
11+{
12+ options = {
13+
14+ security.pam.mount = {
15+ enable = mkOption {
16+ type = types.bool;
17+ default = false;
18+ description = ''
19+ Enable PAM mount system to mount fileystems on user login.
20+ '';
21+ };
22+
23+ extraVolumes = mkOption {
24+ type = types.listOf types.str;
25+ default = [];
26+ description = ''
27+ List of volume definitions for pam_mount.
28+ For more information, visit <link
29+ xlink:href="http://pam-mount.sourceforge.net/pam_mount.conf.5.html" />.
30+ '';
31+ };
32+ };
33+
34+ };
35+
36+ config = mkIf (cfg.enable || anyPamMount) {
37+
38+ environment.systemPackages = [ pkgs.pam_mount ];
39+ environment.etc = [{
40+ target = "security/pam_mount.conf.xml";
41+ source =
42+ let
43+ extraUserVolumes = filterAttrs (n: u: u.cryptHomeLuks != null) config.users.extraUsers;
44+ userVolumeEntry = user: "<volume user=\"${user.name}\" path=\"${user.cryptHomeLuks}\" mountpoint=\"${user.home}\" />\n";
45+ in
46+ pkgs.writeText "pam_mount.conf.xml" ''
47+ <?xml version="1.0" encoding="utf-8" ?>
48+ <!DOCTYPE pam_mount SYSTEM "pam_mount.conf.xml.dtd">
49+ <!-- auto generated from Nixos: modules/config/users-groups.nix -->
50+ <pam_mount>
51+ <debug enable="0" />
52+
53+ ${concatStrings (map userVolumeEntry (attrValues extraUserVolumes))}
54+ ${concatStringsSep "\n" cfg.extraVolumes}
55+
56+ <!-- if activated, requires ofl from hxtools to be present -->
57+ <logout wait="0" hup="no" term="no" kill="no" />
58+ <!-- set PATH variable for pam_mount module -->
59+ <path>${pkgs.utillinux}/bin</path>
60+ <!-- create mount point if not present -->
61+ <mkmountpoint enable="1" remove="true" />
62+
63+ <!-- specify the binaries to be called -->
64+ <cryptmount>${pkgs.pam_mount}/bin/mount.crypt %(VOLUME) %(MNTPT)</cryptmount>
65+ <cryptumount>${pkgs.pam_mount}/bin/umount.crypt %(MNTPT)</cryptumount>
66+ <pmvarrun>${pkgs.pam_mount}/bin/pmvarrun -u %(USER) -o %(OPERATION)</pmvarrun>
67+ </pam_mount>
68+ '';
69+ }];
70+
71+ };
72+}