Skip to content

Instantly share code, notes, and snippets.

@grawity
Last active September 8, 2025 05:24
Show Gist options
  • Save grawity/3886114 to your computer and use it in GitHub Desktop.
Save grawity/3886114 to your computer and use it in GitHub Desktop.

Revisions

  1. grawity revised this gist Sep 8, 2025. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion _Example polkit rules_.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,12 @@
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the `polkit(8)` manpage for the object structure and available API. **These examples are for polkit versions 106 and later, with the JS interpreter.** They won't work with Debian's polkit v105.

    - If you don't know the action name, run `pkaction`:
    - If you don't know the action name, either run `pkaction` and look for anything similar:

    pkaction | grep cups
    ...or try to perform the actual action, cancel it, then look in your system logs:

    journalctl -t polkitd -n 10 | grep action

    - The possible results are `YES`, `AUTH_SELF(_KEEP)`, `AUTH_ADMIN(_KEEP)`, `NO`. Returning a result is final. Returning `null` will continue checking other rules.

  2. grawity revised this gist Feb 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion _Example polkit rules_.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the `polkit(8)` manpage for the object structure and available API.
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the `polkit(8)` manpage for the object structure and available API. **These examples are for polkit versions 106 and later, with the JS interpreter.** They won't work with Debian's polkit v105.

    - If you don't know the action name, run `pkaction`:

  3. grawity revised this gist Jan 26, 2016. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions systemd-allow-service.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.systemd1.manage-units" &&
    action.lookup("unit") == "hybrid.service" &&
    subject.user == "michael")
    {
    return polkit.Result.YES;
    }
    })
  4. grawity revised this gist Oct 9, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions _Example polkit rules_.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest. See the `polkit(8)` manpage for rule syntax. (It's JavaScript.)
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the `polkit(8)` manpage for the object structure and available API.

    If you don't know the action name, run `pkaction`:
    - If you don't know the action name, run `pkaction`:

    pkaction | grep cups
    pkaction | grep cups

    The possible results are `YES`, `AUTH_SELF(_KEEP)`, `AUTH_ADMIN(_KEEP)`, `NO`. Returning a result is final. Returning `null` will continue checking other rules.
    - The possible results are `YES`, `AUTH_SELF(_KEEP)`, `AUTH_ADMIN(_KEEP)`, `NO`. Returning a result is final. Returning `null` will continue checking other rules.

    Put your rules in `/etc/polkit-1/rules.d/*.rules`. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)
    - Put your rules in `/etc/polkit-1/rules.d/*.rules`. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)

    To test your rules, use `pkcheck`:
    - To test your rules, use `pkcheck`:

    pkcheck -u -p $$ -a org.freedesktop.packagekit.upgrade-system
    pkcheck -u -p $$ -a org.freedesktop.packagekit.upgrade-system
  5. grawity revised this gist Jan 11, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions _Example polkit rules_.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@ If you don't know the action name, run `pkaction`:

    pkaction | grep cups

    The possible results are `YES`, `AUTH_SELF(_KEEP)`, `AUTH_ADMIN(_KEEP)`, `NO`. Returning a result is final. Returning `null` will continue checking other rules.

    Put your rules in `/etc/polkit-1/rules.d/*.rules`. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)

    To test your rules, use `pkcheck`:
  6. grawity revised this gist Jan 11, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions _Example polkit rules_.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest.

    See the `polkit(8)` manpage for rule syntax. (It's JavaScript.)
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest. See the `polkit(8)` manpage for rule syntax. (It's JavaScript.)

    If you don't know the action name, run `pkaction`:

  7. grawity revised this gist Jan 11, 2015. 6 changed files with 13 additions and 14 deletions.
    12 changes: 8 additions & 4 deletions _Example polkit rules_.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,13 @@
    Put your rules in `/etc/polkit-1/rules.d/*.rules`.
    **These are only examples,** for a few very common actions. You are expected to write your own rules for the rest.

    See the `polkit(8)` manpage for rule syntax. (It's JavaScript.)

    If you don't know the action name, run `pkaction`.
    If you don't know the action name, run `pkaction`:

    To test your rules, use `pkcheck`.
    pkaction | grep cups

    `pkcheck -u -p $$ -a org.freedesktop.packagekit.upgrade-system`
    Put your rules in `/etc/polkit-1/rules.d/*.rules`. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)

    To test your rules, use `pkcheck`:

    pkcheck -u -p $$ -a org.freedesktop.packagekit.upgrade-system
    3 changes: 1 addition & 2 deletions networkmanager-wheel-noauth.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    /* Copy this to /etc/polkit-1/rules.d/80-networkmanager-wheel-without-authentication.rules
    */
    /* Copy this to /etc/polkit-1/rules.d/80-networkmanager-wheel-without-authentication.rules */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.NetworkManager\./.test(action.id) &&
    3 changes: 1 addition & 2 deletions packagekit-restrict.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    /* Copy this to /etc/polkit-1/rules.d/packagekit-restrict.rules
    */
    /* Copy this to /etc/polkit-1/rules.d/packagekit-restrict.rules */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.packagekit\./.test(action.id)) {
    3 changes: 1 addition & 2 deletions udisks1-avoid-consolekit.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    /* Copy this to /etc/polkit-1/rules.d/udisks-no-consolekit.rules
    */
    /* Copy this to /etc/polkit-1/rules.d/udisks-no-consolekit.rules */

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks.filesystem-mount") {
    3 changes: 1 addition & 2 deletions udisks1-wheel-is-god.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    /* Copy this to /etc/polkit-1/rules.d/always-allow-wheel.rules
    */
    /* Copy this to /etc/polkit-1/rules.d/always-allow-wheel.rules */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.udisks\./.test(action.id)
    3 changes: 1 addition & 2 deletions udisks2-allow-mount-internal.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    /* Copy this to /etc/polkit-1/rules.d/allow-mount-internal.rules
    */
    /* Copy this to /etc/polkit-1/rules.d/allow-mount-internal.rules */

    polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||
  8. grawity revised this gist Dec 27, 2014. 3 changed files with 7 additions and 4 deletions.
    3 changes: 2 additions & 1 deletion networkmanager-wheel-noauth.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,8 @@

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.NetworkManager\./.test(action.id) &&
    subject.local && subject.active && subject.isInGroup("wheel")) {
    subject.local && subject.active && subject.isInGroup("wheel"))
    {
    return polkit.Result.YES;
    }
    });
    5 changes: 3 additions & 2 deletions udisks1-wheel-is-god.js
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,9 @@
    */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.udisks\./.test(action.id) && subject.isInGroup("wheel"))
    if (/^org\.freedesktop\.udisks\./.test(action.id)
    && subject.isInGroup("wheel"))
    {
    return polkit.Result.YES;
    }
    });
    });
    3 changes: 2 additions & 1 deletion udisks2-allow-mount-internal.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,8 @@
    polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||
    action.id == "org.freedesktop.udisks.filesystem-mount-system-internal") &&
    subject.local && subject.active && subject.isInGroup("users")) {
    subject.local && subject.active && subject.isInGroup("users"))
    {
    return polkit.Result.YES;
    }
    });
  9. grawity revised this gist Aug 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion packagekit-restrict.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.packagekit\./.test(action.id)) {
    if (subject.local && subject.active && subject.isInGroup("wheel")) {
    if (subject.user === "fred" || subject.isInGroup("wheel")) {
    return polkit.Result.YES;
    } else {
    return polkit.Result.AUTH_ADMIN_KEEP;
  10. grawity revised this gist Oct 9, 2013. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions networkmanager-wheel-noauth.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    /* Copy this to /etc/polkit-1/rules.d/80-networkmanager-wheel-without-authentication.rules
    */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.NetworkManager\./.test(action.id) &&
    subject.local && subject.active && subject.isInGroup("wheel")) {
    return polkit.Result.YES;
    }
    });
  11. grawity revised this gist Sep 8, 2013. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions udisks1-avoid-consolekit.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    /* Copy this to /etc/polkit-1/rules.d/udisks-no-consolekit.rules
    */

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks.filesystem-mount") {
    if (subject.isInGroup("wheel"))
    return polkit.Result.YES;
    else
    return polkit.Result.AUTH_ADMIN_KEEP;
    } else if (/^org\.freedesktop\.udisks\./.test(action.id)) {
    return polkit.Result.AUTH_ADMIN_KEEP;
    }
    });
  12. grawity revised this gist Sep 8, 2013. 3 changed files with 5 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion packagekit-restrict.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /* Copy this to /etc/polkit-1/rules.d/packagekit-restrict.rules
    */
    */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.packagekit\./.test(action.id)) {
    3 changes: 3 additions & 0 deletions udisks1-wheel-is-god.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    /* Copy this to /etc/polkit-1/rules.d/always-allow-wheel.rules
    */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.udisks\./.test(action.id) && subject.isInGroup("wheel"))
    {
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /* Copy this to /etc/polkit-1/rules.d/allow-mount-internal.rules
    */
    */

    polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||
  13. grawity revised this gist Sep 8, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions udisks1-wheel-is-god.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.udisks\./.test(action.id) && subject.isInGroup("wheel"))
    {
    return polkit.Result.YES;
    }
    });
  14. grawity renamed this gist Jun 3, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  15. grawity revised this gist Jun 3, 2013. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion _README_.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,9 @@
    Put your rules in `/etc/polkit-1/rules.d/*.rules`. See the `polkit(8)` manpage for rule syntax.
    Put your rules in `/etc/polkit-1/rules.d/*.rules`.

    See the `polkit(8)` manpage for rule syntax. (It's JavaScript.)

    If you don't know the action name, run `pkaction`.

    To test your rules, use `pkcheck`.

    `pkcheck -u -p $$ -a org.freedesktop.packagekit.upgrade-system`
  16. grawity revised this gist Jun 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion _README_.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    Put your rules in `/etc/polkit-1/rules.d/*.rules`.
    Put your rules in `/etc/polkit-1/rules.d/*.rules`. See the `polkit(8)` manpage for rule syntax.
  17. grawity revised this gist Jun 3, 2013. 2 changed files with 13 additions and 0 deletions.
    1 change: 1 addition & 0 deletions _README_.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Put your rules in `/etc/polkit-1/rules.d/*.rules`.
    12 changes: 12 additions & 0 deletions packagekit-restrict.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    /* Copy this to /etc/polkit-1/rules.d/packagekit-restrict.rules
    */

    polkit.addRule(function(action, subject) {
    if (/^org\.freedesktop\.packagekit\./.test(action.id)) {
    if (subject.local && subject.active && subject.isInGroup("wheel")) {
    return polkit.Result.YES;
    } else {
    return polkit.Result.AUTH_ADMIN_KEEP;
    }
    }
    });
  18. grawity revised this gist Dec 30, 2012. 2 changed files with 10 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    /* /etc/polkit-1/rules.d/allow-mount-system.rules */

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks2.filesystem-mount-system" &&
    subject.local && subject.active && subject.isInGroup("users")) {
    return polkit.Result.YES;
    }
    });
    10 changes: 10 additions & 0 deletions udisks-allow-mount-internal.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    /* Copy this to /etc/polkit-1/rules.d/allow-mount-internal.rules
    */

    polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||
    action.id == "org.freedesktop.udisks.filesystem-mount-system-internal") &&
    subject.local && subject.active && subject.isInGroup("users")) {
    return polkit.Result.YES;
    }
    });
  19. grawity revised this gist Nov 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # /etc/polkit-1/rules.d/allow-mount-system.rules
    /* /etc/polkit-1/rules.d/allow-mount-system.rules */

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks2.filesystem-mount-system" &&
  20. grawity revised this gist Nov 16, 2012. 3 changed files with 8 additions and 16 deletions.
    8 changes: 0 additions & 8 deletions allow-shutdown-105.rule
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    # /etc/polkit-1/localauthority/50-local.d/foo.pkla

    [Allow users to power off always]
    Identity=unix-group:users
    Action=org.freedesktop.login1.power-off
    ResultAny=yes
    ResultActive=yes
    ResultInactive=yes
    8 changes: 0 additions & 8 deletions allow-shutdown-107.rule
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    # /etc/polkit-1/rules.d/foo.rules

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.power-off" &&
    subject.isInGroup("users")) {
    return polkit.Result.YES;
    }
    });
    8 changes: 8 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # /etc/polkit-1/rules.d/allow-mount-system.rules

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks2.filesystem-mount-system" &&
    subject.local && subject.active && subject.isInGroup("users")) {
    return polkit.Result.YES;
    }
    });
  21. grawity revised this gist Oct 13, 2012. 2 changed files with 5 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions allow-shutdown-105.rule
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # /etc/polkit-1/localauthority/50-local.d/foo.pkla

    [Allow users to power off always]
    Identity=unix-group:users
    Action=org.freedesktop.login1.power-off
    4 changes: 3 additions & 1 deletion allow-shutdown-107.rule
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # /etc/polkit-1/rules.d/foo.rules

    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.power-off" &&
    subject.isInGroup("users")) {
    return polkit.Result.YES;
    }
    });
    });
  22. grawity revised this gist Oct 13, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions allow-shutdown-107.rule
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.power-off" &&
    subject.isInGroup("users")) {
    return polkit.Result.YES;
    }
    });
  23. grawity created this gist Oct 13, 2012.
    6 changes: 6 additions & 0 deletions allow-shutdown-105.rule
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    [Allow users to power off always]
    Identity=unix-group:users
    Action=org.freedesktop.login1.power-off
    ResultAny=yes
    ResultActive=yes
    ResultInactive=yes