Saltstack Official Users 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.

102 lines
3.2KB

  1. # vim: sts=2 ts=2 sw=2 et ai
  2. {%- from "users/map.jinja" import users with context %}
  3. {%- if not grains['os_family'] in ['Suse'] %}
  4. {%- if salt['grains.get']('osfinger', '') in ['Amazon Linux-2'] %}
  5. users_epel_repo:
  6. pkgrepo.managed:
  7. - name: epel
  8. - humanname: Extra Packages for Enterprise Linux 7 - $basearch
  9. - mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
  10. - enabled: 1
  11. - gpgcheck: 1
  12. - gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
  13. - failovermethod: priority
  14. - require_in:
  15. - pkg: users_googleauth-package
  16. {%- endif %}
  17. users_googleauth-package:
  18. pkg.installed:
  19. - name: {{ users.googleauth_package }}
  20. - require:
  21. - file: {{ users.googleauth_dir }}
  22. users_{{ users.googleauth_dir }}:
  23. file.directory:
  24. - name: {{ users.googleauth_dir }}
  25. - user: root
  26. - group: {{ users.root_group }}
  27. - mode: '0700'
  28. {%- if grains['os_family'] == 'RedHat' and "selinux" in grains and grains.selinux.enabled %}
  29. policycoreutils-package:
  30. pkg.installed:
  31. - pkgs:
  32. - policycoreutils
  33. {%- if grains['osmajorrelease']|int <= 7 %}
  34. - policycoreutils-python
  35. {%- else %}
  36. - policycoreutils-python-utils
  37. {%- endif %}
  38. users_googleauth_selinux_present:
  39. selinux.fcontext_policy_present:
  40. - name: "{{ users.googleauth_dir }}(/.*)?"
  41. - filetype: 'a'
  42. - sel_user: unconfined_u
  43. - sel_type: ssh_home_t
  44. - sel_level: s0
  45. - require:
  46. - pkg: policycoreutils-package
  47. {%- endif %}
  48. {%- for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %}
  49. {%- if 'google_auth' in user %}
  50. {%- for svc in user['google_auth'] %}
  51. {%- if user.get('google_2fa', True) %}
  52. {%- set repl = '{0} {1} {2} {3} {4}{5}/{6}_{7} {8}'.format(
  53. 'auth',
  54. '[success=done new_authtok_reqd=done default=die]',
  55. 'pam_google_authenticator.so',
  56. 'user=root',
  57. 'secret=',
  58. users.googleauth_dir,
  59. '${USER}',
  60. svc,
  61. 'echo_verification_code',
  62. ) %}
  63. users_googleauth-pam-{{ svc }}-{{ name }}:
  64. file.replace:
  65. - name: /etc/pam.d/{{ svc }}
  66. {%- if grains['os_family'] == 'RedHat' %}
  67. - pattern: '^(auth[ \t]*substack[ \t]*password-auth)'
  68. {%- else %}
  69. - pattern: '^(@include[ \t]*common-auth)'
  70. {%- endif %}
  71. - repl: '{{ repl }}\n\1'
  72. - unless: grep pam_google_authenticator.so /etc/pam.d/{{ svc }}
  73. - backup: .bak
  74. {%- endif %}
  75. {%- endfor %}
  76. {%- endif %}
  77. {%- endfor %}
  78. {%- if grains['os_family'] == 'RedHat' and "selinux" in grains and grains.selinux.enabled %}
  79. users_googleauth_selinux_applied:
  80. selinux.fcontext_policy_applied:
  81. - name: {{ users.googleauth_dir }}
  82. {%- endif %}
  83. sshd:
  84. service.running:
  85. - watch:
  86. - file: /etc/ssh/sshd_config
  87. sshd_config:
  88. file.replace:
  89. - name: /etc/ssh/sshd_config
  90. - pattern: '^(ChallengeResponseAuthentication|KbdInteractiveAuthentication).*'
  91. - repl: '\1 yes'
  92. {%- endif %}