Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make AdminIdentity configureable per user #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ users:
- ALL=(otheruser) /usr/bin/script.sh
sudo_defaults:
- '!requiretty'
# enable polkitadmin to make user an AdminIdentity for polkit
polkitadmin: True
shell: /bin/bash
remove_groups: False
prime_group:
Expand Down
9 changes: 8 additions & 1 deletion users/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% set used_sudo = [] %}
{% set used_googleauth = [] %}
{% set used_user_files = [] %}
{% 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' %}
Expand Down Expand Up @@ -38,9 +39,12 @@ users_group_present_{{ group }}:
{%- if salt['pillar.get']('users:' ~ name ~ ':user_files:enabled', False) %}
{%- do used_user_files.append(1) %}
{%- endif %}
{%- if user.get('polkitadmin', False) == True %}
{%- do used_polkit.append(1) %}
{%- endif %}
{%- endfor %}

{%- if used_sudo or used_googleauth or used_user_files %}
{%- if used_sudo or used_googleauth or used_user_files or used_polkit %}
include:
{%- if used_sudo %}
- users.sudo
Expand All @@ -51,6 +55,9 @@ include:
{%- if used_user_files %}
- users.user_files
{%- endif %}
{%- if used_polkit %}
- users.polkit
noelmcloughlin marked this conversation as resolved.
Show resolved Hide resolved
{%- endif %}
{%- endif %}

{% for name, user in pillar.get('users', {}).items()
Expand Down
8 changes: 6 additions & 2 deletions users/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
'bash_package': 'bash',
'sudo_package': 'sudo',
'googleauth_package': 'libpam-google-authenticator',
},
'polkit_dir': '/etc/polkit-1/localauthority.conf.d',
'polkit_defaults': 'unix-group:sudo;'
},
'Gentoo': {
'sudoers_dir': '/etc/sudoers.d',
'sudoers_file': '/etc/sudoers',
Expand Down Expand Up @@ -82,6 +84,8 @@
'bash_package': 'bash',
'sudo_package': 'sudo',
'googleauth_package': 'libpam-google-authenticator',
'polkit_dir': '/etc/polkit-1/localauthority.conf.d',
'polkit_defaults': 'unix-group:sudo;'
},
}, merge=salt['pillar.get']('users-formula:lookup')),
base='users',
Expand All @@ -90,4 +94,4 @@
{% if grains.os == 'MacOS' %}
{% set group = salt['cmd.run']("stat -f '%Sg' /dev/console") %}
{% do users.update({'root_group': group,}) %}
{% endif %}
{% endif %}
31 changes: 31 additions & 0 deletions users/polkit.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% from "users/map.jinja" import users with context %}
{% set polkitusers = {} %}
{% set polkitusers = {'value': ''} %}

{% for name, user in pillar.get('users', {}).items() %}
{% if user.absent is not defined or not user.absent %}
{% if 'polkitadmin' in user and user['polkitadmin'] %}
{% do polkitusers.update({'value': polkitusers.value + 'unix-user:' + name + ';'}) %}
{% endif %}
{% endif %}
{% endfor %}

{% if polkitusers.value != '' %}
users_{{ users.polkit_dir }}/99salt-users-formula.conf:
file.managed:
noelmcloughlin marked this conversation as resolved.
Show resolved Hide resolved
- replace: True
- onlyif: 'test -d {{ users.polkit_dir }}'
- name: {{ users.polkit_dir }}/99salt-users-formula.conf
- contents: |
########################################################################
# File managed by Salt (users-formula).
# Your changes will be overwritten.
########################################################################
#
[Configuration]
AdminIdentities={{ users.polkit_defaults }}{{ polkitusers.value }}
{% else %}
users_{{ users.polkit_dir }}/99salt-users-formula.conf_delete:
file.absent:
- name: {{ users.polkit_dir }}/99salt-users-formula.conf
{% endif %}