Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 779181 - acct-user.eclass: Skip adding users/groups if on Prefix (as root)
Summary: acct-user.eclass: Skip adding users/groups if on Prefix (as root)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-30 00:20 UTC by Sam James
Modified: 2022-12-27 23:55 UTC (History)
4 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 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-03-30 00:20:23 UTC
A user reported that acct-group/portage was adding the group to their host's /etc/group. This is unexpected behaviour.

Right now, we check if we're root and bail out if not which covers most Prefix cases.

While we don't (as far as I know) officially support Prefix-as-root, this is an extremely cheap change to make to avoid breakage, especially if this is one of the only issues people are actually hitting in production.

We should check for EPREFIX != / (or some other check if more suitable).
Comment 1 Sargun Dhillon 2021-03-30 03:37:10 UTC
It should also work to pass --prefix $EPREFIX to groupadd and so. All of that should be possible to do in user.eclass.
Comment 2 Sargun Dhillon 2021-03-30 06:18:30 UTC
I checked and it appears to work -- passing --prefix to groupadd and useradd if shadow is installed.
Comment 3 Mike Gilbert gentoo-dev 2021-03-30 11:56:56 UTC
> This is unexpected behaviour.

Is it really unexpected? How should user/group management on prefix work? How can we ensure that the necessary users/groups are available for installed software to use?

I would guess that adding entries to ${EPREFIX}/etc/{passwd,group} would probably not be very useful.
Comment 4 Thomas Deutschmann (RETIRED) gentoo-dev 2021-03-30 12:35:13 UTC
I would also like to know what is unexpected.

If you are running as root, you are basically asking PREFIX to create these users. The user running prefix is the only indicator we have. Keep in mind that we have multiple PREFIX variants. Some of them should only install into an offset (i.e. to allow to make use of packages from Gentoo repository) but you still want the users.

I only see an inconsistency: Sometimes we check for EUID and sometimes we check for USE=prefix to decide if we want to pull in users...
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-03-30 14:40:48 UTC
(In reply to Mike Gilbert from comment #3)
> > This is unexpected behaviour.
> 
> Is it really unexpected? How should user/group management on prefix work?
> How can we ensure that the necessary users/groups are available for
> installed software to use?

Simply put, it doesn't. That's hotw it's always worked.

> 
> I would guess that adding entries to ${EPREFIX}/etc/{passwd,group} would
> probably not be very useful.

Yep.

(In reply to Thomas Deutschmann from comment #4)
> I would also like to know what is unexpected.
> 
> If you are running as root, you are basically asking PREFIX to create these
> users. The user running prefix is the only indicator we have. Keep in mind
> that we have multiple PREFIX variants. Some of them should only install into
> an offset (i.e. to allow to make use of packages from Gentoo repository) but
> you still want the users.

Doing anything outside of the EPREFIX is a no-no which is the problem. We do not support this case (running as root) really _anyway_, this is just a simple workaround/fix to ensure consistent behaviour, which leads me to...

> 
> I only see an inconsistency: Sometimes we check for EUID and sometimes we
> check for USE=prefix to decide if we want to pull in users...


Exactly.
Comment 6 Sargun Dhillon 2021-03-30 16:15:59 UTC
I mean, ignoring this being unexpected, it's broken. Software looks at the database in $EPREFIX/etc/{group,passwd,shadow}. groupadd / useradd adds the user to /etc/{group,passwd,shadow}. It should be caused with the --prefix or --chroot option to fix this.
Comment 7 Mike Gilbert gentoo-dev 2021-03-30 16:29:59 UTC
It seems odd that software would look at EPREFIX/etc/passed. That means you would have 2 disparate user databases with names and ids that might conflict. 

I suspect this also depends on whether you link the prefix software against the system libc, or a prefixed libc. Either is probably feasible.
Comment 8 Mike Gilbert gentoo-dev 2021-03-30 16:42:24 UTC
Instead of assuming that all prefix users want to disable this, maybe we should define a new eclass var to disable the update functionality of user.eclass. Users could set this in make.conf and it could be set in prefix profiles if desired.
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-04-26 06:22:42 UTC
(In reply to Sargun Dhillon from comment #6)
> I mean, ignoring this being unexpected, it's broken. Software looks at the
> database in $EPREFIX/etc/{group,passwd,shadow}. groupadd / useradd adds the
> user to /etc/{group,passwd,shadow}. It should be caused with the --prefix or
> --chroot option to fix this.

I wonder if this is actually fixed by bug 541406. I guess not if something is running it within prefix as ROOT will still be empty.
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-04-26 06:26:13 UTC
(In reply to Mike Gilbert from comment #7)
> It seems odd that software would look at EPREFIX/etc/passed. That means you
> would have 2 disparate user databases with names and ids that might
> conflict. 
> 
> I suspect this also depends on whether you link the prefix software against
> the system libc, or a prefixed libc. Either is probably feasible.

Based on this, I'm unsure about whether --prefix on groupadd and friends in user*.eclass makes sense. I suppose, again, it kind of does if you're doing things as root, even though it's odd.

so I guess let's:
1. bail out if EPREFIX is non-empty, unless..
2. some USER_ECLASS_ALLOW_ROOT_PREFIX=yes is set by the user?
Comment 11 James Le Cuirot gentoo-dev 2022-12-14 22:17:50 UTC
I've dealt with this in https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=eabd386679e85e14532642e4fd03585acb6e881a by bailing out if EPREFIX is non-empty. Feel free to take this further if you want.
Comment 12 Larry the Git Cow gentoo-dev 2022-12-27 23:49:05 UTC
The bug has been closed via the following commit(s):

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

commit cfad8158b77d70f92698d1d616f778cd8d4656b1
Author:     James Le Cuirot <chewi@gentoo.org>
AuthorDate: 2022-12-08 09:16:41 +0000
Commit:     James Le Cuirot <chewi@gentoo.org>
CommitDate: 2022-12-27 23:48:47 +0000

    acct-group.eclass: Don't modify groups when EPREFIX is non-empty
    
    This was happening when running a prefix as root, which we don't really
    support, but also when building a prefixed system under ROOT.
    
    Closes: https://bugs.gentoo.org/779181
    Signed-off-by: James Le Cuirot <chewi@gentoo.org>

 eclass/acct-group.eclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 13 James Le Cuirot gentoo-dev 2022-12-27 23:55:12 UTC
I'd pushed the users commit but not the groups commit. Woops!