2015-07-27 19:50:49 +02:00
|
|
|
# vim: sts=2 ts=2 sw=2 et ai
|
|
|
|
{% from "users/map.jinja" import users with context %}
|
|
|
|
{% set used_sudo = [] %}
|
|
|
|
{% set used_googleauth = [] %}
|
2015-08-21 22:42:25 +02:00
|
|
|
{% set used_user_files = [] %}
|
2015-07-27 19:50:49 +02:00
|
|
|
|
2018-08-24 15:22:00 +02:00
|
|
|
{% for group, setting in salt['pillar.get']('groups', {}).items() %}
|
2017-04-18 19:57:18 +02:00
|
|
|
users_group_{{ setting.get('state', "present") }}_{{ group }}:
|
|
|
|
group.{{ setting.get('state', "present") }}:
|
|
|
|
- name: {{ group }}
|
|
|
|
{%- if setting.get('gid') %}
|
|
|
|
- gid: {{setting.get('gid') }}
|
|
|
|
{%- endif %}
|
|
|
|
- system: {{ setting.get('system',"False") }}
|
|
|
|
{% endfor %}
|
|
|
|
|
2015-08-18 16:27:25 +02:00
|
|
|
{%- for name, user in pillar.get('users', {}).items()
|
|
|
|
if user.absent is not defined or not user.absent %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- if user == None -%}
|
|
|
|
{%- set user = {} -%}
|
|
|
|
{%- endif -%}
|
2017-08-07 00:14:53 +02:00
|
|
|
{%- if 'sudoonly' in user and user['sudoonly'] %}
|
|
|
|
{%- set _dummy=user.update({'sudouser': True}) %}
|
|
|
|
{%- endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- if 'sudouser' in user and user['sudouser'] %}
|
|
|
|
{%- do used_sudo.append(1) %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'google_auth' in user %}
|
|
|
|
{%- do used_googleauth.append(1) %}
|
|
|
|
{%- endif %}
|
2015-08-21 22:52:36 +02:00
|
|
|
{%- if salt['pillar.get']('users:' ~ name ~ ':user_files:enabled', False) %}
|
2015-08-21 22:42:25 +02:00
|
|
|
{%- do used_user_files.append(1) %}
|
|
|
|
{%- endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- endfor %}
|
|
|
|
|
2015-08-21 22:42:25 +02:00
|
|
|
{%- if used_sudo or used_googleauth or used_user_files %}
|
2015-01-14 18:25:17 +01:00
|
|
|
include:
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- if used_sudo %}
|
2015-01-14 18:25:17 +01:00
|
|
|
- users.sudo
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- endif %}
|
|
|
|
{%- if used_googleauth %}
|
2015-01-14 18:25:17 +01:00
|
|
|
- users.googleauth
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- endif %}
|
2015-08-21 22:42:25 +02:00
|
|
|
{%- if used_user_files %}
|
|
|
|
- users.user_files
|
|
|
|
{%- endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- endif %}
|
|
|
|
|
2015-08-18 16:27:25 +02:00
|
|
|
{% for name, user in pillar.get('users', {}).items()
|
|
|
|
if user.absent is not defined or not user.absent %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- if user == None -%}
|
|
|
|
{%- set user = {} -%}
|
|
|
|
{%- endif -%}
|
2016-06-23 21:19:17 +02:00
|
|
|
{%- set current = salt.user.info(name) -%}
|
|
|
|
{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%}
|
2015-07-27 19:50:49 +02:00
|
|
|
|
|
|
|
{%- if 'prime_group' in user and 'name' in user['prime_group'] %}
|
|
|
|
{%- set user_group = user.prime_group.name -%}
|
|
|
|
{%- else -%}
|
|
|
|
{%- set user_group = name -%}
|
|
|
|
{%- endif %}
|
|
|
|
|
2017-08-07 00:14:53 +02:00
|
|
|
{%- if not ( 'sudoonly' in user and user['sudoonly'] ) %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% for group in user.get('groups', []) %}
|
|
|
|
users_{{ name }}_{{ group }}_group:
|
2015-08-13 23:57:09 +02:00
|
|
|
group.present:
|
2015-07-27 19:50:49 +02:00
|
|
|
- name: {{ group }}
|
2015-08-13 23:57:09 +02:00
|
|
|
{% if group == 'sudo' %}
|
|
|
|
- system: True
|
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endfor %}
|
|
|
|
|
2018-07-10 15:51:10 +02:00
|
|
|
{# in case home subfolder doesn't exist, create it before the user exists #}
|
|
|
|
{% if user.get('createhome', True) %}
|
|
|
|
users_{{ name }}_user_prereq:
|
|
|
|
file.directory:
|
2018-07-17 18:03:04 +02:00
|
|
|
- name: {{ salt['file.dirname'](home) }}
|
2018-07-10 15:51:10 +02:00
|
|
|
- makedirs: True
|
|
|
|
- prereq:
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{%- endif %}
|
|
|
|
|
2015-07-27 19:50:49 +02:00
|
|
|
users_{{ name }}_user:
|
|
|
|
{% if user.get('createhome', True) %}
|
|
|
|
file.directory:
|
|
|
|
- name: {{ home }}
|
2016-06-13 17:22:24 +02:00
|
|
|
- user: {{ user.get('homedir_owner', name) }}
|
|
|
|
- group: {{ user.get('homedir_group', user_group) }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- mode: {{ user.get('user_dir_mode', '0750') }}
|
2018-03-23 13:42:11 +01:00
|
|
|
- makedirs: True
|
2015-07-27 19:50:49 +02:00
|
|
|
- require:
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
- group: {{ user_group }}
|
|
|
|
{%- endif %}
|
|
|
|
group.present:
|
|
|
|
- name: {{ user_group }}
|
|
|
|
{%- if 'prime_group' in user and 'gid' in user['prime_group'] %}
|
|
|
|
- gid: {{ user['prime_group']['gid'] }}
|
|
|
|
{%- elif 'uid' in user %}
|
|
|
|
- gid: {{ user['uid'] }}
|
|
|
|
{%- endif %}
|
2016-06-22 12:08:39 +02:00
|
|
|
{% if 'system' in user and user['system'] %}
|
|
|
|
- system: True
|
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
user.present:
|
|
|
|
- name: {{ name }}
|
2017-04-25 19:29:00 +02:00
|
|
|
{% if user.get('createhome', True) -%}
|
2015-07-27 19:50:49 +02:00
|
|
|
- home: {{ home }}
|
2017-04-25 19:29:00 +02:00
|
|
|
{% endif -%}
|
2016-06-23 21:19:17 +02:00
|
|
|
- shell: {{ user.get('shell', current.get('shell', users.get('shell', '/bin/bash'))) }}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if 'uid' in user -%}
|
|
|
|
- uid: {{ user['uid'] }}
|
|
|
|
{% endif -%}
|
2015-09-27 17:41:51 +02:00
|
|
|
{% if 'password' in user -%}
|
2015-07-27 19:50:49 +02:00
|
|
|
- password: '{{ user['password'] }}'
|
|
|
|
{% endif -%}
|
2015-09-27 18:59:09 +02:00
|
|
|
{% if user.get('empty_password') -%}
|
|
|
|
- empty_password: {{ user.get('empty_password') }}
|
2015-09-27 16:20:45 +02:00
|
|
|
{% endif -%}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if 'enforce_password' in user -%}
|
|
|
|
- enforce_password: {{ user['enforce_password'] }}
|
|
|
|
{% endif -%}
|
2016-12-01 16:59:51 +01:00
|
|
|
{% if 'hash_password' in user -%}
|
|
|
|
- hash_password: {{ user['hash_password'] }}
|
|
|
|
{% endif -%}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if user.get('system', False) -%}
|
|
|
|
- system: True
|
|
|
|
{% endif -%}
|
|
|
|
{% if 'prime_group' in user and 'gid' in user['prime_group'] -%}
|
|
|
|
- gid: {{ user['prime_group']['gid'] }}
|
2017-02-02 22:03:36 +01:00
|
|
|
{% elif 'prime_group' in user and 'name' in user['prime_group'] %}
|
|
|
|
- gid: {{ user['prime_group']['name'] }}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% else -%}
|
|
|
|
- gid_from_name: True
|
|
|
|
{% endif -%}
|
|
|
|
{% if 'fullname' in user %}
|
|
|
|
- fullname: {{ user['fullname'] }}
|
|
|
|
{% endif -%}
|
2015-09-12 23:22:42 +02:00
|
|
|
{% if 'roomnumber' in user %}
|
|
|
|
- roomnumber: {{ user['roomnumber'] }}
|
|
|
|
{% endif %}
|
|
|
|
{% if 'workphone' in user %}
|
|
|
|
- workphone: {{ user['workphone'] }}
|
|
|
|
{% endif %}
|
|
|
|
{% if 'homephone' in user %}
|
2017-12-03 14:46:52 +01:00
|
|
|
- homephone: {{ user['homephone'] }}
|
2015-09-12 23:22:42 +02:00
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if not user.get('createhome', True) %}
|
|
|
|
- createhome: False
|
|
|
|
{% endif %}
|
2018-01-18 18:45:32 +01:00
|
|
|
{% if not user.get('unique', True) %}
|
|
|
|
- unique: False
|
|
|
|
{% endif %}
|
2018-10-03 17:35:06 +02:00
|
|
|
{%- 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 %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if 'expire' in user -%}
|
2015-11-18 16:13:55 +01:00
|
|
|
{% if grains['kernel'].endswith('BSD') and
|
|
|
|
user['expire'] < 157766400 %}
|
|
|
|
{# 157762800s since epoch equals 01 Jan 1975 00:00:00 UTC #}
|
|
|
|
- expire: {{ user['expire'] * 86400 }}
|
|
|
|
{% elif grains['kernel'] == 'Linux' and
|
|
|
|
user['expire'] > 84006 %}
|
|
|
|
{# 2932896 days since epoch equals 9999-12-31 #}
|
|
|
|
- expire: {{ (user['expire'] / 86400) | int}}
|
|
|
|
{% else %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- expire: {{ user['expire'] }}
|
2015-11-18 16:13:55 +01:00
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endif -%}
|
2019-01-04 18:56:49 +01:00
|
|
|
{% 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 %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- remove_groups: {{ user.get('remove_groups', 'False') }}
|
|
|
|
- groups:
|
|
|
|
- {{ user_group }}
|
|
|
|
{% for group in user.get('groups', []) -%}
|
|
|
|
- {{ group }}
|
|
|
|
{% endfor %}
|
2016-08-05 20:05:12 +02:00
|
|
|
{% if 'optional_groups' in user %}
|
|
|
|
- optional_groups:
|
|
|
|
{% for optional_group in user['optional_groups'] -%}
|
|
|
|
- {{optional_group}}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- require:
|
|
|
|
- group: {{ user_group }}
|
|
|
|
{% for group in user.get('groups', []) -%}
|
|
|
|
- group: {{ group }}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
|
2015-08-18 16:27:25 +02:00
|
|
|
{% if 'ssh_keys' in user or
|
|
|
|
'ssh_auth' in user or
|
|
|
|
'ssh_auth_file' in user or
|
2016-02-02 14:58:39 +01:00
|
|
|
'ssh_auth_pillar' in user or
|
2015-08-18 16:27:25 +02:00
|
|
|
'ssh_auth.absent' in user or
|
|
|
|
'ssh_config' in user %}
|
2015-07-27 19:50:49 +02:00
|
|
|
user_keydir_{{ name }}:
|
|
|
|
file.directory:
|
2016-06-23 21:19:17 +02:00
|
|
|
- name: {{ home }}/.ssh
|
2015-07-27 19:50:49 +02:00
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ user_group }}
|
|
|
|
- makedirs: True
|
|
|
|
- mode: 700
|
2018-11-06 18:04:15 +01:00
|
|
|
- dir_mode: 700
|
2015-07-27 19:50:49 +02:00
|
|
|
- require:
|
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ user_group }}
|
|
|
|
{%- for group in user.get('groups', []) %}
|
|
|
|
- group: {{ group }}
|
|
|
|
{%- endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if 'ssh_keys' in user %}
|
2016-10-04 20:53:01 +02:00
|
|
|
{% 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 %}
|
2017-09-26 14:49:45 +02:00
|
|
|
users_{{ name }}_{{ key_name }}_key:
|
2015-07-27 19:50:49 +02:00
|
|
|
file.managed:
|
2016-10-04 20:53:01 +02:00
|
|
|
- name: {{ home }}/.ssh/{{ key_name }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ user_group }}
|
2017-09-28 08:22:25 +02:00
|
|
|
{% if key_name.endswith(".pub") %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- mode: 644
|
2017-09-28 08:22:25 +02:00
|
|
|
{% else %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- mode: 600
|
2017-09-28 08:22:25 +02:00
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- show_diff: False
|
2018-02-14 07:08:09 +01:00
|
|
|
{%- set key_value = salt['pillar.get']('users:'+name+':ssh_keys:'+_key) %}
|
|
|
|
{%- if 'salt://' in key_value[:7] %}
|
|
|
|
- source: {{ key_value }}
|
|
|
|
{%- else %}
|
2016-10-04 20:53:01 +02:00
|
|
|
- contents_pillar: users:{{ name }}:ssh_keys:{{ _key }}
|
2018-02-14 07:08:09 +01:00
|
|
|
{%- endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- require:
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% for group in user.get('groups', []) %}
|
|
|
|
- group: users_{{ name }}_{{ group }}_group
|
|
|
|
{% endfor %}
|
2016-10-04 20:53:01 +02:00
|
|
|
{% endfor %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endif %}
|
|
|
|
|
2016-10-04 20:53:01 +02:00
|
|
|
|
2015-08-21 12:17:49 +02:00
|
|
|
{% if 'ssh_auth_file' in user or 'ssh_auth_pillar' in user %}
|
2015-07-27 19:50:49 +02:00
|
|
|
users_authorized_keys_{{ name }}:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ home }}/.ssh/authorized_keys
|
|
|
|
- user: {{ name }}
|
2015-12-15 21:21:00 +01:00
|
|
|
- group: {{ user_group }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- mode: 600
|
2015-08-21 12:17:49 +02:00
|
|
|
{% if 'ssh_auth_file' in user %}
|
2015-07-27 19:50:49 +02:00
|
|
|
- contents: |
|
|
|
|
{% for auth in user.ssh_auth_file -%}
|
|
|
|
{{ auth }}
|
|
|
|
{% endfor -%}
|
2015-08-21 12:17:49 +02:00
|
|
|
{% else %}
|
2017-07-09 16:06:17 +02:00
|
|
|
- contents: |
|
2015-12-30 04:27:51 +01:00
|
|
|
{%- for key_name, pillar_name in user['ssh_auth_pillar'].items() %}
|
2017-07-09 16:06:17 +02:00
|
|
|
{{ salt['pillar.get'](pillar_name + ':' + key_name + ':pubkey', '') }}
|
2015-08-21 18:20:07 +02:00
|
|
|
{%- endfor %}
|
2015-08-21 12:17:49 +02:00
|
|
|
{% endif %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if 'ssh_auth' in user %}
|
|
|
|
{% for auth in user['ssh_auth'] %}
|
|
|
|
users_ssh_auth_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_auth.present:
|
|
|
|
- user: {{ name }}
|
|
|
|
- name: {{ auth }}
|
|
|
|
- require:
|
2016-07-01 08:20:20 +02:00
|
|
|
- file: user_keydir_{{ name }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if 'ssh_keys_pillar' in user %}
|
|
|
|
{% for key_name, pillar_name in user['ssh_keys_pillar'].items() %}
|
|
|
|
user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key:
|
|
|
|
file.managed:
|
2016-06-23 21:19:17 +02:00
|
|
|
- name: {{ home }}/.ssh/{{ key_name }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ user_group }}
|
|
|
|
- mode: 600
|
|
|
|
- show_diff: False
|
|
|
|
- contents_pillar: {{ pillar_name }}:{{ key_name }}:privkey
|
|
|
|
- require:
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% for group in user.get('groups', []) %}
|
|
|
|
- group: users_{{ name }}_{{ group }}_group
|
|
|
|
{% endfor %}
|
|
|
|
user_ssh_keys_files_{{ name }}_{{ key_name }}_public_key:
|
|
|
|
file.managed:
|
2016-06-23 21:19:17 +02:00
|
|
|
- name: {{ home }}/.ssh/{{ key_name }}.pub
|
2015-07-27 19:50:49 +02:00
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ user_group }}
|
|
|
|
- mode: 644
|
|
|
|
- show_diff: False
|
|
|
|
- contents_pillar: {{ pillar_name }}:{{ key_name }}:pubkey
|
|
|
|
- require:
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% for group in user.get('groups', []) %}
|
|
|
|
- group: users_{{ name }}_{{ group }}_group
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if 'ssh_auth_sources' in user %}
|
|
|
|
{% for pubkey_file in user['ssh_auth_sources'] %}
|
|
|
|
users_ssh_auth_source_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_auth.present:
|
|
|
|
- user: {{ name }}
|
|
|
|
- source: {{ pubkey_file }}
|
|
|
|
- require:
|
|
|
|
- file: users_{{ name }}_user
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
2017-06-12 13:20:12 +02:00
|
|
|
{% if 'ssh_auth_sources.absent' in user %}
|
|
|
|
{% for pubkey_file in user['ssh_auth_sources.absent'] %}
|
2017-07-07 19:21:48 +02:00
|
|
|
users_ssh_auth_source_delete_{{ name }}_{{ loop.index0 }}:
|
2017-06-12 13:20:12 +02:00
|
|
|
ssh_auth.absent:
|
|
|
|
- user: {{ name }}
|
|
|
|
- source: {{ pubkey_file }}
|
|
|
|
- require:
|
|
|
|
- file: users_{{ name }}_user
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if 'ssh_auth.absent' in user %}
|
|
|
|
{% for auth in user['ssh_auth.absent'] %}
|
|
|
|
users_ssh_auth_delete_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_auth.absent:
|
|
|
|
- user: {{ name }}
|
|
|
|
- name: {{ auth }}
|
|
|
|
- require:
|
|
|
|
- file: users_{{ name }}_user
|
|
|
|
- user: users_{{ name }}_user
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if 'ssh_config' in user %}
|
|
|
|
users_ssh_config_{{ name }}:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ home }}/.ssh/config
|
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ user_group }}
|
|
|
|
- mode: 640
|
|
|
|
- contents: |
|
|
|
|
# Managed by Saltstack
|
|
|
|
# Do Not Edit
|
|
|
|
{% for label, setting in user.ssh_config.items() %}
|
|
|
|
# {{ label }}
|
|
|
|
Host {{ setting.get('hostname') }}
|
|
|
|
{%- for opts in setting.get('options') %}
|
|
|
|
{{ opts }}
|
|
|
|
{%- endfor %}
|
|
|
|
{% endfor -%}
|
|
|
|
{% endif %}
|
|
|
|
|
2015-08-27 16:31:14 +02:00
|
|
|
{% if 'ssh_known_hosts' in user %}
|
|
|
|
{% for hostname, host in user['ssh_known_hosts'].items() %}
|
|
|
|
users_ssh_known_hosts_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_known_hosts.present:
|
|
|
|
- user: {{ name }}
|
|
|
|
- name: {{ hostname }}
|
|
|
|
{% if 'port' in host %}
|
|
|
|
- port: {{ host['port'] }}
|
|
|
|
{% endif -%}
|
|
|
|
{% if 'fingerprint' in host %}
|
|
|
|
- fingerprint: {{ host['fingerprint'] }}
|
|
|
|
{% endif -%}
|
|
|
|
{% if 'key' in host %}
|
|
|
|
- key: {{ host['key'] }}
|
|
|
|
{% endif -%}
|
|
|
|
{% if 'enc' in host %}
|
|
|
|
- enc: {{ host['enc'] }}
|
|
|
|
{% endif -%}
|
2016-12-13 14:58:28 +01:00
|
|
|
{% if 'hash_known_hosts' in host %}
|
|
|
|
- hash_known_hosts: {{ host['hash_known_hosts'] }}
|
2015-09-14 17:18:57 +02:00
|
|
|
{% endif -%}
|
2017-11-17 14:30:00 +01:00
|
|
|
{% if 'timeout' in host %}
|
|
|
|
- timeout: {{ host['timeout'] }}
|
|
|
|
{% endif -%}
|
|
|
|
{% if 'fingerprint_hash_type' in host %}
|
|
|
|
- fingerprint_hash_type: {{ host['fingerprint_hash_type'] }}
|
2015-09-14 17:18:57 +02:00
|
|
|
{% endif -%}
|
2015-08-27 16:31:14 +02:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if 'ssh_known_hosts.absent' in user %}
|
|
|
|
{% for host in user['ssh_known_hosts.absent'] %}
|
|
|
|
users_ssh_known_hosts_delete_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_known_hosts.absent:
|
|
|
|
- user: {{ name }}
|
|
|
|
- name: {{ host }}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2017-08-07 00:14:53 +02:00
|
|
|
{% endif %}
|
2015-08-27 16:31:14 +02:00
|
|
|
|
2017-06-16 09:48:18 +02:00
|
|
|
{% set sudoers_d_filename = name|replace('.','_') %}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if 'sudouser' in user and user['sudouser'] %}
|
|
|
|
|
|
|
|
users_sudoer-{{ name }}:
|
|
|
|
file.managed:
|
2016-08-30 17:20:18 +02:00
|
|
|
- replace: False
|
2017-06-16 09:48:18 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ sudoers_d_filename }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- user: root
|
|
|
|
- group: {{ users.root_group }}
|
|
|
|
- mode: '0440'
|
|
|
|
{% if 'sudo_rules' in user or 'sudo_defaults' in user %}
|
2015-09-20 15:21:34 +02:00
|
|
|
#{#%
|
2015-07-27 19:50:49 +02:00
|
|
|
{% if 'sudo_rules' in user %}
|
|
|
|
{% for rule in user['sudo_rules'] %}
|
|
|
|
"validate {{ name }} sudo rule {{ loop.index0 }} {{ name }} {{ rule }}":
|
|
|
|
cmd.run:
|
|
|
|
- name: 'visudo -cf - <<<"$rule" | { read output; if [[ $output != "stdin: parsed OK" ]] ; then echo $output ; fi }'
|
|
|
|
- stateful: True
|
|
|
|
- shell: {{ users.visudo_shell }}
|
|
|
|
- env:
|
|
|
|
# Specify the rule via an env var to avoid shell quoting issues.
|
|
|
|
- rule: "{{ name }} {{ rule }}"
|
|
|
|
- require_in:
|
|
|
|
- file: users_{{ users.sudoers_dir }}/{{ name }}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% if 'sudo_defaults' in user %}
|
|
|
|
{% for entry in user['sudo_defaults'] %}
|
|
|
|
"validate {{ name }} sudo Defaults {{ loop.index0 }} {{ name }} {{ entry }}":
|
|
|
|
cmd.run:
|
|
|
|
- name: 'visudo -cf - <<<"$rule" | { read output; if [[ $output != "stdin: parsed OK" ]] ; then echo $output ; fi }'
|
|
|
|
- stateful: True
|
|
|
|
- shell: {{ users.visudo_shell }}
|
|
|
|
- env:
|
|
|
|
# Specify the rule via an env var to avoid shell quoting issues.
|
|
|
|
- rule: "Defaults:{{ name }} {{ entry }}"
|
|
|
|
- require_in:
|
|
|
|
- file: users_{{ users.sudoers_dir }}/{{ name }}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2015-09-20 15:21:34 +02:00
|
|
|
#%#}
|
2015-07-27 19:50:49 +02:00
|
|
|
|
|
|
|
users_{{ users.sudoers_dir }}/{{ name }}:
|
|
|
|
file.managed:
|
2016-08-30 17:20:18 +02:00
|
|
|
- replace: True
|
2017-06-16 09:48:18 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ sudoers_d_filename }}
|
2015-07-27 19:50:49 +02:00
|
|
|
- contents: |
|
|
|
|
{%- if 'sudo_defaults' in user %}
|
|
|
|
{%- for entry in user['sudo_defaults'] %}
|
|
|
|
Defaults:{{ name }} {{ entry }}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'sudo_rules' in user %}
|
2015-12-30 04:31:57 +01:00
|
|
|
########################################################################
|
|
|
|
# File managed by Salt (users-formula).
|
|
|
|
# Your changes will be overwritten.
|
|
|
|
########################################################################
|
|
|
|
#
|
2015-07-27 19:50:49 +02:00
|
|
|
{%- for rule in user['sudo_rules'] %}
|
|
|
|
{{ name }} {{ rule }}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
- require:
|
|
|
|
- file: users_sudoer-defaults
|
|
|
|
- file: users_sudoer-{{ name }}
|
2015-12-30 04:31:57 +01:00
|
|
|
cmd.wait:
|
2017-06-16 09:48:18 +02:00
|
|
|
- name: visudo -cf {{ users.sudoers_dir }}/{{ sudoers_d_filename }} || ( rm -rvf {{ users.sudoers_dir }}/{{ sudoers_d_filename }}; exit 1 )
|
2015-12-30 04:31:57 +01:00
|
|
|
- watch:
|
2017-06-16 09:48:18 +02:00
|
|
|
- file: {{ users.sudoers_dir }}/{{ sudoers_d_filename }}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endif %}
|
|
|
|
{% else %}
|
2017-06-16 09:48:18 +02:00
|
|
|
users_{{ users.sudoers_dir }}/{{ sudoers_d_filename }}:
|
2015-07-27 19:50:49 +02:00
|
|
|
file.absent:
|
2017-06-16 09:48:18 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ sudoers_d_filename }}
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{%- if 'google_auth' in user %}
|
|
|
|
{%- for svc in user['google_auth'] %}
|
|
|
|
users_googleauth-{{ svc }}-{{ name }}:
|
|
|
|
file.managed:
|
|
|
|
- replace: false
|
|
|
|
- name: {{ users.googleauth_dir }}/{{ name }}_{{ svc }}
|
|
|
|
- contents_pillar: 'users:{{ name }}:google_auth:{{ svc }}'
|
|
|
|
- user: root
|
|
|
|
- group: {{ users.root_group }}
|
|
|
|
- mode: 400
|
|
|
|
- require:
|
|
|
|
- pkg: users_googleauth-package
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
|
2016-12-08 04:29:03 +01:00
|
|
|
# this doesn't work (Salt bug), therefore need to run state.apply twice
|
|
|
|
#include:
|
|
|
|
# - users
|
|
|
|
#
|
|
|
|
#git:
|
|
|
|
# pkg.installed:
|
|
|
|
# - require_in:
|
|
|
|
# - sls: users
|
|
|
|
#
|
2018-02-23 15:51:34 +01:00
|
|
|
{% if salt['cmd.has_exec']('git') %}
|
2016-02-17 11:35:29 +01:00
|
|
|
|
|
|
|
{% if 'gitconfig' in user %}
|
2015-09-11 10:40:14 +02:00
|
|
|
{% for key, value in user['gitconfig'].items() %}
|
|
|
|
users_{{ name }}_user_gitconfig_{{ loop.index0 }}:
|
2017-09-24 12:16:43 +02:00
|
|
|
{% if grains['saltversioninfo'] >= [2015, 8, 0, 0] %}
|
2015-09-11 10:40:14 +02:00
|
|
|
git.config_set:
|
|
|
|
{% else %}
|
|
|
|
git.config:
|
|
|
|
{% endif %}
|
|
|
|
- name: {{ key }}
|
|
|
|
- value: "{{ value }}"
|
|
|
|
- user: {{ name }}
|
2017-09-24 12:16:43 +02:00
|
|
|
{% if grains['saltversioninfo'] >= [2015, 8, 0, 0] %}
|
2015-09-11 10:40:14 +02:00
|
|
|
- global: True
|
|
|
|
{% else %}
|
|
|
|
- is_global: True
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2016-02-17 11:35:29 +01:00
|
|
|
|
|
|
|
{% 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 %}
|
|
|
|
|
2018-02-23 15:51:34 +01:00
|
|
|
{% endif %}
|
2015-09-11 10:40:14 +02:00
|
|
|
|
2015-07-27 19:50:49 +02:00
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
|
2015-08-18 16:27:25 +02:00
|
|
|
{% for name, user in pillar.get('users', {}).items()
|
|
|
|
if user.absent is defined and user.absent %}
|
2015-07-27 19:50:49 +02:00
|
|
|
users_absent_user_{{ name }}:
|
|
|
|
{% if 'purge' in user or 'force' in user %}
|
|
|
|
user.absent:
|
|
|
|
- name: {{ name }}
|
|
|
|
{% if 'purge' in user %}
|
|
|
|
- purge: {{ user['purge'] }}
|
|
|
|
{% endif %}
|
|
|
|
{% if 'force' in user %}
|
|
|
|
- force: {{ user['force'] }}
|
|
|
|
{% endif %}
|
|
|
|
{% else %}
|
|
|
|
user.absent:
|
|
|
|
- name: {{ name }}
|
|
|
|
{% endif -%}
|
|
|
|
users_{{ users.sudoers_dir }}/{{ name }}:
|
|
|
|
file.absent:
|
|
|
|
- name: {{ users.sudoers_dir }}/{{ name }}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for user in pillar.get('absent_users', []) %}
|
|
|
|
users_absent_user_2_{{ user }}:
|
2016-08-10 10:32:46 +02:00
|
|
|
user.absent:
|
2016-11-30 16:33:38 +01:00
|
|
|
- name: {{ user }}
|
2015-07-27 19:50:49 +02:00
|
|
|
users_2_{{ users.sudoers_dir }}/{{ user }}:
|
|
|
|
file.absent:
|
|
|
|
- name: {{ users.sudoers_dir }}/{{ user }}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for group in pillar.get('absent_groups', []) %}
|
|
|
|
users_absent_group_{{ group }}:
|
|
|
|
group.absent:
|
|
|
|
- name: {{ group }}
|
|
|
|
{% endfor %}
|