Saltstack Official Linux Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.5KB

  1. {%- from "linux/map.jinja" import auth with context %}
  2. {%- if auth.enabled %}
  3. {%- set pam_modules_enable = "" %}
  4. {%- set pam_modules_disable = "" %}
  5. {%- if grains.os_family == 'Debian' %}
  6. linux_auth_pam_packages:
  7. pkg.installed:
  8. - pkgs: [ 'libpam-runtime' ]
  9. linux_auth_pam_add_profile:
  10. file.managed:
  11. - name: /usr/local/bin/pam-add-profile
  12. - source: salt://linux/files/pam-add-profile
  13. - mode: 755
  14. - require:
  15. - pkg: linux_auth_pam_packages
  16. {%- endif %}
  17. {%- if auth.get('mkhomedir', {}).get('enabled', False) %}
  18. {%- if grains.os_family == 'Debian' %}
  19. {%- set pam_modules_enable = pam_modules_enable + ' mkhomedir' %}
  20. linux_auth_mkhomedir_debconf_package:
  21. pkg.installed:
  22. - pkgs: [ 'debconf-utils' ]
  23. linux_auth_mkhomedir_config:
  24. file.managed:
  25. - name: /usr/share/pam-configs/mkhomedir
  26. - source: salt://linux/files/mkhomedir
  27. - template: jinja
  28. {%- endif %}
  29. {%- else %}
  30. {%- if grains.os_family == 'Debian' %}
  31. {%- set pam_modules_disable = pam_modules_disable + ' mkhomedir' %}
  32. {%- endif %}
  33. {%- endif %}
  34. {%- if auth.get('ldap', {}).get('enabled', False) %}
  35. {%- from "linux/map.jinja" import ldap with context %}
  36. {%- if grains.os_family == 'Debian' %}
  37. {%- set pam_modules_enable = pam_modules_enable + ' ldap' %}
  38. linux_auth_ldap_debconf_package:
  39. pkg.installed:
  40. - pkgs: [ 'debconf-utils' ]
  41. linux_auth_debconf_libnss-ldapd:
  42. debconf.set:
  43. - name: libnss-ldapd
  44. - data:
  45. libnss-ldapd/nsswitch:
  46. type: 'multiselect'
  47. value: 'group, passwd, shadow'
  48. libnss-ldapd/clean_nsswitch:
  49. type: 'boolean'
  50. value: 'false'
  51. - require_in:
  52. - pkg: linux_auth_ldap_packages
  53. - require:
  54. - pkg: linux_auth_ldap_debconf_package
  55. linux_auth_debconf_libpam-ldapd:
  56. debconf.set:
  57. - name: libpam-ldapd
  58. - data:
  59. libpam-ldapd/enable_shadow:
  60. type: 'boolean'
  61. value: 'true'
  62. {%- endif %}
  63. {%- else %}
  64. {%- if grains.os_family == 'Debian' %}
  65. {%- set pam_modules_disable = pam_modules_disable + ' ldap' %}
  66. {%- endif %}
  67. {%- endif %}
  68. {#- Setup PAM profiles #}
  69. {%- if grains.os_family == 'Debian' %}
  70. {%- if auth.get('mkhomedir', {}).get('enabled', False) %}
  71. linux_auth_pam_add_profiles_mkhomedir_enable:
  72. cmd.run:
  73. - name: /usr/local/bin/pam-add-profile {{ pam_modules_enable }}
  74. - unless: "[[ `grep -c pam_mkhomedir.so /etc/pam.d/common-session` -ne 0 ]]"
  75. - require:
  76. - file: linux_auth_pam_add_profile
  77. linux_auth_pam_add_profiles_mkhomedir_update:
  78. cmd.wait:
  79. - name: /usr/local/bin/pam-add-profile {{ pam_modules_enable }}
  80. - watch:
  81. - file: linux_auth_mkhomedir_config
  82. - require:
  83. - file: linux_auth_pam_add_profile
  84. {%- if auth.get('ldap', {}).get('enabled', False) %}
  85. - pkg: linux_auth_ldap_packages
  86. {%- endif %}
  87. {%- else %}
  88. linux_auth_pam_remove_profiles_mkhomedir:
  89. cmd.run:
  90. - name: /usr/sbin/pam-auth-update --remove {{ pam_modules_disable }}
  91. - onlyif: "[[ `grep -c pam_mkhomedir.so /etc/pam.d/common-session` -ne 0 ]]"
  92. - require:
  93. - pkg: linux_auth_pam_packages
  94. {%- endif %}
  95. {%- if auth.get('ldap', {}).get('enabled', False) %}
  96. linux_auth_pam_add_profiles_ldap:
  97. cmd.run:
  98. - name: /usr/local/bin/pam-add-profile {{ pam_modules_enable }}
  99. - unless: "[[ `debconf-get-selections | grep libpam-runtime/profiles | grep -c ldap` -ne 0 ]]"
  100. - require:
  101. - file: linux_auth_pam_add_profile
  102. - pkg: linux_auth_ldap_packages
  103. {%- else %}
  104. linux_auth_pam_remove_profiles_ldap:
  105. cmd.run:
  106. - name: /usr/sbin/pam-auth-update --remove {{ pam_modules_disable }}
  107. - onlyif: "[[ `debconf-get-selections | grep libpam-runtime/profiles | grep -c ldap` -ne 0 ]]"
  108. - require:
  109. - pkg: linux_auth_pam_packages
  110. {%- endif %}
  111. {%- elif grains.os_family == 'RedHat' %}
  112. {%- if auth.get('mkhomedir', {}).get('enabled', False) %}
  113. linux_auth_config_enable_mkhomedir:
  114. cmd.run:
  115. - name: "authconfig --enablemkhomedir --update"
  116. - require:
  117. {%- if auth.get('ldap', {}).get('enabled', False) %}
  118. - pkg: linux_auth_ldap_packages
  119. {%- endif %}
  120. {%- else %}
  121. linux_auth_config_disable_mkhomedir:
  122. cmd.run:
  123. - name: "authconfig --disablemkhomedir --update"
  124. - require:
  125. - pkg: linux_auth_ldap_packages
  126. {%- endif %}
  127. {%- if auth.get('ldap', {}).get('enabled', False) %}
  128. linux_auth_config_enable_ldap:
  129. cmd.run:
  130. - name: "authconfig --enableldap --enableldapauth --update"
  131. - require:
  132. {%- if auth.get('ldap', {}).get('enabled', False) %}
  133. - pkg: linux_auth_ldap_packages
  134. {%- endif %}
  135. {%- else %}
  136. linux_auth_config_disable_ldap:
  137. cmd.run:
  138. - name: "authconfig --disableldap --disableldapauth --update"
  139. - require:
  140. - pkg: linux_auth_ldap_packages
  141. {%- endif %}
  142. {%- endif %}
  143. {%- if auth.get('ldap', {}).get('enabled', False) %}
  144. linux_auth_nsswitch_config_file:
  145. file.managed:
  146. - name: /etc/nsswitch.conf
  147. - source: salt://linux/files/nsswitch.conf
  148. - template: jinja
  149. - mode: 644
  150. - require:
  151. - pkg: linux_auth_ldap_packages
  152. - watch_in:
  153. - service: linux_auth_nslcd_service
  154. linux_auth_ldap_packages:
  155. pkg.installed:
  156. - pkgs: {{ ldap.pkgs }}
  157. linux_auth_nslcd_config_file:
  158. file.managed:
  159. - name: /etc/nslcd.conf
  160. - source: salt://linux/files/nslcd.conf
  161. - template: jinja
  162. - mode: 600
  163. - require:
  164. - pkg: linux_auth_ldap_packages
  165. - watch_in:
  166. - service: linux_auth_nslcd_service
  167. linux_auth_nslcd_service:
  168. service.running:
  169. - enable: true
  170. - name: nslcd
  171. {%- endif %}
  172. {%- endif %}