Is there a way to make the polkit agent default to the currently logged in user?

1

Does anyone know how to configure polkit-gnome-authentication-agent-1 to default to the current user initially when handling a request, or alternatively if one of the other polkit agents has this ability?


When authenticating to perform a polkit action with an agent like polkit-gnome-authentication-agent-1, because I have multiple users in the wheel group I'm provided a drop down to select which user to authenticate as.

This is an irritating extra step, when in most cases the user I want to authenticate as, is the currently logged in user*. My preferred behaviour is that the currently logged in user is pre-selected and I'm taken straight to password entry, with the option to change to another user if that's what I want.

I'm aware that it's possible to restrict the users that appear in the list via polkit rules but my naive understanding of those rules is they change who is allowed to authenticate for certain actions, and that this behaviour is instead in the realm of the polkit GUI agent. Or am I wrong and that the default selection is something that can be set via polkit rules?

To reiterate I don't wish to change which users/groups are allowed to authenticate to perform polkit actions but just make the UI a little quicker to move through with minimum keypresses and definitely no rodents.

* I fully acknowledge that this might be the most sensible behaviour for most deployments, but for me its awkward.

Chris Scutcher

Posted 2018-04-08T20:02:38.270

Reputation: 111

Answers

1

The way I managed to solve this issue is by adding a custom file to /etc/polkit-1/rules.d/ named 00-custom.rules with the following lines, to override the 50-default.rules:

polkit.addAdminRule(function(action, subject) {
    if( subject.isInGroup("wheel") ) {
        return ["unix-user:"+subject.user];
    }
    else {
        return [polkit.Result.NO];
    }
});

This way the current user, if present in the wheel group, will be prompted for their password, otherwise for the root password.

nicolo.rebughini

Posted 2018-04-08T20:02:38.270

Reputation: 11