Skip to content

Commit

Permalink
Add new flag to check root user too in ChcekAuthorization (#452)
Browse files Browse the repository at this point in the history
Currently if the subject has uid 0 a shortcut is taken and authorization
is immediately granted, without checking against policies and rules.
Add a flag that allows skipping this shortcut.

uid 0 can of course alter polkit's behaviour directly, so this is not so
much a security feature, but more useful as a safety feature, so that
when an action is disabled it cannot be accidentally performed by root,
unless they really mean it and bypass polkit.
  • Loading branch information
bluca authored Jun 25, 2024
1 parent 0831cb8 commit 5a0a3cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/org.freedesktop.PolicyKit1.Authority.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
<annotation name="org.gtk.EggDBus.Flags.Member" value="AllowUserInteraction">
<annotation name="org.gtk.EggDBus.DocString" value="If the #Subject can obtain the authorization through authentication, and an authentication agent is available, then attempt to do so. Note, this means that the org.freedesktop.PolicyKit1.Authority.CheckAuthorization() method will block while the user is being asked to authenticate."/>
</annotation>
<annotation name="org.gtk.EggDBus.Flags.Member" value="AlwaysCheck">
<annotation name="org.gtk.EggDBus.DocString" value="Check access against policy even if the #Subject is the root user."/>
</annotation>
</annotation>

<!-- ---------------------------------------------------------------------------------------------------- -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ This D-Bus interface is implemented by the <literal>/org/freedesktop/PolicyKit1/
<programlisting>
{
None = 0x00000000,
AllowUserInteraction = 0x00000001
AllowUserInteraction = 0x00000001,
AlwaysCheck = 0x00000002
}
</programlisting>
<para>
Expand All @@ -100,6 +101,14 @@ No flags set.
If the <link linkend="eggdbus-struct-Subject">Subject</link> can obtain the authorization through authentication, and an authentication agent is available, then attempt to do so. Note, this means that the <link linkend="eggdbus-method-org.freedesktop.PolicyKit1.Authority.CheckAuthorization">CheckAuthorization()</link> method will block while the user is being asked to authenticate.
</para>
</listitem>
</varlistentry>
<varlistentry id="eggdbus-constant-CheckAuthorizationFlags.AlwaysCheck" role="constant">
<term><literal>AlwaysCheck</literal></term>
<listitem>
<para>
Check access against policy even if the <link linkend="eggdbus-struct-Subject">Subject</link> is the root user.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
Expand Down
2 changes: 2 additions & 0 deletions src/polkit/polkitcheckauthorizationflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ G_BEGIN_DECLS
* @POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION: If the subject can obtain the authorization
* through authentication, and an authentication agent is available, then attempt to do so. Note, this
* means that the method used for checking authorization is likely to block for a long time.
* @POLKIT_CHECK_AUTHORIZATION_FLAGS_ALWAYS_CHECK: Check access against policy even for root user.
*
* Possible flags when checking authorizations.
*/
typedef enum
{
POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE = 0,
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION = (1<<0),
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALWAYS_CHECK = (1<<1),
} PolkitCheckAuthorizationFlags;

G_END_DECLS
Expand Down
2 changes: 1 addition & 1 deletion src/polkitbackend/polkitbackendinteractiveauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
goto out;

/* special case: uid 0, root, is _always_ authorized for anything */
if (identity_is_root_user (user_of_subject))
if (!(flags & POLKIT_CHECK_AUTHORIZATION_FLAGS_ALWAYS_CHECK) && identity_is_root_user (user_of_subject))
{
result = polkit_authorization_result_new (TRUE, FALSE, NULL);
goto out;
Expand Down

0 comments on commit 5a0a3cf

Please sign in to comment.