Skip to content

Commit 12fa3df

Browse files
committed
Update the optional PolicyKit rule
1. To limit by service 2. To take a list of users in addition to a group 2. To optionally automatically use the `owner`s in `cvmfs_repositories` instead of a provided list
1 parent 6536712 commit 12fa3df

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

defaults/main.yml

+13
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ cvmfs_geoip_db_update_day: "{{ 28 | random(seed=inventory_hostname) }}"
124124
# 3. this points to a cert bundle that contains CA certs for your Stratum 0 (the default here is valid for EL).
125125
# cvmfs_x509_cert_bundle: /etc/pki/tls/cert.pem
126126

127+
# The role will deploy a PolicyKit rule that allows unprivileged users to manage the services in cvmfs_manage_units if
128+
# either of the following two options are set.
129+
130+
# Either a list of usernames, or set to a boolean true to automatically use the 'owner's in cvmfs_repositories
131+
#cvmfs_manage_units_users: ...
132+
133+
# A group name
134+
#cvmfs_manage_units_group: ...
135+
136+
# The list of units that can be managed by users in the above group
137+
cvmfs_manage_units:
138+
- squid.service
139+
127140
#
128141
# Galaxy-specific stuff follows
129142
#

tasks/stratum1.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@
129129
src: 01-manage-units.rules.j2
130130
dest: /etc/polkit-1/rules.d/01-manage-units.rules
131131
mode: 0644
132-
when: cvmfs_manage_units_group is defined
132+
when: cvmfs_manage_units_users is defined or cvmfs_manage_units_group is defined

templates/01-manage-units.rules.j2

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
* This file is managed by Ansible. ALL CHANGES WILL BE OVERWRITTEN.
33
*/
44

5-
/* Allow users in the docker group to manage units. Way more control than we
6-
* would like to give, but the "unit" and "verb" action variables (used with
7-
* action.lookup()) were not added to systemd until 226, so unless RedHat
8-
* backports them, we are SOL.
9-
*/
5+
// Allow CVMFS repo owners to manage related services
106
polkit.addRule(function(action, subject) {
7+
var allowedUnits = {{ cvmfs_manage_units | to_json }};
8+
{% if cvmfs_manage_units_users is defined and cvmfs_manage_units_users is true %}
9+
var allowedUsers = {{ cvmfs_repositories | map(attribute='owner') | unique | to_json }};
10+
{% elif cvmfs_manage_units_users is defined %}
11+
var allowedUsers = {{ cvmfs_manage_units_users | to_json }};
12+
{% endif %}
1113
if (action.id == "org.freedesktop.systemd1.manage-units" &&
14+
allowedUnits.includes(action.lookup("unit")) &&
15+
{% if cvmfs_manage_units_users is defined and cvmfs_manage_units_group is defined %}
16+
(allowedUsers.includes(subject.user) || subject.isInGroup("{{ cvmfs_manage_units_group }}"))) {
17+
{% elif cvmfs_manage_units_users is defined %}
18+
allowedUsers.includes(subject.user)) {
19+
{% elif cvmfs_manage_units_group is defined %}
1220
subject.isInGroup("{{ cvmfs_manage_units_group }}")) {
21+
{% endif %}
1322
return polkit.Result.YES;
1423
}
1524
});

0 commit comments

Comments
 (0)