Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-flash· GoogleHugging Face LMArena Human Preference 140K

I am using Cinnamon 6.0.4. Please rewrite the polkit rules with JavaScript instead of…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Qwenqwen3-235b-a22b’s answer.
  1. User

    I am using Cinnamon 6.0.4. Please rewrite the polkit rules with JavaScript instead of the legacy pkla format.

  2. Gemini Assistant

    Alright, let's transition from the legacy .pkla format to the modern JavaScript .rules format for PolicyKit. This is a much cleaner and more powerful way to define authorization rules, giving you more granular control.

    PolicyKit JavaScript rules are placed in /etc/polkit-1/rules.d/ and are processed in alphanumeric order. This means files named 50-my-rule.rules will be processed before 60-another-rule.rules.

    Here's how to rewrite the previous rules using JavaScript.

    Important Considerations for JavaScript Rules:

    1. File Location: All these files will go into /etc/polkit-1/rules.d/.
    2. Naming: Use a two-digit prefix (e.g., 50-, 60-) for ordering and a descriptive name ending in .rules.
    3. polkit.addRule(function(action, subject) { ... });: This is the core function.
      • action: An object representing the action being performed (e.g., action.id for "org.freedesktop.login1.power-off").
      • subject: An object representing the user trying to perform the action (e.g., subject.isInGroup("sudo")).
    4. Return Values:
      • polkit.Result.YES: Allow the action.
      • polkit.Result.NO: Deny the action.
      • polkit.Result.AUTH_ADMIN: Require an administrator's password.
      • polkit.Result.AUTH_SELF: Require the user's own password (useful for things like changing their own settings).
    5. !subject.isInGroup("sudo"): This is your primary condition to identify non-admin users.

    Prerequisites (Review)

    • You have xrdp and cinnamon-desktop-environment installed.
    • Your users are added with sudo adduser <username> and are NOT in the sudo group.
    • The /etc/xrdp/startwm.sh is configured for Cinnamon.

    How to Implement

    1. Remove Old .pkla Files: First, clean up the old rules to avoid conflicts.

      sudo rm /etc/polkit-1/localauthority/50-local.d/01-no-power-actions.pkla
      sudo rm /etc/polkit-1/localauthority/50-local.d/02-no-network-changes.pkla
      sudo rm /etc/polkit-1/localauthority/50-local.d/03-no-user-management.pkla
      sudo rm /etc/polkit-1/localauthority/50-local.d/04-no-software-management.pkla
      sudo rm /etc/polkit-1/localauthority/50-local.d/05-no-time-changes.pkla
      sudo rm /etc/polkit-1/localauthority/50-local.d/06-no-drive-mounts.pkla
      sudo rm /etc/polkit-1/localauthority/50-local.d/07-no-printer-config.pkla
      
    2. Create New .rules Files: Use sudo nano or sudo vim to create these files in /etc/polkit-1/rules.d/.

    3. Restart Polkit Service (or Logout/Login): After creating/modifying rules, refresh the PolicyKit daemon:

      sudo systemctl restart polkit.service
      

      Or simply have the affected users log out of their xrdp session and log back in.


    The JavaScript PolicyKit Rules

    1. Power Management

    • File: /etc/polkit-1/rules.d/50-no-power-actions.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny power management actions for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var powerActions = [
                  "org.freedesktop.login1.power-off",
                  "org.freedesktop.login1.power-off-multiple-sessions",
                  "org.freedesktop.login1.reboot",
                  "org.freedesktop.login1.reboot-multiple-sessions",
                  "org.freedesktop.login1.suspend",
                  "org.freedesktop.login1.suspend-multiple-sessions",
                  "org.freedesktop.login1.hibernate",
                  "org.freedesktop.login1.hibernate-multiple-sessions"
              ];
              if (powerActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied power action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      

    2. Network Configuration

    • File: /etc/polkit-1/rules.d/51-no-network-changes.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny NetworkManager system settings changes for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var networkActions = [
                  "org.freedesktop.NetworkManager.settings.modify.system",
                  "org.freedesktop.NetworkManager.settings.modify.own", // Can affect shared settings if user creates a "system" connection
                  "org.freedesktop.NetworkManager.settings.modify.hostname",
                  "org.freedesktop.NetworkManager.network-control",
                  "org.freedesktop.NetworkManager.enable-disable-wifi",
                  "org.freedesktop.NetworkManager.enable-disable-network",
                  "org.freedesktop.NetworkManager.sleep-wake",
                  "org.freedesktop.NetworkManager.vpn.control",
                  "org.freedesktop.NetworkManager.connection.new",
                  "org.freedesktop.NetworkManager.connection.delete",
                  "org.freedesktop.NetworkManager.connection.modify"
              ];
              if (networkActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied network action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      

    3. User & Group Management

    • File: /etc/polkit-1/rules.d/52-no-user-management.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny user management actions for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var userManagementActions = [
                  "org.freedesktop.Accounts.set-enabled",
                  "org.freedesktop.Accounts.set-locked",
                  "org.freedesktop.Accounts.set-user-attribute",
                  "org.freedesktop.Accounts.create-user",
                  "org.freedesktop.Accounts.delete-user",
                  "org.freedesktop.Accounts.modify-user-privileges",
                  // "org.freedesktop.Accounts.change-own-password" // Uncomment if you want to prevent users from changing their OWN password
              ];
              if (userManagementActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied user management action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      
      • Note: I've commented out org.freedesktop.Accounts.change-own-password by default. Most environments allow users to change their own password. If you truly want to prevent even that, uncomment the line.

    4. Software Installation & Updates

    • File: /etc/polkit-1/rules.d/53-no-software-management.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny software management actions for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var softwareActions = [
                  "org.debian.apt.install-or-remove-packages",
                  "org.debian.apt.update-cache",
                  "org.debian.apt.upgrade-packages",
                  "org.freedesktop.packagekit.install-packages",
                  "org.freedesktop.packagekit.remove-packages",
                  "org.freedesktop.packagekit.update-packages",
                  "org.freedesktop.packagekit.repair-system",
                  "org.freedesktop.packagekit.change-locale",
                  "org.freedesktop.software-center.install",
                  "org.freedesktop.software-center.remove"
              ];
              if (softwareActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied software action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      

    5. System Time & Date

    • File: /etc/polkit-1/rules.d/54-no-time-changes.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny time and date changes for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var timeActions = [
                  "org.freedesktop.timedate1.set-time",
                  "org.freedesktop.timedate1.set-timezone",
                  "org.freedesktop.timedate1.set-ntp",
                  "org.freedesktop.timedate1.set-local-rtc"
              ];
              if (timeActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied time action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      

    6. Mounting/Unmounting Filesystems

    • File: /etc/polkit-1/rules.d/55-no-drive-mounts.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny system disk mounting/unmounting actions for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var mountActions = [
                  "org.freedesktop.udisks2.filesystem-mount-system",
                  "org.freedesktop.udisks2.filesystem-mount-other-seat",
                  "org.freedesktop.udisks2.filesystem-mount-options",
                  "org.freedesktop.udisks2.filesystem-unmount-others",
                  "org.freedesktop.udisks2.loop-setup",
                  "org.freedesktop.udisks2.change-system-power",
                  "org.freedesktop.udisks2.authorize"
                  // "org.freedesktop.udisks2.filesystem-mount" // This can prevent mounting *any* drive, including personal USBs. Use with caution.
              ];
              if (mountActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied mount action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      
      • Note: This is a strong restriction. If you want users to be able to mount their own USB drives, you might need to adjust or remove org.freedesktop.udisks2.filesystem-mount-other-seat or org.freedesktop.udisks2.filesystem-mount. The default PolicyKit rules often allow org.freedesktop.udisks2.filesystem-mount for active users if the device is not "system" owned. This rule explicitly tries to block broader mounting actions.

    7. Printing & Printer Configuration

    • File: /etc/polkit-1/rules.d/56-no-printer-config.rules
    • Content:
      polkit.addRule(function(action, subject) {
          // Deny printer configuration actions for non-sudo users
          if (!subject.isInGroup("sudo")) {
              var printerActions = [
                  "org.cups.cupsd.admin",
                  "org.cups.cupsd.set-default",
                  "org.cups.cupsd.shutdown"
                  // "org.cups.cupsd.print" // Uncomment if you want to prevent printing altogether.
              ];
              if (printerActions.indexOf(action.id) !== -1) {
                  polkit.log("Denied printer action '" + action.id + "' for user " + subject.user + ".");
                  return polkit.Result.NO;
              }
          }
      });
      
      • Note: org.cups.cupsd.print is commented out by default. This allows users to print to existing configured printers. If you want to disable printing entirely, uncomment that line.

    Important Reminder

    • Testing: After applying these rules and restarting polkit.service (or logging out/in as the test user), thoroughly test each restricted action while logged in as a normal user.
    • Logs: Check journalctl -f or /var/log/auth.log while testing. You should see polkit.log messages indicating that the actions were denied by your custom rules.

    This set of JavaScript rules provides the same level of robust restriction as the .pkla files, but in a more modern, flexible, and maintainable format.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.