Polkit: Difference between revisions

Rrdpad (talk | contribs)
Update syntax for example systemd unit
DHCP (talk | contribs)
m fix indentation
 
(One intermediate revision by one other user not shown)
Line 22: Line 22:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  security.polkit.extraConfig = ''
security.polkit.extraConfig = ''
    polkit.addRule(function (action, subject) {
  polkit.addRule(function (action, subject) {
      if (
    if (
        subject.isInGroup("users") &&
      subject.isInGroup("users") &&
        [
      [
          "org.freedesktop.login1.reboot",
        "org.freedesktop.login1.reboot",
          "org.freedesktop.login1.reboot-multiple-sessions",
        "org.freedesktop.login1.reboot-multiple-sessions",
          "org.freedesktop.login1.power-off",
        "org.freedesktop.login1.power-off",
          "org.freedesktop.login1.power-off-multiple-sessions",
        "org.freedesktop.login1.power-off-multiple-sessions",
        ].indexOf(action.id) !== -1
      ].indexOf(action.id) !== -1
      ) {
    ) {
        return polkit.Result.YES;
      return polkit.Result.YES;
      }
    }
    });
  });
  '';
'';
</nowiki>}}
</nowiki>}}


Line 43: Line 43:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
   security.polkit.extraConfig = ''
security.polkit.extraConfig = ''
  polkit.addRule(function(action, subject) {
    if (subject.isInGroup("wheel"))
      return polkit.Result.YES;
   });
'';
</nowiki>}}
 
(This does ''not'' take into account the <code>security.polkit.adminIdentities</code> setting.)
 
=== Debugging requested rules ===
 
To have Polkit print debug information for every incoming authorization, it is possible to create a debugging rule and enable Polkit debug printing:
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
security.polkit = {
  debug = true;  // Enables `polkit.log` function
  extraConfig = ''
     polkit.addRule(function(action, subject) {
     polkit.addRule(function(action, subject) {
       if (subject.isInGroup("wheel"))
       polkit.log("");
        return polkit.Result.YES;
      polkit.log("action=" + action);
      polkit.log("subject=" + subject);
     });
     });
   '';
   '';
};
</nowiki>}}
</nowiki>}}
(This does ''not'' take into account the <code>security.polkit.adminIdentities</code> setting.)


== Authentication agents ==
== Authentication agents ==