PolicyKit provides an authorization API intended to be used by privileged programs (lqMECHANISMSrq) offering service to unprivileged programs (lqCLIENTSrq) through some form of IPC mechanism such as D-Bus or Unix pipes. In this scenario, the mechanism typically treats the client as untrusted. For every request from a client, the mechanism needs to determine if the request is authorized or if it should refuse to service the client. Using the PolicyKit API, a mechanism can offload this decision to a trusted party: The PolicyKit Authority.
In addition to acting as an authority, PolicyKit allows users to obtain temporary authorization through authenticating either an administrative user or the owner of the session the client belongs to. This is useful for scenarios where a mechanism needs to verify that the operator of the system really is the user or really is an administrative user.
The system architecture of PolicyKit is comprised of the Authority (implemented as a service on the system message bus) and a Authentication Agent per user session (provided and started by the user session e.g. GNOME or KDE). Additionally, PolicyKit supports a number of extension points - specifically, vendors and/or sites can write extensions to completely control authorization policy. In a block diagram, the architecture looks like this:
+-------------------+ | Authentication | | Agent | +-------------------+ | libpolkit-agent-1 | +-------------------+ ^ +--------+ | | Client | +--------------+ +--------+ | ^ | | User Session | | =======================|========================|============= System Context | | | | | +---+ V | /------------\ | | System Bus | | \------------/ | ^ ^ V | | +---------------------+ +--------------+ | | Mechanism | | | +---------------------+ V +----> | libpolkit-gobject-1 | +------------------+ +---------------------+ | org.freedesktop. | | PolicyKit1 | +------------------+ | Backends and | | Extensions | +------------------+
For convenience, the libpolkit-gobject-1 library wraps the PolicyKit D-Bus API using GObject. However, a mechanism can also use the D-Bus API or the pkcheck(1) command to check authorizations.
The libpolkit-agent-1 library provides an abstraction of the native authentication system, e.g. pam(8) and also facilities registration and communication with the PolicyKit D-Bus service.
PolicyKit extensions and authority backends are implemented using the libpolkit-backend-1 library.
See the m[blue]developer documentationm[][2] for more information about using and extending PolicyKit.
See pklocalauthority(8) for information about the Local Authority - the default authority implementation shipped with PolicyKit.
An authentication agent is used to make the user of a session prove that the user of the session really is the user (by authenticating as the user) or an administrative user (by authenticating as a administrator). In order to integrate well with the rest of the user session (e.g. match the look and feel), authentication agents are meant to be provided by the user session that the user uses. For example, an authentication agent may look like this:
+----------------------------------------------------------+ | Authenticate [X] | +----------------------------------------------------------+ | | | [Icon] Authentication is required to run ATA SMART | | self tests | | | | An application is attempting to perform an | | action that requires privileges. Authentication | | as the super user is required to perform this | | action. | | | | Password for root: [_________________________] | | | | [V] Details: | | Drive: ATA INTEL SSDSA2MH08 (045C) | | Device: /dev/sda | | Action: org.fd.devicekit.disks.drive-ata-smart-selftest | | Vendor: The DeviceKit Project | | | | [Cancel] [Authenticate] | +----------------------------------------------------------+
If the system is configured without a root account it may allow you to select the administrative user who is authenticating:
+----------------------------------------------------------+ | Authenticate [X] | +----------------------------------------------------------+ | | | [Icon] Authentication is required to run ATA SMART | | self tests | | | | An application is attempting to perform an | | action that requires privileges. Authentication | | as one of the users below is required to | | perform this action. | | | | [[Face] Patrick Bateman (bateman) [V]] | | | | Password for bateman: [______________________] | | | | [V] Details: | | Drive: ATA INTEL SSDSA2MH08 (045C) | | Device: /dev/sda | | Action: org.fd.devicekit.disks.drive-ata-smart-selftest | | Vendor: The DeviceKit Project | | | | [Cancel] [Authenticate] | +----------------------------------------------------------+
See pklocalauthority(8) on how to set up the local authority implemention for systems without a root account.
A mechanism need to declare a set of lqACTIONSrq in order to use PolicyKit. Actions correspond to operations that clients can request the mechanism to carry out and are defined in XML files that the mechanism installs into the /usr/share/polkit-1/actions directory.
PolicyKit actions are namespaced and can only contain the characters [a-z][0-9].- e.g. lower-case ASCII, digits, period and hyphen. Each XML file can contain more than one action but all actions need to be in the same namespace and the file needs to be named after the namespace and have the extension .policy.
The XML file must have the following doctype declaration
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
The policyconfig element must be present exactly once. Elements that can be used inside policyconfig includes:
vendor
vendor_url
icon_name
action
Elements that can be used inside action includes:
description
message
defaults
Elements that can be used inside defaults includes:
allow_any
allow_inactive
allow_active
Each of the allow_any, allow_inactive and allow_active elements can contain the following values:
no
yes
auth_self
auth_admin
auth_self_keep
auth_admin_keep
annotate
vendor
vendor_url
icon_name
For localization, description and message elements may occur multiple times with different xml:lang attributes.
To list installed PolicyKit actions, use the pkaction(1) command.
Written by David Zeuthen davidz@redhat.com with a lot of help from many others.
Please send bug reports to either the distribution or the polkit-devel mailing list, see the link m[blue]http://lists.freedesktop.org/mailman/listinfo/polkit-develm[] on how to subscribe.
pklocalauthority(8) polkitd(8) pkaction(1), pkcheck(1), pkexec(1),