Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make user/group info reliable operation across chroot #2503

Merged
merged 3 commits into from
Jul 4, 2023

Conversation

pmatilai
Copy link
Member

@pmatilai pmatilai commented May 5, 2023

There's no telling what sort of caching getpwnam() and friends perform behind the scenes, and worse, there's no way to explicitly reset those caches. This can lead to chrooted operations using user/group data from the host, which is simply wrong.

Do our own parsing of /etc/passwd and /etc/group to fix. Besides the chroot matter, we then only ever lookup local system users and groups and not something from eg network name services. Technically we should track chroot status for each lookup and flush the cache if the state changed, but this is an internal API and rpm usages only ever call it from one side of the chroot for a given operation.

Fixes: #882

@pmatilai pmatilai added the bug label May 5, 2023
@DemiMarie
Copy link
Contributor

What about users and groups that are not in /etc/passwd or /etc/group? Those won’t work with this design.

IMO the only way to get everything right is to either reimplement glibc nsswitch (yuck) or to fork/exec a subprocess and have that chroot before it makes any user or group lookups.

@pmatilai
Copy link
Member Author

pmatilai commented May 8, 2023

Ignoring users from network services is quite intentional. That's mentioned in the commit message but perhaps it deserves to be expanded. see the discussion in #882.

Copy link
Contributor

@dcantrell dcantrell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments and questions.

lib/rpmug.c Outdated Show resolved Hide resolved
lib/rpmug.c Outdated Show resolved Hide resolved
lib/rpmug.c Outdated Show resolved Hide resolved
@mlschroe
Copy link
Contributor

mlschroe commented May 9, 2023

I would be more happy if it does the local parsing only in the chroot case, like with my old patch.

@pmatilai
Copy link
Member Author

pmatilai commented May 10, 2023

Doing one thing for a chroot and another for the host seems inconsistent to me. Assuming we accept that rpm needs to honor NSS then doing a local parse for the chroot is just different kind of buggy, because the chroot may just as well be configured for something else. I'm inclined to agree with this @keszybz 's comment: #882 (comment) - the only thing that's well defined for rpm purposes is the local files, and we'll be better off with consistent, clearly defined behavior. This goes for user/group creation too.

@pmatilai pmatilai force-pushed the ugid-pr branch 2 times, most recently from 831db8e to 1cd4bbe Compare May 24, 2023 07:22
@pmatilai
Copy link
Member Author

pmatilai commented May 24, 2023

One possibility is to (perhaps optionally) fall back to NSS if local lookup fails, for the non-chroot case.

That said, I'd rather leave that fallback out initially and only add later if it turns out unavoidable. The thing is, NSS in a chroot is a lost cause because doing the first lookup inside the chroot means the we or the alleged helper would try to dlopen() stuff from the chroot, which could be anything at all, or be entirely missing. So if we accept NSS use for packaged files, we'll accept forever having undefined behavior for verify in chroot, which is basically the case we're trying to solve here. And in that case we might just as well not bother with this at all.

@pmatilai
Copy link
Member Author

Should also fix #1789 for real

@pmatilai pmatilai force-pushed the ugid-pr branch 2 times, most recently from b086193 to f2a24cc Compare June 1, 2023 09:19
@pmatilai
Copy link
Member Author

pmatilai commented Jun 1, 2023

Elaborated a bit on the intentional NSS exclusion in the commit message and docs as well.

lib/rpmug.c Outdated Show resolved Hide resolved
macros.in Outdated Show resolved Hide resolved
tests/rpmi.at Show resolved Hide resolved
@dmnks
Copy link
Contributor

dmnks commented Jun 23, 2023

Apart from the inline comments I made, the change itself looks good!

pmatilai added 3 commits June 27, 2023 14:31
There's no telling what sort of caching getpwnam() and friends perform
behind the scenes, and worse, there's no way to explicitly reset those
caches. This can lead to chrooted operations using user/group data from
the host, which is simply wrong.

Do our own parsing of /etc/passwd and /etc/group to fix. Besides the
chroot matter, we then only ever lookup local system users and groups
and not something from eg network name services. We cannot reliably
do NSS in a chroot because doing so would require relying on binaries
in the chroot, which in itself is completely unreliable. NSS is also
unreliable in various rescue mode situations. Bottom line, local files
are the only ones that can be guaranteed for rpm operation, and this
change basically enforces that.

Technically we should track chroot status for each lookup and flush the
cache if the state changed, but this is an internal API and rpm usages
only ever call it from one side of the chroot for a given operation.

Fixes: rpm-software-management#882, rpm-software-management#1789
The simple cache whose efficiency troubled ewt back in 1997
(see commit 97999ce)
has proven more than adequate over the years.

In a local testcase based on Fedora 33 server iso contents, an install
of 1765 packages consisting of 201344 files did a whopping 27 user +
groups combined. So a few more alloc+free is not going to make the
damnest difference, don't bother with reallocing the cache buffer, just
strdup() a new one when needed.
@pmatilai
Copy link
Member Author

Typo + poor function name addressed in the last push, plus rebased.

@pmatilai
Copy link
Member Author

pmatilai commented Jul 4, 2023

Okay no further comments from anybody...

This needs to go into the beta to give us a chance to react if it turns out to be a disaster.

@pmatilai pmatilai merged commit 36c48df into rpm-software-management:master Jul 4, 2023
@pmatilai pmatilai deleted the ugid-pr branch July 4, 2023 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rpm chroot operations use user/group info from the host
6 participants