Skip to content

Commit

Permalink
Changes in user management:
Browse files Browse the repository at this point in the history
  - Allow to specify primary gid for user
  - Use user.name field for setting linux username
  - Allow non-unique uids
  - Workaround file.directory bug for non-unique uids
  - Allow system users (Choose UID in the range of FIRST_SYSTEM_UID and LAST_SYSTEM_UID)
  • Loading branch information
horakmar committed Aug 3, 2018
1 parent c6f75ef commit 479a4be
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ will be removed.
full_name: 'With hased password'
home: '/home/elizabeth'
password: "$6$nUI7QEz3$dFYjzQqK5cJ6HQ38KqG4gTWA9eJu3aKx6TRVDFh6BVJxJgFWg2akfAA7f1fCxcSUeOJ2arCO6EEI6XXnHXxG10"
someserv:
name: 'someservice'
enabled: true
full_name: 'Some super service owner'
home: '/usr/lib/someservice'
home_dir_mode: 700
system:true
unique: false
uid: 0
gid: 0
Configure sudo for users and groups under ``/etc/sudoers.d/``.
This ways ``linux.system.sudo`` pillar map to actual sudo attributes:
Expand Down
43 changes: 27 additions & 16 deletions linux/system/user.sls
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ include:
{%- endfor %}
{%- if user.gid is not defined %}
system_group_{{ name }}:
system_group_{{ user.name }}:
group.present:
- name: {{ name }}
- name: {{ user.name }}
- require_in:
- user: system_user_{{ name }}
- user: system_user_{{ user.name }}
{%- endif %}
system_user_{{ name }}:
system_user_{{ user.name }}:
user.present:
- name: {{ name }}
- name: {{ user.name }}
- home: {{ user.home }}
{% if user.get('password') == False %}
- enforce_password: false
Expand All @@ -37,62 +37,73 @@ system_user_{{ name }}:
- password: {{ user.password }}
- hash_password: {{ user.get('hash_password', False) }}
{% endif %}
{%- if user.gid is defined %}
- gid: {{ user.gid }}
{%- else %}
- gid_from_name: true
{%- endif %}
{%- if user.groups is defined %}
- groups: {{ user.groups }}
{%- endif %}
{%- if user.system is defined and user.system %}
- system: True
- system: true
{%- else %}
- shell: {{ user.get('shell', '/bin/bash') }}
{%- endif %}
{%- if user.uid is defined and user.uid %}
{%- if user.uid is defined %}
- uid: {{ user.uid }}
{%- endif %}
{%- if user.unique is defined %}
- unique: {{ user.unique }}
{%- endif %}
- require: {{ requires|yaml }}
system_user_home_{{ user.home }}:
file.directory:
- name: {{ user.home }}
- user: {{ name }}
{%- if user.uid is defined and user.uid == 0 %}
- user: root
{%- else %}
- user: {{ user.name }}
{%- endif %}
- mode: {{ user.get('home_dir_mode', 700) }}
- makedirs: true
- require:
- user: system_user_{{ name }}
- user: system_user_{{ user.name }}
{%- if user.get('sudo', False) %}
/etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
/etc/sudoers.d/90-salt-user-{{ user.name|replace('.', '-') }}:
file.managed:
- source: salt://linux/files/sudoer
- template: jinja
- user: root
- group: root
- mode: 440
- defaults:
user_name: {{ name }}
user_name: {{ user.name }}
- require:
- user: system_user_{{ name }}
- user: system_user_{{ user.name }}
- check_cmd: /usr/sbin/visudo -c -f
{%- else %}
/etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
/etc/sudoers.d/90-salt-user-{{ user.name|replace('.', '-') }}:
file.absent
{%- endif %}
{%- else %}
system_user_{{ name }}:
system_user_{{ user.name }}:
user.absent:
- name: {{ name }}
- name: {{ user.name }}
system_user_home_{{ user.home }}:
file.absent:
- name: {{ user.home }}
/etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
/etc/sudoers.d/90-salt-user-{{ user.name|replace('.', '-') }}:
file.absent
{%- endif %}
Expand Down

0 comments on commit 479a4be

Please sign in to comment.