I am using Cinnamon 6.0.4. Please rewrite the polkit rules with JavaScript instead of…
- User
I am using Cinnamon 6.0.4. Please rewrite the polkit rules with JavaScript instead of the legacy pkla format.
Assistant
To enforce strict access control on your Ubuntu system with Cinnamon 6.0.4, you can replace the legacy
.pklaPolicyKit configuration files with modern JavaScript-based authorization rules. This method provides a more flexible and maintainable approach to defining system-wide access policies, especially in multi-user remote desktop environments.
🛠️ Prerequisites
- PolicyKit version 0.105 or later (required for JS rules)
- Cinnamon 6.0.4 (desktop environment)
- Remote desktop access via xrdp (already set up)
- User groups:
- Regular users:
users - Administrators:
sudo
- Regular users:
📁 Directory for JS Policy Files
Place your JavaScript-based rules in:
/etc/polkit-1/priviled.d/Note: Ensure the directory exists. If not, create it with:
sudo mkdir -p /etc/polkit-1/priviled.d/Each rule should be in a separate
.jsfile (e.g.,01-power.js,02-network.js) for clarity and modularity.
🧩 JavaScript Rule Template
Each JavaScript rule is a function that returns a
Polkit.Resultbased on the action and subject (user/group):polkit.addRule(function(action, subject) { // Condition logic return polkit.Result.no; // Deny });You can also return:
polkit.Result.auth_admin(require admin password)polkit.Result.auth_self(require user's own password)polkit.Result.yes(allow)
🛑 Disable Power Management Actions
File:
/etc/polkit-1/priviled.d/01-power.jspolkit.addRule(function(action, subject) { if ( (subject.isInGroup("users") || subject.isInGroup("lpadmin") || subject.isInGroup("cdrom") || subject.isInGroup("plugdev") || subject.isInGroup("sambashare")) && !subject.isInGroup("sudo") ) { if ( action.id == "org.freedesktop.login1.power-off" || action.id == "org.freedesktop.login1.power-off-multiple-sessions" || action.id == "org.freedesktop.login1.reboot" || action.id == "org.freedesktop.login1.reboot-multiple-sessions" || action.id == "org.freedesktop.login1.suspend" || action.id == "org.freedesktop.login1.suspend-multiple-sessions" || action.id == "org.freedesktop.login1.hibernate" || action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ) { return polkit.Result.no; } } });
🛑 Disable Network Configuration Changes
File:
/etc/polkit-1/priviled.d/02-network.jspolkit.addRule(function(action, subject) { if ( subject.isInGroup("users") && !subject.isInGroup("sudo") ) { if ( action.id == "org.freedesktop.NetworkManager.settings.modify.system" || action.id == "org.freedesktop.NetworkManager.settings.modify.own" || action.id == "org.freedesktop.NetworkManager.settings.modify.hostname" || action.id == "org.freedesktop.NetworkManager.network-control" || action.id == "org.freedesktop.NetworkManager.enable-disable-wifi" || action.id == "org.freedesktop.NetworkManager.enable-disable-network" || action.id == "org.freedesktop.NetworkManager.sleep-wake" || action.id == "org.freedesktop.NetworkManager.vpn.control" || action.id == "org.freedesktop.NetworkManager.connection.new" || action.id == "org.freedesktop.NetworkManager.connection.delete" || action.id == "org.freedesktop.NetworkManager.connection.modify" ) { return polkit.Result.no; } } });
🛑 Disable User & Group Management
File:
/etc/polkit-1/priviled.d/03-user-management.jspolkit.addRule(function(action, subject) { if ( subject.isInGroup("users") && !subject.isInGroup("sudo") ) { if ( action.id == "org.freedesktop.Accounts.set-enabled" || action.id == "org.freedesktop.Accounts.set-locked" || action.id == "org.freedesktop.Accounts.set-user-attribute" || action.id == "org.freedesktop.Accounts.create-user" || action.id == "org.freedesktop.Accounts.delete-user" || action.id == "org.freedesktop.Accounts.modify-user-privileges" ) { return polkit.Result.no; } } });To allow users to change their own password, remove
org.freedesktop.Accounts.change-own-passwordfrom the list or handle it separately.
🛑 Disable Software Installation and Updates
File:
/etc/polkit-1/priviled.d/04-software.jspolkit.addRule(function(action, subject) { if ( subject.isInGroup("users") && !subject.isInGroup("sudo") ) { if ( action.id == "org.debian.apt.install-or-remove-packages" || action.id == "org.debian.apt.update-cache" || action.id == "org.debian.apt.upgrade-packages" || action.id == "org.freedesktop.packagekit.install-packages" || action.id == "org.freedesktop.packagekit.remove-packages" || action.id == "org.freedesktop.packagekit.update-packages" || action.id == "org.freedesktop.packagekit.repair-system" || action.id == "org.freedesktop.packagekit.change-locale" || action.id == "org.freedesktop.software-center.install" || action.id == "org.freedesktop.software-center.remove" ) { return polkit.Result.no; } } });
🛑 Disable System Time and Date Changes
File:
/etc/polkit-1/priviled.d/05-time.jspolkit.addRule(function(action, subject) { if ( subject.isInGroup("users") && !subject.isInGroup("sudo") ) { if ( action.id == "org.freedesktop.timedate1.set-time" || action.id == "org.freedesktop.timedate1.set-timezone" || action.id == "org.freedesktop.timedate1.set-ntp" || action.id == "org.freedesktop.timedate1.set-local-rtc" ) { return polkit.Result.no; } } });
🛑 Disable Disk Mounting/Unmounting
File:
/etc/polkit-1/priviled.d/06-disk.jspolkit.addRule(function(action, subject) { if ( subject.isInGroup("users") && !subject.isInGroup("sudo") ) { if ( action.id == "org.freedesktop.udisks2.filesystem-mount-system" || action.id == "org.freedesktop.udisks2.filesystem-mount-other-seat" || action.id == "org.freedesktop.udisks2.filesystem-mount-options" || action.id == "org.freedesktop.udisks2.filesystem-unmount-others" || action.id == "org.freedesktop.udisks2.loop-setup" || action.id == "org.freedesktop.udisks2.change-system-power" || action.id == "org.freedesktop.udisks2.authorize" ) { return polkit.Result.no; } } });
🛑 Disable Printer Configuration
File:
/etc/polkit-1/priviled.d/07-printer.jspolkit.addRule(function(action, subject) { if ( subject.isInGroup("users") && !subject.isInGroup("sudo") ) { if ( action.id == "org.cups.cupsd.admin" || action.id == "org.cups.cupsd.set-default" || action.id == "org.cups.cupsd.shutdown" ) { return polkit.Result.no; } } });If you want to allow printing but not configuration, remove
org.cups.cupsd.printfrom the list.
🧪 Apply and Test
After placing all
.jsfiles in/etc/polkit-1/priviled.d/, restart the PolicyKit daemon:sudo systemctl restart polkit✅ Test as a non-privileged user:
- Try to shut down the system via the Cinnamon menu
- Attempt to change network settings
- Try to install software
- Attempt to change the system time
- Try to add/remove printers
You should either see:
- Options grayed out
- A password prompt that doesn't accept the user's password
- Or a prompt requiring an administrator password (if you set
auth_admin)
📌 Final Notes
-
Permissions: Ensure all
.jsfiles are owned by root and readable only by root:sudo chown root:root /etc/polkit-1/priviled.d/*.js sudo chmod 644 /etc/polkit-1/priviled.d/*.js -
Session Restart: For changes to take effect, users may need to log out and back in.
-
Validation: Use
journalctl -u polkitto check for any errors in the PolicyKit rules.
By using JavaScript-based PolicyKit rules, you maintain a modern, scalable, and readable configuration that aligns with current Linux best practices and ensures robust access control in your multi-user remote desktop environment.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.