I have a requirement to allow non-root users to start and stop a service. It was recommended to me to use PolicyKit
rather than sudoers.d
, which I am familiar with.
As I have no experience with PolicyKit
, I thought I would experiment and create a rule to allow non-root users to start and stop the Docker service. I have created a file, /etc/polkit-1/rules.d/10-docker.rules
containing:
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units" &&
action.lookup("unit") == "docker.service")
{
return polkit.Result.YES;
}
})
However, whenever I execute systemctl start|stop|restart docker.service
, I keep getting prompted for a password. What am I missing?
Also, I would like to limit non-root users to control this service who are in a specific group e.g. blah
. How do I incorporate this into my rule?
My target OS is RHEL 7.7.