Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 690290 - app-portage/pfl-3.0.1-r1 missing RDEPEND on sys-apps/util-linux[caps]: /etc/cron.weekly/pfl: line 2: setpriv: command not found
Summary: app-portage/pfl-3.0.1-r1 missing RDEPEND on sys-apps/util-linux[caps]: /etc/c...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Daniel Pielmeier
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-20 14:06 UTC by Louis Sautier (sbraz)
Modified: 2019-07-22 05:23 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Louis Sautier (sbraz) gentoo-dev 2019-07-20 14:06:17 UTC
Hi,
I recently noticed a failing cron job because setpriv was missing on my system.
# cat /etc/cron.weekly/pfl 
#!/bin/sh
setpriv --reuid=portage --regid=portage --clear-groups nice /usr/bin/pfl >/dev/null
# /etc/cron.weekly/pfl
/etc/cron.weekly/pfl: line 2: setpriv: command not found

The presence of the setpriv binary is controlled by the caps use-flag for util-linux so it should be added to pfl's RDEPEND.
Comment 1 Daniel Pielmeier gentoo-dev 2019-07-20 14:52:00 UTC
Thanks for the report. This is fixed in Git with pfl-3.0.1-r2.
Comment 2 Thomas Deutschmann (RETIRED) gentoo-dev 2019-07-21 12:32:10 UTC
Can't you rewrite cronjob to do something like

> exec su portage -s /bin/sh -c 'nice /usr/bin/pfl >/dev/null' 2>/dev/null

to avoid setpriv depedency?
Comment 3 Daniel Pielmeier gentoo-dev 2019-07-21 13:04:49 UTC
(In reply to Thomas Deutschmann from comment #2)
> Can't you rewrite cronjob to do something like
> 
> > exec su portage -s /bin/sh -c 'nice /usr/bin/pfl >/dev/null' 2>/dev/null
> 
> to avoid setpriv depedency?

Of course I can. I looked for solutions in bug #679772. I found setpriv suitable and chose it. Maybe I just missed the obvious solution.
Comment 4 Daniel Pielmeier gentoo-dev 2019-07-21 14:42:49 UTC
(In reply to Daniel Pielmeier from comment #3)
> (In reply to Thomas Deutschmann from comment #2)
> > Can't you rewrite cronjob to do something like
> > 
> > > exec su portage -s /bin/sh -c 'nice /usr/bin/pfl >/dev/null' 2>/dev/null
> > 
> > to avoid setpriv depedency?
> 
> Of course I can. I looked for solutions in bug #679772. I found setpriv
> suitable and chose it. Maybe I just missed the obvious solution.

Okay I tried to remember why I chose setpriv. When doing the research I stumbled upon a stackoverflow question [1] where su was initially listed a non-option.

Then I found a stackexchange [2] question. Especially answer [3] mentioned an excerpt from the su man-page which explicitly states that privileged user should use runuser or setpriv instead of su itself. An earlier comment [4] links to a document stating that su should not be abused for dropping privileges. Thus I settled to go with setpriv from util-linux.

However after your comment and some more digging I found that there are more implementations of su. One from the sys-apps/util-linux package and another one from the sys-apps/shadow package. Gentoo apparently uses the version from shadow. The excerpt from the man-page is from the util-linux version, the shadow version apparently does not distinguish between privileged and unprivileged users.

This however does not mean the implementation of shadow is better (or worse). I have not that much experience and can not decide this. If somebody tells me I can savely use su from shadow, i have no problem with changing it. If not I will stick with setpriv from util-linux.

Besides when running su as you recommended it I get the following:
> su: Authentication service cannot retrieve authentication info
> (Ignored)
The command itself executed just fine but there seems to be an issue with pam.

[1] https://stackoverflow.com/questions/24251474/how-to-drop-root-privileges-from-a-posix-shell-script
[2] https://unix.stackexchange.com/questions/132663/how-do-i-drop-root-privileges-in-shell-scripts
[3] https://unix.stackexchange.com/a/479308
[4] https://unix.stackexchange.com/a/353698
Comment 5 Thomas Deutschmann (RETIRED) gentoo-dev 2019-07-21 16:19:12 UTC
Oh, didn't expect such a research. Well, I wouldn't care that much:

I took my example from sys-apps/man-db cronjob (base-system package).
Even sys-apps/portage install logrote script which uses su.

Using my suggestion (with fixed/normalized output handling of course) should be safe.
Comment 6 Daniel Pielmeier gentoo-dev 2019-07-21 17:40:46 UTC
(In reply to Thomas Deutschmann from comment #5)
> Oh, didn't expect such a research. Well, I wouldn't care that much:
> 
> I took my example from sys-apps/man-db cronjob (base-system package).
> Even sys-apps/portage install logrote script which uses su.
> 
> Using my suggestion (with fixed/normalized output handling of course) should
> be safe.

As this was the first time I had to deal with dropping privileges I thought I might as well read a bit about it.

After reading some more I think I will stick with using setpriv. The man-page says:
> It is a simple, non-set-user-ID wrapper around execve(2), and can be used to
> drop privileges in the same way as setuidgid(8) from daemontools, chpst(8) from
> runit, or similar tools shipped by other service managers.
From [1], setuidgid and chpst fall into the category of dropping privileges instead of adding them and also do not fall into an interactive mode. So I think the additional dependency is justified.

[1] https://unix.stackexchange.com/a/353698
Comment 7 Larry the Git Cow gentoo-dev 2019-07-21 20:59:29 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8c429919d7ede49af0bf8e8b718001748934953a

commit 8c429919d7ede49af0bf8e8b718001748934953a
Author:     Thomas Deutschmann <whissi@gentoo.org>
AuthorDate: 2019-07-21 20:59:05 +0000
Commit:     Thomas Deutschmann <whissi@gentoo.org>
CommitDate: 2019-07-21 20:59:21 +0000

    app-portage/pfl: hide sys-apps/util-linux RDEPEND behind USE flag
    
    Bug: https://bugs.gentoo.org/690290
    Package-Manager: Portage-2.3.68, Repoman-2.3.16
    Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>

 app-portage/pfl/pfl-3.0.1-r2.ebuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 8 Daniel Pielmeier gentoo-dev 2019-07-22 05:23:57 UTC
>     app-portage/pfl: hide sys-apps/util-linux RDEPEND behind USE flag

While looking at so many things I completely forgot about the cron script being conditionally installed. Thanks a lot.