|
|
|
|
|
|
|
|
{% set used_user_files = [] %} |
|
|
{% set used_user_files = [] %} |
|
|
{% set used_polkit = [] %} |
|
|
{% set used_polkit = [] %} |
|
|
|
|
|
|
|
|
|
|
|
{% for group, setting in salt['pillar.get']('groups', {}).items() %} |
|
|
|
|
|
{% if setting.absent is defined and setting.absent or setting.get('state', "present") == 'absent' %} |
|
|
|
|
|
users_group_absent_{{ group }}: |
|
|
|
|
|
group.absent: |
|
|
|
|
|
- name: {{ group }} |
|
|
|
|
|
{% else %} |
|
|
|
|
|
users_group_present_{{ group }}: |
|
|
|
|
|
group.present: |
|
|
|
|
|
- name: {{ group }} |
|
|
|
|
|
- gid: {{ setting.get('gid', "null") }} |
|
|
|
|
|
- system: {{ setting.get('system',"False") }} |
|
|
|
|
|
- members: {{ setting.get('members')|json }} |
|
|
|
|
|
- addusers: {{ setting.get('addusers')|json }} |
|
|
|
|
|
- delusers: {{ setting.get('delusers')|json }} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
{% endfor %} |
|
|
|
|
|
|
|
|
{%- for name, user in pillar.get('users', {}).items() |
|
|
{%- for name, user in pillar.get('users', {}).items() |
|
|
if user.absent is not defined or not user.absent %} |
|
|
if user.absent is not defined or not user.absent %} |
|
|
{%- if user == None -%} |
|
|
{%- if user == None -%} |
|
|
{%- set user = {} -%} |
|
|
{%- set user = {} -%} |
|
|
{%- endif -%} |
|
|
{%- endif -%} |
|
|
|
|
|
{%- if 'sudoonly' in user and user['sudoonly'] %} |
|
|
|
|
|
{%- set _dummy=user.update({'sudouser': True}) %} |
|
|
|
|
|
{%- endif %} |
|
|
{%- if 'sudouser' in user and user['sudouser'] %} |
|
|
{%- if 'sudouser' in user and user['sudouser'] %} |
|
|
{%- do used_sudo.append(1) %} |
|
|
{%- do used_sudo.append(1) %} |
|
|
{%- endif %} |
|
|
{%- endif %} |
|
|
|
|
|
|
|
|
{%- endif -%} |
|
|
{%- endif -%} |
|
|
{%- set current = salt.user.info(name) -%} |
|
|
{%- set current = salt.user.info(name) -%} |
|
|
{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%} |
|
|
{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%} |
|
|
|
|
|
{%- set createhome = user.get('createhome') -%} |
|
|
|
|
|
|
|
|
{%- if 'prime_group' in user and 'name' in user['prime_group'] %} |
|
|
{%- if 'prime_group' in user and 'name' in user['prime_group'] %} |
|
|
{%- set user_group = user.prime_group.name -%} |
|
|
{%- set user_group = user.prime_group.name -%} |
|
|
|
|
|
|
|
|
{%- set user_group = name -%} |
|
|
{%- set user_group = name -%} |
|
|
{%- endif %} |
|
|
{%- endif %} |
|
|
|
|
|
|
|
|
|
|
|
{%- if not ( 'sudoonly' in user and user['sudoonly'] ) %} |
|
|
{% for group in user.get('groups', []) %} |
|
|
{% for group in user.get('groups', []) %} |
|
|
users_{{ name }}_{{ group }}_group: |
|
|
users_{{ name }}_{{ group }}_group: |
|
|
group.present: |
|
|
group.present: |
|
|
|
|
|
|
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
|
|
|
|
|
|
|
|
|
{# in case home subfolder doesn't exist, create it before the user exists #} |
|
|
|
|
|
{% if createhome -%} |
|
|
|
|
|
users_{{ name }}_user_prereq: |
|
|
|
|
|
file.directory: |
|
|
|
|
|
- name: {{ salt['file.dirname'](home) }} |
|
|
|
|
|
- makedirs: True |
|
|
|
|
|
- prereq: |
|
|
|
|
|
- user: users_{{ name }}_user |
|
|
|
|
|
{%- endif %} |
|
|
|
|
|
|
|
|
users_{{ name }}_user: |
|
|
users_{{ name }}_user: |
|
|
{% if user.get('createhome', True) %} |
|
|
|
|
|
|
|
|
{% if createhome -%} |
|
|
file.directory: |
|
|
file.directory: |
|
|
- name: {{ home }} |
|
|
- name: {{ home }} |
|
|
- user: {{ user.get('homedir_owner', name) }} |
|
|
- user: {{ user.get('homedir_owner', name) }} |
|
|
- group: {{ user.get('homedir_group', user_group) }} |
|
|
- group: {{ user.get('homedir_group', user_group) }} |
|
|
- mode: {{ user.get('user_dir_mode', '0750') }} |
|
|
- mode: {{ user.get('user_dir_mode', '0750') }} |
|
|
|
|
|
- makedirs: True |
|
|
- require: |
|
|
- require: |
|
|
- user: users_{{ name }}_user |
|
|
- user: users_{{ name }}_user |
|
|
- group: {{ user_group }} |
|
|
- group: {{ user_group }} |
|
|
|
|
|
|
|
|
- workphone: {{ user['workphone'] }} |
|
|
- workphone: {{ user['workphone'] }} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% if 'homephone' in user %} |
|
|
{% if 'homephone' in user %} |
|
|
- homephone: {{ user['workphone'] }} |
|
|
|
|
|
|
|
|
- homephone: {{ user['homephone'] }} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% if not user.get('createhome', True) %} |
|
|
|
|
|
- createhome: False |
|
|
|
|
|
|
|
|
- createhome: {{ createhome }} |
|
|
|
|
|
{% if not user.get('unique', True) %} |
|
|
|
|
|
- unique: False |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
{%- if grains['saltversioninfo'] >= [2018, 3, 1] %} |
|
|
|
|
|
- allow_gid_change: {{ users.allow_gid_change if 'allow_gid_change' not in user else user['allow_gid_change'] }} |
|
|
|
|
|
{%- endif %} |
|
|
{% if 'expire' in user -%} |
|
|
{% if 'expire' in user -%} |
|
|
{% if grains['kernel'].endswith('BSD') and |
|
|
{% if grains['kernel'].endswith('BSD') and |
|
|
user['expire'] < 157766400 %} |
|
|
user['expire'] < 157766400 %} |
|
|
|
|
|
|
|
|
- expire: {{ user['expire'] }} |
|
|
- expire: {{ user['expire'] }} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% endif -%} |
|
|
{% endif -%} |
|
|
|
|
|
{% if 'mindays' in user %} |
|
|
|
|
|
- mindays: {{ user.get('mindays', None) }} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
{% if 'maxdays' in user %} |
|
|
|
|
|
- maxdays: {{ user.get('maxdays', None) }} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
{% if 'inactdays' in user %} |
|
|
|
|
|
- inactdays: {{ user.get('inactdays', None) }} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
{% if 'warndays' in user %} |
|
|
|
|
|
- warndays: {{ user.get('warndays', None) }} |
|
|
|
|
|
{% endif %} |
|
|
- remove_groups: {{ user.get('remove_groups', 'False') }} |
|
|
- remove_groups: {{ user.get('remove_groups', 'False') }} |
|
|
- groups: |
|
|
- groups: |
|
|
- {{ user_group }} |
|
|
- {{ user_group }} |
|
|
|
|
|
|
|
|
- group: {{ user_group }} |
|
|
- group: {{ user_group }} |
|
|
- makedirs: True |
|
|
- makedirs: True |
|
|
- mode: 700 |
|
|
- mode: 700 |
|
|
|
|
|
- dir_mode: 700 |
|
|
- require: |
|
|
- require: |
|
|
- user: {{ name }} |
|
|
- user: {{ name }} |
|
|
- group: {{ user_group }} |
|
|
- group: {{ user_group }} |
|
|
|
|
|
|
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
{% if 'ssh_keys' in user %} |
|
|
{% if 'ssh_keys' in user %} |
|
|
{% set key_type = 'id_' + user.get('ssh_key_type', 'rsa') %} |
|
|
|
|
|
users_user_{{ name }}_private_key: |
|
|
|
|
|
|
|
|
{% for _key in user.ssh_keys.keys() %} |
|
|
|
|
|
{% if _key == 'privkey' %} |
|
|
|
|
|
{% set key_name = 'id_' + user.get('ssh_key_type', 'rsa') %} |
|
|
|
|
|
{% elif _key == 'pubkey' %} |
|
|
|
|
|
{% set key_name = 'id_' + user.get('ssh_key_type', 'rsa') + '.pub' %} |
|
|
|
|
|
{% else %} |
|
|
|
|
|
{% set key_name = _key %} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
users_{{ name }}_{{ key_name }}_key: |
|
|
file.managed: |
|
|
file.managed: |
|
|
- name: {{ home }}/.ssh/{{ key_type }} |
|
|
|
|
|
- user: {{ name }} |
|
|
|
|
|
- group: {{ user_group }} |
|
|
|
|
|
- mode: 600 |
|
|
|
|
|
- show_diff: False |
|
|
|
|
|
- contents_pillar: users:{{ name }}:ssh_keys:privkey |
|
|
|
|
|
- require: |
|
|
|
|
|
- user: users_{{ name }}_user |
|
|
|
|
|
{% for group in user.get('groups', []) %} |
|
|
|
|
|
- group: users_{{ name }}_{{ group }}_group |
|
|
|
|
|
{% endfor %} |
|
|
|
|
|
users_user_{{ name }}_public_key: |
|
|
|
|
|
file.managed: |
|
|
|
|
|
- name: {{ home }}/.ssh/{{ key_type }}.pub |
|
|
|
|
|
|
|
|
- name: {{ home }}/.ssh/{{ key_name }} |
|
|
- user: {{ name }} |
|
|
- user: {{ name }} |
|
|
- group: {{ user_group }} |
|
|
- group: {{ user_group }} |
|
|
|
|
|
{% if key_name.endswith(".pub") %} |
|
|
- mode: 644 |
|
|
- mode: 644 |
|
|
|
|
|
{% else %} |
|
|
|
|
|
- mode: 600 |
|
|
|
|
|
{% endif %} |
|
|
- show_diff: False |
|
|
- show_diff: False |
|
|
- contents_pillar: users:{{ name }}:ssh_keys:pubkey |
|
|
|
|
|
|
|
|
{%- set key_value = salt['pillar.get']('users:'+name+':ssh_keys:'+_key) %} |
|
|
|
|
|
{%- if 'salt://' in key_value[:7] %} |
|
|
|
|
|
- source: {{ key_value }} |
|
|
|
|
|
{%- else %} |
|
|
|
|
|
- contents_pillar: users:{{ name }}:ssh_keys:{{ _key }} |
|
|
|
|
|
{%- endif %} |
|
|
- require: |
|
|
- require: |
|
|
- user: users_{{ name }}_user |
|
|
- user: users_{{ name }}_user |
|
|
{% for group in user.get('groups', []) %} |
|
|
{% for group in user.get('groups', []) %} |
|
|
- group: users_{{ name }}_{{ group }}_group |
|
|
- group: users_{{ name }}_{{ group }}_group |
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
|
|
|
{% endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{% if 'ssh_auth_file' in user or 'ssh_auth_pillar' in user %} |
|
|
{% if 'ssh_auth_file' in user or 'ssh_auth_pillar' in user %} |
|
|
users_authorized_keys_{{ name }}: |
|
|
users_authorized_keys_{{ name }}: |
|
|
file.managed: |
|
|
file.managed: |
|
|
|
|
|
|
|
|
{{ auth }} |
|
|
{{ auth }} |
|
|
{% endfor -%} |
|
|
{% endfor -%} |
|
|
{% else %} |
|
|
{% else %} |
|
|
|
|
|
- contents: | |
|
|
{%- for key_name, pillar_name in user['ssh_auth_pillar'].items() %} |
|
|
{%- for key_name, pillar_name in user['ssh_auth_pillar'].items() %} |
|
|
- contents_pillar: {{ pillar_name }}:{{ key_name }}:pubkey |
|
|
|
|
|
|
|
|
{{ salt['pillar.get'](pillar_name + ':' + key_name + ':pubkey', '') }} |
|
|
{%- endfor %} |
|
|
{%- endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
- user: {{ name }} |
|
|
- user: {{ name }} |
|
|
- source: {{ pubkey_file }} |
|
|
- source: {{ pubkey_file }} |
|
|
- require: |
|
|
- require: |
|
|
|
|
|
{% if createhome -%} |
|
|
|
|
|
- file: users_{{ name }}_user |
|
|
|
|
|
{% endif -%} |
|
|
|
|
|
- user: users_{{ name }}_user |
|
|
|
|
|
{% endfor %} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
|
|
|
|
|
|
{% if 'ssh_auth_sources.absent' in user %} |
|
|
|
|
|
{% for pubkey_file in user['ssh_auth_sources.absent'] %} |
|
|
|
|
|
users_ssh_auth_source_delete_{{ name }}_{{ loop.index0 }}: |
|
|
|
|
|
ssh_auth.absent: |
|
|
|
|
|
- user: {{ name }} |
|
|
|
|
|
- source: {{ pubkey_file }} |
|
|
|
|
|
- require: |
|
|
|
|
|
{% if createhome -%} |
|
|
- file: users_{{ name }}_user |
|
|
- file: users_{{ name }}_user |
|
|
|
|
|
{% endif -%} |
|
|
- user: users_{{ name }}_user |
|
|
- user: users_{{ name }}_user |
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
- user: {{ name }} |
|
|
- user: {{ name }} |
|
|
- name: {{ auth }} |
|
|
- name: {{ auth }} |
|
|
- require: |
|
|
- require: |
|
|
|
|
|
{% if createhome -%} |
|
|
- file: users_{{ name }}_user |
|
|
- file: users_{{ name }}_user |
|
|
|
|
|
{% endif -%} |
|
|
- user: users_{{ name }}_user |
|
|
- user: users_{{ name }}_user |
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
{% if 'enc' in host %} |
|
|
{% if 'enc' in host %} |
|
|
- enc: {{ host['enc'] }} |
|
|
- enc: {{ host['enc'] }} |
|
|
{% endif -%} |
|
|
{% endif -%} |
|
|
{% if 'hash_hostname' in host %} |
|
|
|
|
|
- hash_hostname: {{ host['hash_hostname'] }} |
|
|
|
|
|
|
|
|
{% if 'hash_known_hosts' in host %} |
|
|
|
|
|
- hash_known_hosts: {{ host['hash_known_hosts'] }} |
|
|
|
|
|
{% endif -%} |
|
|
|
|
|
{% if 'timeout' in host %} |
|
|
|
|
|
- timeout: {{ host['timeout'] }} |
|
|
|
|
|
{% endif -%} |
|
|
|
|
|
{% if 'fingerprint_hash_type' in host %} |
|
|
|
|
|
- fingerprint_hash_type: {{ host['fingerprint_hash_type'] }} |
|
|
{% endif -%} |
|
|
{% endif -%} |
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
- name: {{ host }} |
|
|
- name: {{ host }} |
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
|
|
|
|
|
|
{% set sudoers_d_filename = name|replace('.','_') %} |
|
|
{% if 'sudouser' in user and user['sudouser'] %} |
|
|
{% if 'sudouser' in user and user['sudouser'] %} |
|
|
|
|
|
|
|
|
users_sudoer-{{ name }}: |
|
|
users_sudoer-{{ name }}: |
|
|
file.managed: |
|
|
file.managed: |
|
|
- replace: False |
|
|
- replace: False |
|
|
- name: {{ users.sudoers_dir }}/{{ name }} |
|
|
|
|
|
|
|
|
- name: {{ users.sudoers_dir }}/{{ sudoers_d_filename }} |
|
|
- user: root |
|
|
- user: root |
|
|
- group: {{ users.root_group }} |
|
|
- group: {{ users.root_group }} |
|
|
- mode: '0440' |
|
|
- mode: '0440' |
|
|
|
|
|
|
|
|
users_{{ users.sudoers_dir }}/{{ name }}: |
|
|
users_{{ users.sudoers_dir }}/{{ name }}: |
|
|
file.managed: |
|
|
file.managed: |
|
|
- replace: True |
|
|
- replace: True |
|
|
- name: {{ users.sudoers_dir }}/{{ name }} |
|
|
|
|
|
|
|
|
- name: {{ users.sudoers_dir }}/{{ sudoers_d_filename }} |
|
|
- contents: | |
|
|
- contents: | |
|
|
{%- if 'sudo_defaults' in user %} |
|
|
{%- if 'sudo_defaults' in user %} |
|
|
{%- for entry in user['sudo_defaults'] %} |
|
|
{%- for entry in user['sudo_defaults'] %} |
|
|
|
|
|
|
|
|
- file: users_sudoer-defaults |
|
|
- file: users_sudoer-defaults |
|
|
- file: users_sudoer-{{ name }} |
|
|
- file: users_sudoer-{{ name }} |
|
|
cmd.wait: |
|
|
cmd.wait: |
|
|
- name: visudo -cf {{ users.sudoers_dir }}/{{ name }} || ( rm -rvf {{ users.sudoers_dir }}/{{ name }}; exit 1 ) |
|
|
|
|
|
|
|
|
- name: visudo -cf {{ users.sudoers_dir }}/{{ sudoers_d_filename }} || ( rm -rvf {{ users.sudoers_dir }}/{{ sudoers_d_filename }}; exit 1 ) |
|
|
- watch: |
|
|
- watch: |
|
|
- file: {{ users.sudoers_dir }}/{{ name }} |
|
|
|
|
|
|
|
|
- file: {{ users.sudoers_dir }}/{{ sudoers_d_filename }} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
{% else %} |
|
|
{% else %} |
|
|
users_{{ users.sudoers_dir }}/{{ name }}: |
|
|
|
|
|
|
|
|
users_{{ users.sudoers_dir }}/{{ sudoers_d_filename }}: |
|
|
file.absent: |
|
|
file.absent: |
|
|
- name: {{ users.sudoers_dir }}/{{ name }} |
|
|
|
|
|
|
|
|
- name: {{ users.sudoers_dir }}/{{ sudoers_d_filename }} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
{%- if 'google_auth' in user %} |
|
|
{%- if 'google_auth' in user %} |
|
|
|
|
|
|
|
|
{%- endfor %} |
|
|
{%- endfor %} |
|
|
{%- endif %} |
|
|
{%- endif %} |
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
# if not salt['cmd.has_exec']('git') |
|
|
|
|
|
# fails even if git is installed |
|
|
|
|
|
# |
|
|
|
|
|
# this doesn't work (Salt bug), therefore need to run state.apply twice |
|
|
# this doesn't work (Salt bug), therefore need to run state.apply twice |
|
|
#include: |
|
|
#include: |
|
|
# - users |
|
|
# - users |
|
|
|
|
|
|
|
|
# - require_in: |
|
|
# - require_in: |
|
|
# - sls: users |
|
|
# - sls: users |
|
|
# |
|
|
# |
|
|
|
|
|
{% if salt['cmd.has_exec']('git') %} |
|
|
|
|
|
|
|
|
{% if 'gitconfig' in user %} |
|
|
{% if 'gitconfig' in user %} |
|
|
{% for key, value in user['gitconfig'].items() %} |
|
|
{% for key, value in user['gitconfig'].items() %} |
|
|
users_{{ name }}_user_gitconfig_{{ loop.index0 }}: |
|
|
users_{{ name }}_user_gitconfig_{{ loop.index0 }}: |
|
|
{% if grains['saltversioninfo'] >= (2015, 8, 0, 0) %} |
|
|
|
|
|
|
|
|
{% if grains['saltversioninfo'] >= [2015, 8, 0, 0] %} |
|
|
git.config_set: |
|
|
git.config_set: |
|
|
{% else %} |
|
|
{% else %} |
|
|
git.config: |
|
|
git.config: |
|
|
|
|
|
|
|
|
- name: {{ key }} |
|
|
- name: {{ key }} |
|
|
- value: "{{ value }}" |
|
|
- value: "{{ value }}" |
|
|
- user: {{ name }} |
|
|
- user: {{ name }} |
|
|
{% if grains['saltversioninfo'] >= (2015, 8, 0, 0) %} |
|
|
|
|
|
|
|
|
{% if grains['saltversioninfo'] >= [2015, 8, 0, 0] %} |
|
|
- global: True |
|
|
- global: True |
|
|
{% else %} |
|
|
{% else %} |
|
|
- is_global: True |
|
|
- is_global: True |
|
|
|
|
|
|
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
{% endif %} |
|
|
{% endif %} |
|
|
|
|
|
|
|
|
|
|
|
{% if 'gitconfig.absent' in user and grains['saltversioninfo'] >= [2015, 8, 0, 0] %} |
|
|
|
|
|
{% for key in user.get('gitconfig.absent') %} |
|
|
|
|
|
users_{{ name }}_user_gitconfig_absent_{{ key }}: |
|
|
|
|
|
git.config_unset: |
|
|
|
|
|
- name: '{{ key }}' |
|
|
|
|
|
- user: {{ name }} |
|
|
|
|
|
- global: True |
|
|
|
|
|
- all: True |
|
|
|
|
|
{% endfor %} |
|
|
|
|
|
{% endif %} |
|
|
|
|
|
|
|
|
|
|
|
{% endif %} |
|
|
|
|
|
|
|
|
{% endfor %} |
|
|
{% endfor %} |
|
|
|
|
|
|
|
|
|
|
|
|