directory and communicating with the polkit authority at runtime
(either via the
<linklinkend="ref-dbus-api">D-Bus API</link> or indirectly
via the
<linklinkend="ref-api">libpolkit-gobject-1</link> library or the
(either via the <linklinkend="ref-dbus-api">D-Bus API</link> or
indirectly through the <link
linkend="ref-api">libpolkit-gobject-1</link> library or the
<linklinkend="pkcheck.1">pkcheck</link> command).
</para>
...
...
@@ -37,55 +35,139 @@
<title>Best practices</title>
<itemizedlistmark='opencircle'spacing='compact'>
<listitem><para>
<emphasisrole='bold'>DO</emphasis> use polkit if you are writing a mechanism that is intended to be used by unprivileged programs.
</para></listitem>
<listitem>
<para>
<emphasisrole='bold'>DO</emphasis> use polkit if you are
writing a privileged mechanism (that is, running as
<emphasis>root</emphasis> or otherwise has special
permissions) that is intended to be used by unprivileged
programs.
</para>
</listitem>
<listitem><para>
<emphasisrole='bold'>DO</emphasis> carefully consider what actions to define. In many cases there is not a 1:1 mapping between operations and polkit actions (often a polkit action has more to do with the object the operation is acting on than the operation itself). It is important to strike the right balance between too fine-grained and too coarse-grained.
what actions to define. In many cases there isn't a 1:1
mapping between operations and polkit actions. Often a
polkit action has more to do with the object the operation
is acting on than the operation itself. It is important to
strike the right balance between too fine-grained and too
coarse-grained.
</para>
</listitem>
<listitem><para>
<emphasisrole='bold'>DO</emphasis> try to pick actions and implicit authorizations so applications using your mechanism will work out-of-the box for users logged in at the console (e.g. without interrupting the user with authentication dialogs).
</para></listitem>
<listitem>
<para>
<emphasisrole='bold'>DO</emphasis> try to pick actions
and implicit authorizations so applications using your
mechanism will work out-of-the box for users logged in at
the console. Not interrupting console users with
authentication dialogs should be considered a
priority. For example, it is not wise to require console
users to authenticate for such mundane tasks as adding a
printer queue (if the administrator really wants the OS to
act this way, he can always deploy suitable authorization
rules).
</para>
</listitem>
<listitem><para>
<emphasisrole='bold'>DO</emphasis> pass polkit variables along with
requests so it's possible to write <emphasis>authorization rules</emphasis> matching on these. Also document these variables in your documentation (for example, see the
<ulinkurl="http://udisks.freedesktop.org/docs/latest/udisks-polkit-actions.html">udisks2 actions and variables</ulink>).
<emphasisrole='bold'>DO</emphasis> pass a customized authentication message (using the <literal>polkit.message</literal> and <literal>polkit.gettext_domain</literal> variables) that includes more detailed information about the request than whatever is declared in the <filenameclass='extension'>.policy</filename> file's <literal>message</literal> element. For example, it's better to show <quote>Authentication is needed to format INTEL SSDSA2MH080G1GC (/dev/sda)</quote> than just <quote>Authentication is needed to format the device</quote>.
</para></listitem>
<listitem>
<para>
<emphasisrole='bold'>DO</emphasis> pass a customized
authentication message (using the
<literal>polkit.message</literal> and
<literal>polkit.gettext_domain</literal> variables) that
include more detailed information about the request than
whatever is declared in the <filename
class='extension'>.policy</filename> file's
<literal>message</literal> element. For example, it's
better to show <quote>Authentication is needed to format
INTEL SSDSA2MH080G1GC (/dev/sda)</quote> than just
<quote>Authentication is needed to format the
device</quote>.
</para>
</listitem>
<listitem><para>
<emphasisrole='bold'>DON'T</emphasis> use polkit if your program isn't intended to be used by unprivileged programs. For example, if you are writing developer tools or low-level core OS command it's fine to just require the user to be root. Users can always run your tool through e.g.
or write a simple polkit-using mechanism that allows
access to a (safe) subset of your tool.
</para>
</listitem>
<listitem><para>
<emphasisrole='bold'>DON'T</emphasis> use polkit unless you actually have to. In other words, not every single privileged program providing a service to an unprivileged programs has to use polkit. For example, if you have a small well-written <ulinkurl="http://en.wikipedia.org/wiki/Setuid">setuid</ulink> helper to help deal with some implementation-detail of the OS (such as elevating the priority of the sound server process to real-time for sessions on local seats) it's not really helpful to define a polkit action for this since no-one is going to choose to not grant the privilige (in the example, no-one is going run the sound server process without real-time priority).
</para></listitem>
<listitem>
<para>
<emphasisrole='bold'>DON'T</emphasis> use polkit unless
you actually have to. In other words, not every single
privileged program providing service to unprivileged
programs has to use polkit. For example, if you have a
for all your actions every time the authority emits the
<linklinkend="eggdbus-signal-org.freedesktop.PolicyKit1.Authority::Changed">Changed</link> signal. Not only is this a waste of resources, the result may also be inaccurate as authorization rules can return whatever they want, whenever they want.
signal. Not only is this a waste of resources, the result
may also be inaccurate as authorization rules can return
whatever they want, whenever they want.
</para>
</listitem>
<listitem><para>
<emphasisrole='bold'>DON'T</emphasis> block the main thread in your mechanism (e.g. the one used to service IPC requests from unprivileged programs) while waiting for the authority to reply - calls to