Polkit help
I'd like to allow a user to run systemd-inhibit --what="sleep:shutdown some-task"
I found https://superuser.com/questions/1413107/how-to-use-systemd-inhibit-without-sudo/1621311#1621311, which adds some file in /etc/polkit-1/rules.d (which I had to create as this directory did not exist) I checked the actions in /etc/polkit-1/actions to get the proper name, created the rule, restarted polkit, yet the permission is still denied.
I saw in https://trisquel.info/en/wiki/hibernation-aka-suspend-disk a polkit rule example but as a pkla file, which has a completely different syntax. Is it what should be used? What would be the syntax to allow this only for a particular user?
I found a comment that on Ubuntu, polkit rules in ECMA-262 syntax (more famously known as JavaScript), normally in /etc/polkit-1/rules.d, are not supported. I have read so many Ubuntu wiki pages telling to use /etc/polkit/rules.d, I tried them all (checked the exact action names and re-checked several time everything and tried generating logs) and they seemed to never be executed, so perhaps the comment is right, but I wonder why so many pages of wrong information.
What worked is creating a file /var/lib/polkit-1/localauthority/50-local.d/inhibit-shutdown-idle.pkla with
[Allow specialuser to inhibit shutdown and sleep]
Identity=unix-user:specialuser
Action=org.freedesktop.login1.inhibit-block-shutdown;org.freedesktop.login1.inhibit-block-sleep
ResultAny=yes
The last line is inspired from examples in the man page of pklocalauthority. From the explanation it seems that if ResultActive=yes is used, it will only be valid if there in an active session on the console. Since I want this to work from ssh, I used ResultAny=yes. But I could not find any proper description of the possibly directives and their meanings.
So my problem is somehow solved.
EDIT: The above is correct, but my problem was only almost solved, as I hit the bug described at https://github.com/systemd/systemd/issues/33834 (adding org.freedesktop.login1.inhibit-handle-lid-switch makes it possible to inhibit sleep and shutdown, but according to the description, it will also allow inhibiting any combination of actions, which is wrong).