1PKEXEC(1) pkexec PKEXEC(1)
2
3
4
6 pkexec - Execute a command as another user
7
9 pkexec [--version] [--disable-internal-agent] [--help]
10
11 pkexec [--user username] PROGRAM [ARGUMENTS...]
12
14 pkexec allows an authorized user to execute PROGRAM as another user. If
15 username is not specified, then the program will be executed as the
16 administrative super user, root.
17
19 Upon successful completion, the return value is the return value of
20 PROGRAM. If the calling process is not authorized or an authorization
21 could not be obtained through authentication or an error occured,
22 pkexec exits with a return value of 127.
23
25 pkexec, like any other PolicyKit application, will use the
26 authentication agent registered for the calling process. However, if no
27 authentication agent is available, then pkexec will register its own
28 textual authentication agent. This behavior can be turned off by
29 passing the --disable-internal-agent option.
30
32 Executing a program as another user is a privileged operation. By
33 default the required authorization (See the section called “REQUIRED
34 AUTHORIZATIONS”) requires administrator authentication. In addition,
35 the authentication dialog presented to the user will display the full
36 path to the program to be executed so the user is aware of what will
37 happen:
38
39 [IMAGE][1]
40
41 +----------------------------------------------------------+
42 | Authenticate [X] |
43 +----------------------------------------------------------+
44 | |
45 | [Icon] Authentication is needed to run `/bin/bash' |
46 | as the super user |
47 | |
48 | An application is attempting to perform an |
49 | action that requires privileges. Authentication |
50 | as the super user is required to perform this |
51 | action. |
52 | |
53 | Password for root: [_________________________] |
54 | |
55 | [V] Details: |
56 | Command: /bin/bash |
57 | Run As: Super User (root) |
58 | Action: org.freedesktop.policykit.exec |
59 | Vendor: The PolicyKit Project |
60 | |
61 | [Cancel] [Authenticate] |
62 +----------------------------------------------------------+
63
64 The environment that PROGRAM will run it, will be set to a minimal
65 known and safe environment in order to avoid injecting code through
66 LD_LIBRARY_PATH or similar mechanisms. In addition the PKEXEC_UID
67 environment variable is set to the user id of the process invoking
68 pkexec. As a result, pkexec will not allow you to run e.g. X11
69 applications as another user since the $DISPLAY environment variable is
70 not set.
71
73 By default, the org.freedesktop.policykit.exec authorization is
74 required unless an action definition file is present for the program in
75 question. To require another authorization, it can be specified using
76 the org.freedesktop.policykit.exec.path annotation on an action (See
77 the section called “EXAMPLE” for details).
78
80 To specify what kind of authorization is needed to execute the program
81 /usr/bin/pk-example-frobnicate as another user, simply write an action
82 definition file like this
83
84 <?xml version="1.0" encoding="UTF-8"?>
85 <!DOCTYPE policyconfig PUBLIC
86 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
87 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
88 <policyconfig>
89
90 <vendor>Examples for the PolicyKit Project</vendor>
91 <vendor_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor_url>
92
93 <action id="org.freedesktop.policykit.example.pkexec.run-frobnicate">
94 <description>Run the PolicyKit example program Frobnicate</description>
95 <description xml:lang="da">Kør PolicyKit eksemplet Frobnicate</description>
96 <message>Authentication is required to run the PolicyKit example program Frobnicate</message>
97 <message xml:lang="da">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate</message>
98 <icon_name>audio-x-generic</icon_name>
99 <defaults>
100 <allow_any>no</allow_any>
101 <allow_inactive>no</allow_inactive>
102 <allow_active>auth_self_keep</allow_active>
103 </defaults>
104 <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pk-example-frobnicate</annotate>
105 </action>
106
107 </policyconfig>
108
109 and drop it in the /usr/share/polkit-1/actions directory under a
110 suitable name (e.g. matching the namespace of the action). Note that in
111 addition to specifying the program, the authentication message,
112 description, icon and defaults can be specified. For example, for the
113 action defined above, the following authentication dialog will be
114 shown:
115
116 [IMAGE][2]
117
118 +----------------------------------------------------------+
119 | Authenticate [X] |
120 +----------------------------------------------------------+
121 | |
122 | [Icon] Authentication is required to run the PolicyKit |
123 | example program Frobnicate |
124 | |
125 | An application is attempting to perform an |
126 | action that requires privileges. Authentication |
127 | is required to perform this action. |
128 | |
129 | Password: [__________________________________] |
130 | |
131 | [V] Details: |
132 | Command: /usr/bin/pk-example-frobnicate |
133 | Run As: Super User (root) |
134 | Action: org.fd.pk.example.pkexec.run-frobnicate |
135 | Vendor: Examples for the PolicyKit Project |
136 | |
137 | [Cancel] [Authenticate] |
138 +----------------------------------------------------------+
139
140 If the user is using the da_DK locale, the dialog looks like this:
141
142 [IMAGE][3]
143
144 +----------------------------------------------------------+
145 | Autorisering [X] |
146 +----------------------------------------------------------+
147 | |
148 | [Icon] Autorisering er påkrævet for at afvikle |
149 | PolicyKit eksemplet Frobnicate |
150 | |
151 | Et program forsøger at udføre en handling der |
152 | kræver privilegier. Autorisering er påkrævet. |
153 | |
154 | Kodeord: [___________________________________] |
155 | |
156 | [V] Detaljer: |
157 | Bruger: Super User (root) |
158 | Program: /usr/bin/pk-example-frobnicate |
159 | Handling: org.fd.pk.example.pkexec.run-frobnicate |
160 | Vendor: Examples for the PolicyKit Project |
161 | |
162 | [Annullér] [Autorisering] |
163 +----------------------------------------------------------+
164
165 Note that pkexec does no validation of the ARGUMENTS passed to PROGRAM.
166 In the normal case (where administrator authentication is required
167 every time pkexec is used), this is not a problem since if the user is
168 an administrator he might as well just run pkexec bash to get root.
169
170 However, if an action is used for which the user can retain
171 authorization (or if the user is implicitly authorized), such as with
172 pk-example-frobnicate above, this could be a security hole. Therefore,
173 as a rule of thumb, programs for which the default required
174 authorization is changed, should never implicitly trust user input
175 (e.g. like any other well-written suid program).
176
178 Written by David Zeuthen davidz@redhat.com with a lot of help from many
179 others.
180
182 Please send bug reports to either the distribution or the polkit-devel
183 mailing list, see the link
184 http://lists.freedesktop.org/mailman/listinfo/polkit-devel on how to
185 subscribe.
186
188 polkit(8), pkaction(1), pkcheck(1)
189
191 1. /usr/share/gtk-doc/html/polkit-1/pkexec-bash.png
192
193 2. /usr/share/gtk-doc/html/polkit-1/pkexec-frobnicate.png
194
195 3. /usr/share/gtk-doc/html/polkit-1/pkexec-frobnicate-da.png
196
197
198
199polkit May 2009 PKEXEC(1)