polkit

From Gentoo Wiki
Jump to: navigation, search

Resources

polkit (formerly PolicyKit) is an authorization API intended to be used by privileged programs (e.g. system daemons) offering services to unprivileged programs.

Description

Privileged programs (in the following called daemons) with polkit support offload the decision as to whether a program is allowed to use some function of the daemon. The daemon keeps an incoming request on hold, asks polkit if the program is authorized, and then allows or denies the request based on polkit's return. The requesting program is not aware of polkit and so needs no polkit support itself. The communication is handled over D-Bus.

Daemons come with polkit action files, which offer some function and define who is authorized. This can be any user, either the active or inactive user. Also they can specify that the user needs to authenticate by entering a password as himself or as admin. These actions do not grant root permission to an entire process, but rather allows a finer level of control of centralized system policy.

The authorization defaults defined by the action files can be refined by rules files. Here you can define who's admin (root or any user in a special group) and add special handling for an action.

Installation

Note
When updating, refer to the polkit upgrade subpage.

Prerequisites

Polkit uses D-Bus and ConsoleKit, so set them up first.

Also, make sure you set CONFIG_FUTEX=y in the kernel. Without this option selected, the polkitd process may generate high CPU.

Software

Portage knows the global policykit USE flag for enabling support for polkit in other packages. Enabling this USE flag will pull in sys-auth/polkit automatically (default for desktop profiles):

FILE /etc/portage/make.conf
USE="... policykit ..."

The USE flags of sys-auth/polkit are:

USE flags for sys-auth/polkit Policy framework for controlling privileges for system-wide services

examples Install examples, usually source code global
gtk Add support for x11-libs/gtk+ (The GIMP Toolkit) global
introspection Add support for GObject based introspection global
jit Enable just-in-time compilation for improved performance. May prevent use of some PaX memory protection features in Gentoo Hardened. global
kde Add support for KDE (K Desktop Environment) global
nls Add Native Language Support (using gettext - GNU locale utilities) global
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip global
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur global
systemd Use sys-apps/systemd instead of sys-auth/consolekit for session tracking local
test Workaround to pull in packages needed to run with FEATURES=test. Portage-2.1.2 handles this internally, so don't set it in make.conf/package.use anymore global

After setting this you want to update your system so the changes take effect:

root #emerge --ask --changed-use --deep @world

Configuration

The actions files are in /usr/share/polkit-1/actions, the rules files are in /usr/share/polkit-1/rules.d and /etc/polkit-1/rules.d.

Rules

Rules redefine who's authorized for an action. The rules files begin with a number and are processed in lexical order. The first file with a matching rule is used. Own files should have a low number, like 10. The filenames have the .rules suffix.

For example, to let the users of the wheel group also perform functions as administrators, create the following file:

FILE /etc/polkit-1/rules.d/10-admin.rules
polkit.addAdminRule(function(action, subject) {
    return ["unix-group:wheel"];
});

To allow user larry to mount disks, create the following file:

FILE /etc/polkit-1/rules.d/10-udisks.rules
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks2.filesystem-mount" &&
        subject.user == "larry") {
        return "yes";
    }
});

See man polkit for more information.

Usage

Show all available actions:

user $pkaction

Show details about the given action:

user $pkaction --verbose --action-id ACTION

List all temporary authorizations for the current session:

user $pkcheck --list-temp

Runs the given program with the user rights of the given user:

user $pkexec --user USER PROGRAM

For more information see the man pages, e.g. for pkaction: man pkaction

Troubleshooting