summaryrefslogtreecommitdiff
path: root/docs/man/pkexec.xml
blob: 97ab315d38cf125b2ce62bed2ca94b3763e4cc86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
<!ENTITY version SYSTEM "../version.xml">
]>
<refentry id="pkexec.1" xmlns:xi="http://www.w3.org/2003/XInclude">
  <refentryinfo>
    <title>pkexec</title>
    <date>May 2009</date>
    <productname>polkit</productname>
  </refentryinfo>

  <refmeta>
    <refentrytitle>pkexec</refentrytitle>
    <manvolnum>1</manvolnum>
    <refmiscinfo class="version"></refmiscinfo>
  </refmeta>

  <refnamediv>
    <refname>pkexec</refname>
    <refpurpose>Execute a command as another user</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <cmdsynopsis>
      <command>pkexec</command>
      <arg><option>--version</option></arg>
      <arg><option>--disable-internal-agent</option></arg>
      <arg><option>--help</option></arg>
    </cmdsynopsis>

    <cmdsynopsis>
      <command>pkexec</command>
      <group>
        <arg choice="plain">
          <option>--user</option>
          <replaceable>username</replaceable>
        </arg>
      </group>
      <arg choice="plain"><replaceable>PROGRAM</replaceable></arg>
      <group rep="repeat">
        <arg choice="plain"><replaceable>ARGUMENTS</replaceable></arg>
      </group>
    </cmdsynopsis>

  </refsynopsisdiv>

  <refsect1 id="pkexec-description"><title>DESCRIPTION</title>
    <para>
      <command>pkexec</command> allows an authorized user to
      execute <replaceable>PROGRAM</replaceable> as another
      user. If <replaceable>username</replaceable> is not specified,
      then the program will be executed as the administrative super
      user, <emphasis>root</emphasis>.
    </para>
  </refsect1>

  <refsect1 id="pkexec-return-value"><title>RETURN VALUE</title>
    <para>
      Upon successful completion, the return value is the return value
      of <replaceable>PROGRAM</replaceable>. If the calling process is
      not authorized or an authorization could not be obtained through
      authentication or an error occured, <command>pkexec</command>
      exits with a return value of 127. If the authorization could not
      be obtained because the user dismissed the authentication
      dialog, <command>pkexec</command> exits with a return value of
      126.
    </para>
  </refsect1>

  <refsect1 id="pkexec-auth-agent"><title>AUTHENTICATION AGENT</title>
    <para>
      <command>pkexec</command>, like any other PolicyKit application,
      will use the authentication agent registered for the calling
      process. However, if no authentication agent is available, then
      <command>pkexec</command> will register its own textual
      authentication agent. This behavior can be turned off by passing
      the <option>--disable-internal-agent</option> option.
    </para>
  </refsect1>

  <refsect1 id="pkexec-security-notes"><title>SECURITY NOTES</title>
    <para>
      Executing a program as another user is a privileged
      operation. By default the required authorization (See
      <xref linkend="pkexec-required-authz"/>) requires administrator
      authentication. In addition, the authentication dialog presented
      to the user will display the full path to the program to be
      executed so the user is aware of what will happen:
    </para>
    <mediaobject id="pkexec-bash">
      <imageobject>
        <imagedata fileref="pkexec-bash.png" format="PNG"/>
      </imageobject>
      <textobject>
        <programlisting><![CDATA[
+----------------------------------------------------------+
|                     Authenticate                     [X] |
+----------------------------------------------------------+
|                                                          |
|  [Icon]  Authentication is needed to run `/bin/bash'     |
|          as the super user                               |
|                                                          |
|          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:                                             |
|  Command: /bin/bash                                      |
|  Run As:  Super User (root)                              |
|  Action:  org.freedesktop.policykit.exec                 |
|  Vendor:  The PolicyKit Project                          |
|                                                          |
|                                  [Cancel] [Authenticate] |
+----------------------------------------------------------+
]]></programlisting>
      </textobject>
    </mediaobject>
    <para>
      The environment that <replaceable>PROGRAM</replaceable> will run
      it, will be set to a minimal known and safe environment in order
      to avoid injecting code
      through <literal>LD_LIBRARY_PATH</literal> or similar
      mechanisms. In addition the <literal>PKEXEC_UID</literal>
      environment variable is set to the user id of the process
      invoking <command>pkexec</command>. As a
      result, <command>pkexec</command> will not allow you to run
      e.g. X11 applications as another user since
      the <literal>$DISPLAY</literal> environment variable is not set.
    </para>
  </refsect1>

  <refsect1 id="pkexec-required-authz"><title>REQUIRED AUTHORIZATIONS</title>
    <para>
      By default,
      the <emphasis>org.freedesktop.policykit.exec</emphasis>
      authorization is required unless an action definition file is
      present for the program in question. To require another
      authorization, it can be specified using the <emphasis>org.freedesktop.policykit.exec.path</emphasis> annotation on an action (See <xref linkend="pkexec-example"/> for details).
    </para>
  </refsect1>

  <refsect1 id="pkexec-example"><title>EXAMPLE</title>
    <para>
      To specify what kind of authorization is needed to execute the
      program <filename>/usr/bin/pk-example-frobnicate</filename> as
      another user, simply write an action definition file like this
    </para>
    <programlisting>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../src/examples/org.freedesktop.policykit.examples.pkexec.policy"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting>
    <para>
      and drop it in
      the <filename>/usr/share/polkit-1/actions</filename> directory
      under a suitable name (e.g. matching the namespace of the
      action).  Note that in addition to specifying the program, the
      authentication message, description, icon and defaults can be
      specified. For example, for the action defined above, the following
      authentication dialog will be shown:
    </para>
    <mediaobject id="pkexec-frobnicate">
      <imageobject>
        <imagedata fileref="pkexec-frobnicate.png" format="PNG"/>
      </imageobject>
      <textobject>
        <programlisting><![CDATA[
+----------------------------------------------------------+
|                     Authenticate                     [X] |
+----------------------------------------------------------+
|                                                          |
|  [Icon]  Authentication is required to run the PolicyKit |
|          example program Frobnicate                      |
|                                                          |
|          An application is attempting to perform an      |
|          action that requires privileges. Authentication |
|          is required to perform this action.             |
|                                                          |
|          Password: [__________________________________]  |
|                                                          |
| [V] Details:                                             |
|  Command: /usr/bin/pk-example-frobnicate                 |
|  Run As:  Super User (root)                              |
|  Action:  org.fd.pk.example.pkexec.run-frobnicate        |
|  Vendor:  Examples for the PolicyKit Project             |
|                                                          |
|                                  [Cancel] [Authenticate] |
+----------------------------------------------------------+
]]></programlisting>
      </textobject>
    </mediaobject>
    <para>
      If the user is using the <literal>da_DK</literal> locale, the
      dialog looks like this:
    </para>
    <mediaobject id="pkexec-frobnicate-da">
      <imageobject>
        <imagedata fileref="pkexec-frobnicate-da.png" format="PNG"/>
      </imageobject>
      <textobject>
        <programlisting><![CDATA[
+----------------------------------------------------------+
|                     Autorisering                     [X] |
+----------------------------------------------------------+
|                                                          |
|  [Icon]  Autorisering er påkrævet for at afvikle         |
|          PolicyKit eksemplet Frobnicate                  |
|                                                          |
|          Et program forsøger at udføre en handling der   |
|          kræver privilegier. Autorisering er påkrævet.   |
|                                                          |
|          Kodeord: [___________________________________]  |
|                                                          |
| [V] Detaljer:                                            |
|  Bruger:   Super User (root)                             |
|  Program:  /usr/bin/pk-example-frobnicate                |
|  Handling: org.fd.pk.example.pkexec.run-frobnicate       |
|  Vendor:   Examples for the PolicyKit Project            |
|                                                          |
|                                [Annullér] [Autorisering] |
+----------------------------------------------------------+
]]></programlisting>
      </textobject>
    </mediaobject>
    <para>
      Note that <command>pkexec</command> does no validation of
      the <replaceable>ARGUMENTS</replaceable> passed
      to <replaceable>PROGRAM</replaceable>. In the normal case (where
      administrator authentication is required every
      time <command>pkexec</command> is used), this is not a problem
      since if the user is an administrator he might as well just
      run <command>pkexec bash</command> to get root.
    </para>
    <para>
      However, if an action is used for which the user can retain
      authorization (or if the user is implicitly authorized), such as
      with <filename>pk-example-frobnicate</filename> above, this
      could be a security hole. Therefore, as a rule of thumb,
      programs for which the default required authorization is
      changed, should never implicitly trust user input (e.g. like any
      other well-written <emphasis>suid</emphasis> program).
    </para>
  </refsect1>

  <refsect1 id="pkexec-author"><title>AUTHOR</title>
    <para>
      Written by David Zeuthen <email>davidz@redhat.com</email> with
      a lot of help from many others.
    </para>
  </refsect1>

  <refsect1 id="pkexec-bugs">
    <title>BUGS</title>
    <para>
      Please send bug reports to either the distribution or the
      polkit-devel mailing list,
      see the link <ulink url="http://lists.freedesktop.org/mailman/listinfo/polkit-devel"/>
      on how to subscribe.
    </para>
  </refsect1>

  <refsect1 id="pkexec-see-also">
    <title>SEE ALSO</title>
    <para>
      <citerefentry>
        <refentrytitle>polkit</refentrytitle><manvolnum>8</manvolnum>
      </citerefentry>,
      <citerefentry>
        <refentrytitle>pkaction</refentrytitle><manvolnum>1</manvolnum>
      </citerefentry>,
      <citerefentry>
        <refentrytitle>pkcheck</refentrytitle><manvolnum>1</manvolnum>
      </citerefentry>
    </para>
  </refsect1>
</refentry>