Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #230857 from s1341/bugfix_pam_sssd

nixos/pam: Allow password changing via sssd

authored by Ryan Lahfa and committed by GitHub fe7b996d 84b4373d

+78 -6
+1 -1
nixos/modules/security/pam.nix
··· 638 638 password sufficient ${pkgs.pam_mysql}/lib/security/pam_mysql.so config_file=/etc/security/pam_mysql.conf 639 639 '' + 640 640 optionalString config.services.sssd.enable '' 641 - password sufficient ${pkgs.sssd}/lib/security/pam_sss.so use_authtok 641 + password sufficient ${pkgs.sssd}/lib/security/pam_sss.so 642 642 '' + 643 643 optionalString config.security.pam.krb5.enable '' 644 644 password sufficient ${pam_krb5}/lib/security/pam_krb5.so use_first_pass
+76 -4
nixos/tests/sssd-ldap.nix
··· 6 6 ldapRootPassword = "foobar"; 7 7 8 8 testUser = "alice"; 9 - in import ./make-test-python.nix ({pkgs, ...}: { 9 + testPassword = "foobar"; 10 + testNewPassword = "barfoo"; 11 + in 12 + import ./make-test-python.nix ({ pkgs, ... }: { 10 13 name = "sssd-ldap"; 11 14 12 15 meta = with pkgs.lib.maintainers; { 13 - maintainers = [ bbigras ]; 16 + maintainers = [ bbigras s1341 ]; 14 17 }; 15 18 16 19 nodes.machine = { pkgs, ... }: { 20 + security.pam.services.systemd-user.makeHomeDir = true; 21 + environment.etc."cert.pem".text = builtins.readFile ./common/acme/server/acme.test.cert.pem; 22 + environment.etc."key.pem".text = builtins.readFile ./common/acme/server/acme.test.key.pem; 17 23 services.openldap = { 18 24 enable = true; 25 + urlList = [ "ldap:///" "ldaps:///" ]; 19 26 settings = { 27 + attrs = { 28 + olcTLSCACertificateFile = "/etc/cert.pem"; 29 + olcTLSCertificateFile = "/etc/cert.pem"; 30 + olcTLSCertificateKeyFile = "/etc/key.pem"; 31 + olcTLSCipherSuite = "HIGH:MEDIUM:+3DES:+RC4:+aNULL"; 32 + olcTLSCRLCheck = "none"; 33 + olcTLSVerifyClient = "never"; 34 + olcTLSProtocolMin = "3.1"; 35 + }; 20 36 children = { 21 37 "cn=schema".includes = [ 22 38 "${pkgs.openldap}/etc/schema/core.ldif" ··· 32 48 olcSuffix = dbSuffix; 33 49 olcRootDN = "cn=${ldapRootUser},${dbSuffix}"; 34 50 olcRootPW = ldapRootPassword; 51 + olcAccess = [ 52 + /* 53 + custom access rules for userPassword attributes 54 + */ 55 + '' 56 + {0}to attrs=userPassword 57 + by self write 58 + by anonymous auth 59 + by * none'' 60 + 61 + /* 62 + allow read on anything else 63 + */ 64 + '' 65 + {1}to * 66 + by * read'' 67 + ]; 35 68 }; 36 69 }; 37 70 }; ··· 55 88 dn: uid=${testUser},ou=accounts,ou=posix,${dbSuffix} 56 89 objectClass: person 57 90 objectClass: posixAccount 58 - # userPassword: somePasswordHash 91 + userPassword: ${testPassword} 59 92 homeDirectory: /home/${testUser} 60 93 uidNumber: 1234 61 94 gidNumber: 1234 ··· 78 111 [domain/${dbDomain}] 79 112 auth_provider = ldap 80 113 id_provider = ldap 81 - ldap_uri = ldap://127.0.0.1:389 114 + ldap_uri = ldaps://127.0.0.1:636 115 + ldap_tls_reqcert = allow 116 + ldap_tls_cacert = /etc/cert.pem 82 117 ldap_search_base = ${dbSuffix} 83 118 ldap_default_bind_dn = cn=${ldapRootUser},${dbSuffix} 84 119 ldap_default_authtok_type = password ··· 97 132 else: 98 133 machine.wait_for_console_text("Backend is online") 99 134 machine.succeed("getent passwd ${testUser}") 135 + 136 + with subtest("Log in as ${testUser}"): 137 + machine.wait_until_tty_matches("1", "login: ") 138 + machine.send_chars("${testUser}\n") 139 + machine.wait_until_tty_matches("1", "login: ${testUser}") 140 + machine.wait_until_succeeds("pgrep login") 141 + machine.wait_until_tty_matches("1", "Password: ") 142 + machine.send_chars("${testPassword}\n") 143 + machine.wait_until_succeeds("pgrep -u ${testUser} bash") 144 + machine.send_chars("touch done\n") 145 + machine.wait_for_file("/home/${testUser}/done") 146 + 147 + with subtest("Change ${testUser}'s password"): 148 + machine.send_chars("passwd\n") 149 + machine.wait_until_tty_matches("1", "Current Password: ") 150 + machine.send_chars("${testPassword}\n") 151 + machine.wait_until_tty_matches("1", "New Password: ") 152 + machine.send_chars("${testNewPassword}\n") 153 + machine.wait_until_tty_matches("1", "Reenter new Password: ") 154 + machine.send_chars("${testNewPassword}\n") 155 + machine.wait_until_tty_matches("1", "passwd: password updated successfully") 156 + 157 + with subtest("Log in as ${testUser} with new password in virtual console 2"): 158 + machine.send_key("alt-f2") 159 + machine.wait_until_succeeds("[ $(fgconsole) = 2 ]") 160 + machine.wait_for_unit("getty@tty2.service") 161 + machine.wait_until_succeeds("pgrep -f 'agetty.*tty2'") 162 + 163 + machine.wait_until_tty_matches("2", "login: ") 164 + machine.send_chars("${testUser}\n") 165 + machine.wait_until_tty_matches("2", "login: ${testUser}") 166 + machine.wait_until_succeeds("pgrep login") 167 + machine.wait_until_tty_matches("2", "Password: ") 168 + machine.send_chars("${testNewPassword}\n") 169 + machine.wait_until_succeeds("pgrep -u ${testUser} bash") 170 + machine.send_chars("touch done2\n") 171 + machine.wait_for_file("/home/${testUser}/done2") 100 172 ''; 101 173 })
+1 -1
pkgs/os-specific/linux/pam/default.nix
··· 44 44 doCheck = false; # fails 45 45 46 46 passthru.tests = { 47 - inherit (nixosTests) pam-oath-login pam-u2f shadow; 47 + inherit (nixosTests) pam-oath-login pam-u2f shadow sssd-ldap; 48 48 }; 49 49 50 50 meta = with lib; {