Saltstack Official Linux Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

197 lines
5.7KB

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