Polkit / Systemd 交互

Polkit / Systemd 交互

我尝试向 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") });

当我跑步时:

systemctl stop bamboo

我得到:

Failed to stop bamboo.service: Interactive authentication required.

/var/log/secure 文件包含以下几行:

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)

重要的是,动作对象似乎没有为“单位”或“动词”定义键。我从这里抄袭了这条规则:https://wiki.archlinux.org/index.php/Polkit#Allow_management_of_individual_systemd_units_by_regular_users

答案1

此功能已在此处提交:https://github.com/systemd/systemd/commit/88ced61bf9673407f4b15bf51b1b408fd78c149d 并且可在 systemd 版本 226 之后使用。因此,它可能还不适用于您的发行版。RedHat 7 目前有 systemd v219。

我也想要这个,目前正在向 RedHat 开具请求票。

相关内容