polkit

Also known as: PolicyKit

On this page 7

polkit, formerly PolicyKit, is an authorization framework for Linux that decides whether an unprivileged process may ask a privileged system service to perform a specific action, such as mounting a disk, changing the network configuration or rebooting the machine. In the domain of Linux permissions it complements file permissions and sudo by controlling access to services rather than to files or whole commands.

Instead of running an entire program as root, polkit lets a small privileged service perform one well-defined operation on behalf of the user, after checking a policy that may allow it, deny it or require the user or an administrator to authenticate first.

How polkit authorizes an action

polkit works through a three-party model: a subject that wants something done, a mechanism that can do it with privileges, and the polkitd authority daemon that decides. Communication between the parties usually runs over the D-Bus system bus.

A typical sequence looks like this. A desktop application asks a mechanism such as systemd-logind or NetworkManager to perform an action. The mechanism asks polkitd whether the calling process is authorized for that action identifier. If authentication is required, polkitd contacts the session’s authentication agent, which shows a password dialog, and only then returns its answer.

The roles in this exchange are summarized below.

ComponentRoleExample
SubjectUnprivileged process requesting an actionA file manager or a CLI tool
MechanismPrivileged service that performs the actionudisksd, systemd-logind, NetworkManager
polkitdAuthority that evaluates policyRuns as a dedicated system user
Authentication agentAsks the user for credentialsDesktop dialog or pkttyagent in a terminal
ActionNamed operation with default rulesorg.freedesktop.login1.reboot
Components of the polkit model

Actions, implicit authorizations and rules

Every privileged operation is declared as an action in an XML policy file under /usr/share/polkit-1/actions/. Each action carries implicit authorizations that apply by default, specified separately for three kinds of subjects: any client, inactive local sessions and active local sessions.

ValueMeaningTypical use
yesAllowed without authenticationSuspend for the active local user
noAlways deniedRemote sessions for sensitive actions
auth_selfUser must enter own passwordMounting an internal disk
auth_adminAn administrator must authenticateChanging system time or users
auth_self_keepOwn password, cached brieflyRepeated package operations
auth_admin_keepAdministrator password, cached brieflySeveral firewall changes in a row
Implicit authorization values in polkit actions

Administrators override these defaults with JavaScript rules files in /etc/polkit-1/rules.d/. Rules are evaluated in lexical order of file names, across both /etc and /usr/share, and the first rule returning a result wins. The older .pkla INI-style files of the local authority backend were used by polkit versions before 0.106 and still appear on some long-term-support distributions.

A rule usually tests the action identifier and a property of the subject, most often group membership. For example, a rule can return polkit.Result.YES when the action ID starts with org.freedesktop.udisks2. and the subject is in the storage group, which grants passwordless disk mounting to that group only.

polkit compared with sudo and file permissions

polkit, sudo and traditional file permissions all control what a user may do, but they operate at different levels of granularity. Confusing them leads to configurations that are either too permissive or puzzling to debug.

MechanismWhat it controlsGranularityConfiguration
polkitRequests to privileged servicesPer action identifierRules in rules.d
sudoRunning commands as another userPer command and argumentssudoers via visudo
File permissionsRead, write and execute on filesPer file, owner and groupchmod, chown, Linux ACL
setuidProgram always runs as its ownerWhole executableFile mode bit
How polkit differs from related Linux permission mechanisms

The key difference is least privilege. With sudo, the command runs as root in full; with polkit, only the service code for one operation holds privileges, and the requesting program stays unprivileged. The pkexec utility offers a sudo-like way to run a whole program as another user through polkit, but it is a setuid binary and carries comparable risks.

Inspecting and configuring polkit

Administrators use a small set of command-line tools to see which actions exist, test decisions and supply authentication outside a graphical session.

  • pkaction lists registered actions; with --verbose it shows the implicit authorizations of each.
  • pkcheck asks polkitd whether a given process is authorized for an action, which is useful in scripts and debugging.
  • pkttyagent provides a text-mode authentication agent for SSH sessions and servers without a desktop.
  • journalctl -u polkit shows the daemon log, including errors in JavaScript rules files.

On headless servers, administrators often see an authentication failure without any prompt, because no agent is registered for the session. Running the command through sudo, starting pkttyagent or writing a targeted rule for an administrative group such as wheel or sudo resolves the problem.

Security considerations and common mistakes

Because polkit grants access to root-level operations, errors in rules or in polkit itself have high impact. The most widely known example is CVE-2021-4034, called PwnKit, a memory corruption flaw in pkexec that allowed any local user to gain root on most distributions until it was patched in January 2022.

MistakeConsequenceFix
Broad rule matching all actionsGroup gets near-root powerMatch specific action IDs
Editing files in /usr/shareChanges lost on package updatePlace rules in /etc/polkit-1/rules.d
Syntax error in a rules fileRule silently ignoredCheck the polkit journal after edits
Unpatched pkexecLocal privilege escalationUpdate polkit or remove the setuid bit
Assuming sudoers controls GUI actionsUnexpected prompts or accessReview polkit rules separately
Typical polkit mistakes and their fixes

A sound policy grants the narrowest action set to the smallest group, keeps auth_admin for system-wide changes and is reviewed whenever new services are installed, because each package can add its own actions.

The simple explanation

polkit is like a receptionist at a secure office. Regular programs cannot walk into the back rooms where important system work is done. Instead, they ask a trusted staff member, such as the service that manages disks, to do one specific task for them.

Before the staff member acts, the receptionist checks a rulebook. Some requests are fine right away, some need you to show your ID by typing a password, and some are refused. The benefit is that programs get exactly the help they need and nothing more.

How it is used in practice

A university computer lab runs 40 Linux workstations shared by students. The lab administrator wants students to mount USB drives and shut down machines at the end of a session, but not to change network settings, install packages or manage other users.

The administrator places one rules file in /etc/polkit-1/rules.d/ that returns YES for the udisks2 mount actions and for login1 power-off when the subject is in a students group and in an active local session. Every other action keeps its auth_admin default, so attempts to alter network or package settings trigger an administrator password prompt that students cannot satisfy.

No student receives sudo rights, and the outcome is a lab where routine tasks work without passwords while system configuration stays protected. When a polkit security update is released, the administrator patches all workstations centrally on the same day.