J'ai essayé d'ajouter la règle suivante à polkit :
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units") {
polkit.log("action=" + action)
polkit.log("subject=" + subject)
polkit.log("unit="+action.lookup("unit"))
polkit.log("verb="+action.lookup("verb"))
if (action.lookup("unit") == "jira.service" ||
action.lookup("unit") == "bamboo.service" ||
action.lookup("unit") == "bitbucket.service") {
var verb = action.lookup("verb");
if (verb == "start" || verb == "stop" || verb == "restart") {
polkit.log("returning YES")
return polkit.Result.YES;
}
}
}
polkit.log("returning NO") });
Quand je cours :
systemctl stop bamboo
Je reçois :
Failed to stop bamboo.service: Interactive authentication required.
Le fichier /var/log/secure contient les lignes suivantes :
Apr 12 11:19:00 myhost polkitd[1081]: Registered Authentication Agent for unix-process:22681:1068941302 (system bus name :1.192164 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Apr 12 11:19:00 myhost polkitd[1081]: /etc/polkit-1/rules.d/10-buildsys-mgmt.rules:3: action=[Action id='org.freedesktop.systemd1.manage-units']
Apr 12 11:19:00 myhost polkitd[1081]: /etc/polkit-1/rules.d/10-buildsys-mgmt.rules:4: subject=[Subject pid=22681 user='myuser' groups=wheel,cvsgrp, seat='' session='' local=false active=false]
Apr 12 11:19:00 myhost polkitd[1081]: /etc/polkit-1/rules.d/10-buildsys-mgmt.rules:5: unit=undefined
Apr 12 11:19:00 myhost polkitd[1081]: /etc/polkit-1/rules.d/10-buildsys-mgmt.rules:6: verb=undefined
Apr 12 11:19:00 myhost polkitd[1081]: /etc/polkit-1/rules.d/10-buildsys-mgmt.rules:17: returning NO
Apr 12 11:19:00 myhost polkitd[1081]: Unregistered Authentication Agent for unix-process:22681:1068941302 (system bus name :1.192164, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Ce qui est important, c'est que l'objet action ne semble pas avoir de clés définies pour "unit" ou "verb". J'ai emprunté cette règle ici : https://wiki.archlinux.org/index.php/Polkit#Allow_management_of_individual_systemd_units_by_regular_users