'\" t
.\" Title: polkit
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot
.\" Date: February 2021
.\" Manual: polkit
.\" Source: polkit
.\" Language: English
.\"
.TH "POLKIT" "8" "February 2021" "polkit" "polkit"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
polkit \- Authorization Manager
.SH "OVERVIEW"
.PP
polkit provides an authorization API intended to be used by privileged programs (\(lqMECHANISMS\(rq) offering service to unprivileged programs (\(lqSUBJECTS\(rq) often through some form of inter\-process communication mechanism\&. In this scenario, the mechanism typically treats the subject as untrusted\&. For every request from a subject, the mechanism needs to determine if the request is authorized or if it should refuse to service the subject\&. Using the polkit APIs, a mechanism can offload this decision to a trusted party: The polkit authority\&.
.PP
The polkit authority is implemented as an system daemon,
\fBpolkitd\fR(8), which itself has little privilege as it is running as the
\fIpolkitd\fR
system user\&. Mechanisms, subjects and authentication agents communicate with the authority using the system message bus\&.
.PP
In addition to acting as an authority, polkit 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\&.
.SH "SYSTEM ARCHITECTURE"
.PP
The system architecture of polkit is comprised of the
\fIAuthority\fR
(implemented as a service on the system message bus) and an
\fIAuthentication Agent\fR
per user session (provided and started by the user\*(Aqs graphical environment)\&.
\fIActions\fR
are defined by applications\&. Vendors, sites and system administrators can control authorization policy through
\fIAuthorization Rules\fR\&.
.sp
.RS 4
[IMAGE]\&\s-2\u[1]\d\s+2
.sp
.if n \{\
.RS 4
.\}
.nf
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| Authentication |
| Agent |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| libpolkit\-agent\-1 |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
^ +\-\-\-\-\-\-\-\-\-+
| | Subject |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ +\-\-\-\-\-\-\-\-\-+
| ^
| |
User Session | |
=======================|========================|=============
System Context | |
| |
| +\-\-\-+
V |
/\-\-\-\-\-\-\-\-\-\-\-\-\e |
| System Bus | |
\e\-\-\-\-\-\-\-\-\-\-\-\-/ |
^ ^ V
| | +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ | | Mechanism |
| | +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
V +\-\-\-\-> | libpolkit\-gobject\-1 |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| polkitd(8) |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| org\&.freedesktop\&. |
| PolicyKit1 |<\-\-\-\-\-\-\-\-\-+
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ |
^ |
| +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| | /usr/share/polkit\-1/actions/*\&.policy |
| +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
|
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| /etc/polkit\-1/rules\&.d/*\&.rules |
| /usr/share/polkit\-1/rules\&.d/*\&.rules |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
.fi
.if n \{\
.RE
.\}
.RE
.PP
For convenience, the
libpolkit\-gobject\-1
library wraps the polkit D\-Bus API and is usable from any C/C++ program as well as higher\-level languages supporting
\m[blue]\fBGObjectIntrospection\fR\m[]\&\s-2\u[2]\d\s+2
such as JavaScript and Python\&. A mechanism can also use the D\-Bus API or the
\fBpkcheck\fR(1)
command to check authorizations\&. The
libpolkit\-agent\-1
library provides an abstraction of the native authentication system, e\&.g\&.
\fBpam\fR(8)
and also facilities for registration and communication with the polkit D\-Bus service\&.
.PP
See the
\m[blue]\fBdeveloper documentation\fR\m[]\&\s-2\u[3]\d\s+2
for more information about writing polkit applications\&.
.SH "AUTHENTICATION AGENTS"
.PP
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 an 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:
.sp
.RS 4
[IMAGE]\&\s-2\u[4]\d\s+2
.sp
.if n \{\
.RS 4
.\}
.nf
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| |
| [Icon] Authentication required |
| |
| Authentication is required to format INTEL |
| SSDSA2MH080G1GC (/dev/sda) |
| |
| Administrator |
| |
| Password: [__________________________________] |
| |
| [Cancel] [Authenticate] |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
.fi
.if n \{\
.RE
.\}
.RE
.PP
If the system is configured without a
\fIroot\fR
account, it may prompt for a specific user designated as the administrative user:
.sp
.RS 4
[IMAGE]\&\s-2\u[5]\d\s+2
.sp
.if n \{\
.RS 4
.\}
.nf
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
| |
| [Icon] Authentication required |
| |
| Authentication is required to format INTEL |
| SSDSA2MH080G1GC (/dev/sda) |
| |
| [Icon] David Zeuthen |
| |
| Password: [__________________________________] |
| |
| [Cancel] [Authenticate] |
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
.fi
.if n \{\
.RE
.\}
.RE
.PP
Applications that do not run under a desktop environment (for example, if launched from an
\fBssh\fR(1)
login) may not have an authentication agent associated with them\&. Such applications may use the
PolkitAgentTextListener
type or the
\fBpkttyagent\fR(1)
helper so the user can authenticate using a textual interface\&.
.SH "DECLARING ACTIONS"
.PP
A mechanism needs to declare a set of
\fIactions\fR
in order to use polkit\&. 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\&.
.PP
polkit actions are namespaced and can only contain the characters "[A\-Z][a\-z][0\-9]\&.\-", e\&.g\&. 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\&.
.PP
The XML file must have the following doctype declaration
.sp
.if n \{\
.RS 4
.\}
.nf
.fi
.if n \{\
.RE
.\}
.PP
The
\fIpolicyconfig\fR
element must be present exactly once\&. Elements that can be used inside
\fIpolicyconfig\fR
includes:
.PP
\fIvendor\fR
.RS 4
The name of the project or vendor that is supplying the actions in the XML document\&. Optional\&.
.RE
.PP
\fIvendor_url\fR
.RS 4
A URL to the project or vendor that is supplying the actions in the XML document\&. Optional\&.
.RE
.PP
\fIicon_name\fR
.RS 4
An icon representing the project or vendor that is supplying the actions in the XML document\&. The icon name must adhere to the
\m[blue]\fBFreedesktop\&.org Icon Naming Specification\fR\m[]\&\s-2\u[6]\d\s+2\&. Optional\&.
.RE
.PP
\fIaction\fR
.RS 4
Declares an action\&. The action name is specified using the
id
attribute and can only contain the characters "[A\-Z][a\-z][0\-9]\&.\-
", e\&.g\&. ASCII, digits, period and hyphen\&.
.RE
.PP
Elements that can be used inside
\fIaction\fR
include:
.PP
\fIdescription\fR
.RS 4
A human readable description of the action, e\&.g\&.
\(lqInstall unsigned software\(rq\&.
.RE
.PP
\fImessage\fR
.RS 4
A human readable message displayed to the user when asking for credentials when authentication is needed, e\&.g\&.
\(lqInstalling unsigned software requires authentication\(rq\&.
.RE
.PP
\fIdefaults\fR
.RS 4
This element is used to specify implicit authorizations for clients\&. Elements that can be used inside
\fIdefaults\fR
include:
.PP
\fIallow_any\fR
.RS 4
Implicit authorizations that apply to any client\&. Optional\&.
.RE
.PP
\fIallow_inactive\fR
.RS 4
Implicit authorizations that apply to clients in inactive sessions on local consoles\&. Optional\&.
.RE
.PP
\fIallow_active\fR
.RS 4
Implicit authorizations that apply to clients in active sessions on local consoles\&. Optional\&.
.RE
.sp
Each of the
\fIallow_any\fR,
\fIallow_inactive\fR
and
\fIallow_active\fR
elements can contain the following values:
.PP
no
.RS 4
Not authorized\&.
.RE
.PP
yes
.RS 4
Authorized\&.
.RE
.PP
auth_self
.RS 4
Authentication by the owner of the session that the client originates from is required\&. Note that this is not restrictive enough for most uses on multi\-user systems;
auth_admin* is generally recommended\&.
.RE
.PP
auth_admin
.RS 4
Authentication by an administrative user is required\&.
.RE
.PP
auth_self_keep
.RS 4
Like
auth_self
but the authorization is kept for a brief period (e\&.g\&. five minutes)\&. The warning about
auth_self
above applies likewise\&.
.RE
.PP
auth_admin_keep
.RS 4
Like
auth_admin
but the authorization is kept for a brief period (e\&.g\&. five minutes)\&.
.RE
.RE
.PP
\fIannotate\fR
.RS 4
Used for annotating an action with a key/value pair\&. The key is specified using the
key
attribute and the value is specified using the
value
attribute\&. This element may appear zero or more times\&. See below for known annotations\&.
.RE
.PP
\fIvendor\fR
.RS 4
Used for overriding the vendor on a per\-action basis\&. Optional\&.
.RE
.PP
\fIvendor_url\fR
.RS 4
Used for overriding the vendor URL on a per\-action basis\&. Optional\&.
.RE
.PP
\fIicon_name\fR
.RS 4
Used for overriding the icon name on a per\-action basis\&. Optional\&.
.RE
.PP
For localization,
\fIdescription\fR
and
\fImessage\fR
elements may occur multiple times with different
xml:lang
attributes\&.
.PP
To list installed polkit actions, use the
\fBpkaction\fR(1)
command\&.
.SS "Known annotations"
.PP
The
org\&.freedesktop\&.policykit\&.exec\&.path
annotation is used by the
\fBpkexec\fR
program shipped with polkit \- see the
\fBpkexec\fR(1)
man page for details\&.
.PP
The
org\&.freedesktop\&.policykit\&.imply
annotation (its value is a string containing a space\-separated list of action identifiers) can be used to define
\fImeta actions\fR\&. The way it works is that if a subject is authorized for an action with this annotation, then it is also authorized for any action specified by the annotation\&. A typical use of this annotation is when defining an UI shell with a single lock button that should unlock multiple actions from distinct mechanisms\&.
.PP
The
org\&.freedesktop\&.policykit\&.owner
annotation can be used to define a set of users who can query whether a client is authorized to perform this action\&. If this annotation is not specified, then only root can query whether a client running as a different user is authorized for an action\&. The value of this annotation is a string containing a space\-separated list of
PolkitIdentity
entries, for example
"unix\-user:42 unix\-user:colord"\&. A typical use of this annotation is for a daemon process that runs as a system user rather than root\&.
.SH "AUTHORIZATION RULES"
.PP
\fBpolkitd\fR
reads
\&.rules
files from the
/etc/polkit\-1/rules\&.d
and
/usr/share/polkit\-1/rules\&.d
directories by sorting the files in lexical order based on the basename on each file (if there\*(Aqs a tie, files in
/etc
are processed before files in
/usr)\&. For example, for the following four files, the order is
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
/etc/polkit\-1/rules\&.d/10\-auth\&.rules
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
/usr/share/polkit\-1/rules\&.d/10\-auth\&.rules
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
/etc/polkit\-1/rules\&.d/15\-auth\&.rules
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
/usr/share/polkit\-1/rules\&.d/20\-auth\&.rules
.RE
.PP
Both directories are monitored so if a rules file is changed, added or removed, existing rules are purged and all files are read and processed again\&. Rules files are written in the
\m[blue]\fBJavaScript\fR\m[]\&\s-2\u[7]\d\s+2
programming language and interface with
\fBpolkitd\fR
through the global
polkit
object (of type
\fBPolkit\fR)\&.
.PP
While the JavaScript interpreter used in particular versions of polkit may support non\-standard features (such as the
\fIlet\fR
keyword), authorization rules must conform to
\m[blue]\fBECMA\-262 edition 5\fR\m[]\&\s-2\u[8]\d\s+2
(in other words, the JavaScript interpreter used may change in future versions of polkit)\&.
.PP
Authorization rules are intended for two specific audiences
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
System Administrators
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Special\-purpose Operating Systems / Environments
.RE
.PP
and those audiences only\&. In particular, applications, mechanisms and general\-purpose operating systems must never include any authorization rules\&.
.SS "The Polkit type"
.PP
The following methods are available on the
polkit
object:
.HP \w'void\ addRule('u
.BI "void addRule(polkit\&.Result\ function(" "action" ",\ " "subject" ")\ {\&.\&.\&.});"
.HP \w'void\ addAdminRule('u
.BI "void addAdminRule(string[]\ function(" "action" ",\ " "subject" ")\ {\&.\&.\&.});"
.HP \w'void\ log('u
.BI "void log(string\ " "message" ");"
.HP \w'string\ spawn('u
.BI "string spawn(string[]\ " "argv" ");"
.PP
The
\fBaddRule()\fR
method is used for adding a function that may be called whenever an authorization check for
\fIaction\fR
and
\fIsubject\fR
is performed\&. Functions are called in the order they have been added until one of the functions returns a value\&. Hence, to add an authorization rule that is processed before other rules, put it in a file in
/etc/polkit\-1/rules\&.d
with a name that sorts before other rules files, for example
00\-early\-checks\&.rules\&. Each function should return a value from
polkit\&.Result
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.Result = {
NO : "no",
YES : "yes",
AUTH_SELF : "auth_self",
AUTH_SELF_KEEP : "auth_self_keep",
AUTH_ADMIN : "auth_admin",
AUTH_ADMIN_KEEP : "auth_admin_keep",
NOT_HANDLED : null
};
.fi
.if n \{\
.RE
.\}
.PP
corresponding to the values that can be used as defaults\&. If the function returns
\fBpolkit\&.Result\&.NOT_HANDLED\fR,
\fBnull\fR,
\fBundefined\fR
or does not return a value at all, the next user function is tried\&.
.PP
Keep in mind that if
\fBpolkit\&.Result\&.AUTH_SELF_KEEP\fR
or
\fBpolkit\&.Result\&.AUTH_ADMIN_KEEP\fR
is returned, authorization checks for the same action identifier and subject will succeed (that is, return
\fBpolkit\&.Result\&.YES\fR) for the next brief period (e\&.g\&. five minutes)
\fIeven\fR
if the variables passed along with the check are different\&. Therefore, if the result of an authorization rule depend on such variables, it should not use the
\fB"*_KEEP"\fR
constants (if similar functionality is required, the authorization rule can easily implement temporary authorizations using the
\m[blue]\fB\fBDate\fR\fR\m[]\&\s-2\u[9]\d\s+2
type for timestamps)\&.
.PP
The
\fBaddAdminRule()\fR
method is used for adding a function that may be called whenever administrator authentication is required\&. The function is used to specify what identities may be used for administrator authentication for the authorization check identified by
\fIaction\fR
and
\fIsubject\fR\&. Functions added are called in the order they have been added until one of the functions returns a value\&. Each function should return an array of strings where each string is of the form
"unix\-group:",
"unix\-netgroup:"
or
"unix\-user:"\&. If the function returns
\fBnull\fR,
\fBundefined\fR
or does not return a value at all, the next function is tried\&.
.PP
There is no guarantee that a function registered with
\fBaddRule()\fR
or
\fBaddAdminRule()\fR
is ever called \- for example an early rules file could register a function that always returns a value, hence ensuring that functions added later are never called\&.
.PP
If user\-provided code takes a long time to execute, an exception will be thrown which normally results in the function being terminated (the current limit is 15 seconds)\&. This is used to catch runaway scripts\&. If the duktape JavaScript backend is compiled in, instead of mozjs, no exception will be thrown\(emthe script will be killed right away (same timeout)\&.
.PP
The
\fBspawn()\fR
method spawns an external helper identified by the argument vector
\fIargv\fR
and waits for it to terminate\&. If an error occurs or the helper doesn\*(Aqt exit normally with exit code 0, an exception is thrown\&. If the helper does not exit within 10 seconds, it is killed\&. Otherwise, the program\*(Aqs
\fIstandard output\fR
is returned as a string\&. The
\fBspawn()\fR
method should be used sparingly as helpers may take a very long or indeterminate amount of time to complete and no other authorization check can be handled while the helper is running\&. Note that the spawned programs will run as the unprivileged
\fIpolkitd\fR
system user\&.
.PP
The
\fBlog()\fR
method writes the given
\fImessage\fR
to the system logger prefixed with the JavaScript filename and line number\&. Log entries are emitted using the
\fBLOG_AUTHPRIV\fR
flag meaning that the log entries usually ends up in the file
/var/log/secure\&. The
\fBlog()\fR
method is usually only used when debugging rules\&. The
\fBAction\fR
and
\fBSubject\fR
types has suitable
\fBtoString()\fR
methods defined for easy logging, for example,
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addRule(function(action, subject) {
if (action\&.id == "org\&.freedesktop\&.policykit\&.exec") {
polkit\&.log("action=" + action);
polkit\&.log("subject=" + subject);
}
});
.fi
.if n \{\
.RE
.\}
.PP
will produce the following when the user runs \*(Aqpkexec \-u bateman bash \-i\*(Aq from a shell:
.sp
.if n \{\
.RS 4
.\}
.nf
May 24 14:28:50 thinkpad polkitd[32217]: /etc/polkit\-1/rules\&.d/10\-test\&.rules:3: action=[Action id=\*(Aqorg\&.freedesktop\&.policykit\&.exec\*(Aq command_line=\*(Aq/usr/bin/bash \-i\*(Aq program=\*(Aq/usr/bin/bash\*(Aq user=\*(Aqbateman\*(Aq user\&.gecos=\*(AqPatrick Bateman\*(Aq user\&.display=\*(AqPatrick Bateman (bateman)\*(Aq]
May 24 14:28:50 thinkpad polkitd[32217]: /etc/polkit\-1/rules\&.d/10\-test\&.rules:4: subject=[Subject pid=1352 user=\*(Aqdavidz\*(Aq groups=davidz,wheel, seat=\*(Aqseat0\*(Aq session=\*(Aq1\*(Aq local=true active=true]
.fi
.if n \{\
.RE
.\}
.SS "The Action type"
.PP
The
\fIaction\fR
parameter passed to user functions is an object with information about the action being checked\&. It is of type
\fBAction\fR
and has the following attribute:
.PP
\fBstring\fR id
.RS 4
The action identifier, for example
\fIorg\&.freedesktop\&.policykit\&.exec\fR\&.
.RE
.PP
The following methods are available on the
\fBAction\fR
type:
.HP \w'string\ lookup('u
.BI "string lookup(string\ " "key" ");"
.PP
The
\fBlookup()\fR
method is used to lookup the polkit variables passed from the mechanism\&. For example, the
\fBpkexec\fR(1)
mechanism sets the variable
\fIprogram\fR
which can be obtained in JavaScript using the expression
action\&.lookup("program")\&. If there is no value for the given
\fIkey\fR, then
\fBundefined\fR
is returned\&.
.PP
Consult the documentation for each mechanism for what variables are available for each action\&.
.SS "The Subject type"
.PP
The
\fIsubject\fR
parameter passed to user functions is an object with information about the process being checked\&. It is of type
\fBSubject\fR
and has the following attributes
.PP
\fBint\fR pid
.RS 4
The process id\&.
.RE
.PP
\fBstring\fR user
.RS 4
The user name\&.
.RE
.PP
\fBstring[]\fR groups
.RS 4
Array of groups that
\fIuser\fR
user belongs to\&.
.RE
.PP
\fBstring\fR seat
.RS 4
The seat that the subject is associated with \- blank if not on a local seat\&.
.RE
.PP
\fBstring\fR session
.RS 4
The session that the subject is associated with\&.
.RE
.PP
\fBstring\fR system_unit
.RS 4
The systemd unit that the subject\*(Aqs process is part of (if any)\&. Note that this can only match on system units, as user units can be created with any name without privileges (unlike system units which require root to create)\&. A process running in a user unit will return the user session unit in this attribute (e\&.g\&.:
user\-1000\&.service)\&.
.RE
.PP
\fBboolean\fR local
.RS 4
Set to
\fBtrue\fR
only if seat is local\&.
.RE
.PP
\fBboolean\fR no_new_privileges
.RS 4
Set only if
\fIsystem_unit\fR
is not empty, and set to
\fBtrue\fR
only if the referenced systemd service unit has the
\fINoNewPrivileges=\fR
setting enabled\&. This ensures that the process cannot gain any new privileges via executing setuid binaries\&.
.RE
.PP
\fBboolean\fR active
.RS 4
Set to
\fBtrue\fR
only if the session is active\&.
.RE
.PP
The following methods are available on the
\fBSubject\fR
type:
.HP \w'boolean\ isInGroup('u
.BI "boolean isInGroup(string\ " "groupName" ");"
.HP \w'boolean\ isInNetGroup('u
.BI "boolean isInNetGroup(string\ " "netGroupName" ");"
.PP
The
\fBisInGroup()\fR
method can be used to check if the subject is in a given group and
\fBisInNetGroup()\fR
can be used to check if the subject is in a given netgroup\&.
.SS "Authorization Rules Examples"
.PP
Allow all users in the
admin
group to perform user administration without changing policy for other users:
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addRule(function(action, subject) {
if (action\&.id == "org\&.freedesktop\&.accounts\&.user\-administration" &&
subject\&.isInGroup("admin")) {
return polkit\&.Result\&.YES;
}
});
.fi
.if n \{\
.RE
.\}
.PP
Define administrative users to be the users in the
wheel
group:
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addAdminRule(function(action, subject) {
return ["unix\-group:wheel"];
});
.fi
.if n \{\
.RE
.\}
.PP
Forbid users in group
children
to change hostname configuration (that is, any action with an identifier starting with
org\&.freedesktop\&.hostname1\&.) and allow anyone else to do it after authenticating as themselves:
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addRule(function(action, subject) {
if (action\&.id\&.indexOf("org\&.freedesktop\&.hostname1\&.") == 0) {
if (subject\&.isInGroup("children")) {
return polkit\&.Result\&.NO;
} else {
return polkit\&.Result\&.AUTH_SELF_KEEP;
}
}
});
.fi
.if n \{\
.RE
.\}
.PP
Run an external helper to determine if the current user may reboot the system:
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addRule(function(action, subject) {
if (action\&.id\&.indexOf("org\&.freedesktop\&.login1\&.reboot") == 0) {
try {
// user\-may\-reboot exits with success (exit code 0)
// only if the passed username is authorized
polkit\&.spawn(["/opt/company/bin/user\-may\-reboot",
subject\&.user]);
return polkit\&.Result\&.YES;
} catch (error) {
// Nope, but do allow admin authentication
return polkit\&.Result\&.AUTH_ADMIN;
}
}
});
.fi
.if n \{\
.RE
.\}
.PP
The following example shows how the authorization decision can depend on variables passed by the
\fBpkexec\fR(1)
mechanism:
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addRule(function(action, subject) {
if (action\&.id == "org\&.freedesktop\&.policykit\&.exec" &&
action\&.lookup("program") == "/usr/bin/cat") {
return polkit\&.Result\&.AUTH_ADMIN;
}
});
.fi
.if n \{\
.RE
.\}
.PP
The following example shows another use of variables passed from the mechanism\&. In this case, the mechanism is
\m[blue]\fBUDisks\fR\m[]\&\s-2\u[10]\d\s+2
which defines a set of
\m[blue]\fBactions and variables\fR\m[]\&\s-2\u[11]\d\s+2
that is used to match on:
.sp
.if n \{\
.RS 4
.\}
.nf
// Allow users in group \*(Aqengineers\*(Aq to perform any operation on
// some drives without having to authenticate
//
polkit\&.addRule(function(action, subject) {
if (action\&.id\&.indexOf("org\&.freedesktop\&.udisks2\&.") == 0 &&
action\&.lookup("drive\&.vendor") == "SEAGATE" &&
action\&.lookup("drive\&.model") == "ST3300657SS" &&
subject\&.isInGroup("engineers")) {
return polkit\&.Result\&.YES;
}
}
});
.fi
.if n \{\
.RE
.\}
.PP
Allow all processes running as part of the
admin\&.service
systemd system unit to perform user administration, as long as they cannot gain new privileges:
.sp
.if n \{\
.RS 4
.\}
.nf
polkit\&.addRule(function(action, subject) {
if (action\&.id == "org\&.freedesktop\&.accounts\&.user\-administration" &&
subject\&.system_unit == "admin\&.service" &&
subject\&.no_new_privileges) {
return polkit\&.Result\&.YES;
}
});
.fi
.if n \{\
.RE
.\}
.SH "AUTHOR"
.PP
Written by David Zeuthen
with a lot of help from many others\&.
.SH "BUGS"
.PP
Please send bug reports to either the distribution or the polkit\-devel mailing list, see the link
\m[blue]\fB\%https://gitlab.freedesktop.org/polkit/polkit/-/issues/\fR\m[]
on how to subscribe\&.
.SH "SEE ALSO"
.PP
\fBpolkitd\fR(8),
\fBpkaction\fR(1),
\fBpkcheck\fR(1),
\fBpkexec\fR(1),
\fBpkttyagent\fR(1)
.SH "NOTES"
.IP " 1." 4
/usr/share/gtk-doc/html/polkit-1/polkit-architecture.png
.IP " 2." 4
GObjectIntrospection
.RS 4
\%https://live.gnome.org/GObjectIntrospection
.RE
.IP " 3." 4
developer documentation
.RS 4
\%http://www.freedesktop.org/software/polkit/docs/latest/
.RE
.IP " 4." 4
/usr/share/gtk-doc/html/polkit-1/polkit-authentication-agent-example.png
.IP " 5." 4
/usr/share/gtk-doc/html/polkit-1/polkit-authentication-agent-example-wheel.png
.IP " 6." 4
Freedesktop.org Icon Naming Specification
.RS 4
\%http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
.RE
.IP " 7." 4
JavaScript
.RS 4
\%http://en.wikipedia.org/wiki/JavaScript
.RE
.IP " 8." 4
ECMA-262 edition 5
.RS 4
\%http://en.wikipedia.org/wiki/ECMAScript#ECMAScript.2C_5th_Edition
.RE
.IP " 9." 4
\fBDate\fR
.RS 4
\%https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
.RE
.IP "10." 4
UDisks
.RS 4
\%http://udisks.freedesktop.org/docs/latest/udisks.8.html
.RE
.IP "11." 4
actions and variables
.RS 4
\%http://udisks.freedesktop.org/docs/latest/udisks-polkit-actions.html
.RE