Mask sleep.target ask for authentication

Kernels & Hardware, configuring network, installing services

Mask sleep.target ask for authentication

Postby bester69 » 2020-05-29 14:25

Hi,
Im trying to control sleep methods with mask/unmask sleep.target, but when system dekstop tries to go to sleep rise box authentication..

Im using Mask:
sudo systemctl --runtime mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Im using unMask:
sudo systemctl --runtime unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

when I use systemctl suspend, everything work well, but when I use desktop method or let the system idle, it raises the authentication box..so cant make use of these methods within script to control sleep state. :?

when i run .:
qdbus org.kde.Solid.PowerManagement /org/freedesktop/PowerManagement Suspend


Image

Is there any way to make system work with mask/unmask without asking for policy authentication :?:
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1689
Joined: 2015-04-02 13:15

Re: Mask sleep.target ask for authentication

Postby LE_746F6D617A7A69 » 2020-05-29 15:30

The simplest way is to set suid bit for qdbus - this works for any program and for any user, so it should be used with care...

You may also check this link:
systemd-start-as-unprivileged-user-in-a-group

.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 345
Joined: 2020-05-03 14:16

Re: Mask sleep.target ask for authentication

Postby bester69 » 2020-05-29 19:24

LE_746F6D617A7A69 wrote:The simplest way is to set suid bit for qdbus - this works for any program and for any user, so it should be used with care...

You may also check this link:
systemd-start-as-unprivileged-user-in-a-group

.

Hi, Thanls for help, :roll: but I cant make it work

Im doin this.:
0- sudo systemctl --runtime mask sleep.target suspend.target hibernate.target hybrid-sleep.target (disable suspend)
1- run : qdbus org.kde.Solid.PowerManagement /org/freedesktop/PowerManagement Suspend (cant suspend becouse suspend is masked)
2- sudo systemctl --runtime unmask sleep.target suspend.target hibernate.target hybrid-sleep.target (enable suspend)
3- run : qdbus org.kde.Solid.PowerManagement /org/freedesktop/PowerManagement Suspend (ask for polkit authentication) :arrow: :idea:


I tried whith what you gave me..but it didnt work or i dont know what do or i have to do...I did.:
0- Create group and added my user
sudo addgroup awesomeproject
sudo usermod -a -G awesomeproject myuser
1- in sudoers.:
myuser ALL=(awesomeproject) NOPASSWD: /bin/systemctl

2- gkduso gedit /etc/polkit-1/localauthority/50-local.d/service-auth.pkla
[Allow foogroup to start/stop/restart services]
Identity=unix-group:awesomeproject
Action=org.freedesktop.systemd1.manage-units
ResultActive=yes

3- reboot
----------------------------------

I suspect must be some polkit rule, but dont think that is the right one :?
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1689
Joined: 2015-04-02 13:15

Re: Mask sleep.target ask for authentication

Postby LE_746F6D617A7A69 » 2020-05-29 21:24

You have mixed 2 different solutions:
1st solution was to modify the sudoers file, and the 2nd solution was to add a polkit rule.

The 1st solution should work out-of-the-box, unless You've messed something.
This method is equivalent to setting suid bit, but applies only to a specific user/group - so it's actually more safe, unless You are the only user configured in the system.
If Your commands are working with sudo, then they must work also with this method.

The second solution is allowing You to manage systemd units as a normal user (org.freedesktop.systemd1.manage-units), but I'm not sure if this includes masking/unmasking units.

Regards

PS. Are You really using the "awesomeproject" group name, which was used as an example on stackexchange? :roll:
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 345
Joined: 2020-05-03 14:16

Re: Mask sleep.target ask for authentication

Postby bester69 » 2020-05-30 01:17

LE_746F6D617A7A69 wrote:You have mixed 2 different solutions:
1st solution was to modify the sudoers file, and the 2nd solution was to add a polkit rule.

The 1st solution should work out-of-the-box, unless You've messed something.
This method is equivalent to setting suid bit, but applies only to a specific user/group - so it's actually more safe, unless You are the only user configured in the system.
If Your commands are working with sudo, then they must work also with this method.

The second solution is allowing You to manage systemd units as a normal user (org.freedesktop.systemd1.manage-units), but I'm not sure if this includes masking/unmasking units.

Regards

PS. Are You really using the "awesomeproject" group name, which was used as an example on stackexchange? :roll:

yeah, Its just for personal use..

Im sudoering a scritpt that contains systemctl mask/unmask.... but it doesnt matter , there's something that gets broken when you apply sleep.target mask, becouse, when you unmask it back..system ask for poltkit authentication before going sleep when it idles... I was searching some kind fo workaround to this, like restart or reload any service.. but I have no idea..what should i do... my desktop is kde stretch and it doesnt like it "systemctl mask/unmask"

nosleep.sh (script added to sudoers)
Code: Select all
#!/bin/bash
#
    echo "- Nosleep Systemctl: 1 "
OPT="$1"
 case "$OPT" in
    "1" ) 
    sudo systemctl  --runtime mask sleep.target suspend.target hibernate.target hybrid-sleep.target
        ;;
    "0" ) 
    echo "- Nosleep Desactivado Systemctl: 0"
    sudo systemctl --runtime unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
        ;;       
    * )
        echo "Sin Error..."
        ;;
esac
flag=$(find /run/systemd/system/ -type l -name "sleep.target")
if [ ! -z "$flag" ]
then
echo "Estado MASKED sleep.target suspend.target"
else
echo "Estado UNMASKED sleep.target suspend.target"
fi
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1689
Joined: 2015-04-02 13:15

Re: Mask sleep.target ask for authentication

Postby LE_746F6D617A7A69 » 2020-05-30 15:05

I've looked here and there and I've discovered that the Debian wiki is outdated (as usual ;) ) - masking sleep/hibernate targets is no longer a valid method for preventing system from entering the suspend state, here's the reference:
https://freedesktop.org/wiki/Software/systemd/inhibit/

I think that masking sleep/hibernate targets masking may indeed cause some problems in DE, which are supposed to use logind inteface.
In current versions of systemd You should use systemd-inhibit

Regards
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 345
Joined: 2020-05-03 14:16


Return to System configuration

Who is online

Users browsing this forum: No registered users and 14 guests

fashionable