Skip to content

Invoke initgroups() iff we got enough privileges (#11869) - #11872

Merged
jvgutierrez merged 1 commit into
apache:masterfrom
jvgutierrez:fix-initgroups
Nov 21, 2024
Merged

jvgutierrez merged 1 commit into
apache:masterfrom
jvgutierrez:fix-initgroups

Conversation

@jvgutierrez

Copy link
Copy Markdown
Member

Follow up of #11855, that rendered unusable ATS as root when spawned via traffic_manager. As mentioned on #11869, traffic_manager drops privileges when spawned as root and as consequence by the time that traffic_server attempts to call initgroups() it gets an EPERM error.

Fixes #11869

ezelkow1
ezelkow1 previously approved these changes Nov 15, 2024
maskit
maskit previously approved these changes Nov 15, 2024

@maskit maskit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change is necessary for 9.2.x, which uses traffic_manager. I don't think we need this for 10.x but it's probably nice to keep the code consistent.

@cmcfarlen cmcfarlen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should check for superuser, right?

Comment thread src/tscore/ink_cap.cc Outdated
// Always repopulate the supplementary group list for the new user.
if (initgroups(pwd->pw_name, pwd->pw_gid) != 0) {
Fatal("switching to user %s, failed to initialize supplementary groups ID %ld", pwd->pw_name, (long)pwd->pw_gid);
if (geteuid() != 0) { // check that we have enough rights to call initgroups()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be geteuid() == 0?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

😅 you're totally right, fixed :)

@midchildan

midchildan commented Nov 19, 2024 •

Copy link
Copy Markdown
Contributor

I believe this fix will reintroduce the problem in #11855. traffic_manager spawns traffic_server with an unprivileged effective UID and privileged real UID. With this change, traffic_server will keep root's supplementary groups because its EUID won't equal 0.

@midchildan

Copy link
Copy Markdown
Contributor

My bad, I got mixed up with a separate workaround I had for #11869.

Comment thread src/tscore/ink_cap.cc
if (initgroups(pwd->pw_name, pwd->pw_gid) != 0) {
Fatal("switching to user %s, failed to initialize supplementary groups ID %ld", pwd->pw_name, (long)pwd->pw_gid);
if (geteuid() == 0) { // check that we have enough rights to call initgroups()
if (initgroups(pwd->pw_name, pwd->pw_gid) != 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think initgroups() should be called at the end of impersonate() too so that the supplementary groups would be repopulated when elevating privileges instead of dropping them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that would require to add CAP_SETGID to RestrictCapabilities()? maybe it's worth moving this discussion to another PR/issue and solve #11869 with this one

@ezelkow1

Copy link
Copy Markdown
Member

@jvgutierrez if you are happy with this can you merge it so then I can pick it back for a 9.2.x release tomorrow?

Thanks

@jvgutierrez
jvgutierrez merged commit d4dda9b into apache:master Nov 21, 2024
ezelkow1 pushed a commit that referenced this pull request Nov 21, 2024
Follow up of #11855, that rendered unusable ATS as root when spawned via traffic_manager.

(cherry picked from commit d4dda9b)
@ezelkow1

Copy link
Copy Markdown
Member

cherry picked to 9.2.x

@cmcfarlen cmcfarlen added this to the 10.0.3 milestone Dec 4, 2024
@cmcfarlen

Copy link
Copy Markdown
Contributor

Cherry-picked to v10.0.x

cmcfarlen pushed a commit that referenced this pull request Dec 4, 2024
Follow up of #11855, that rendered unusable ATS as root when spawned via traffic_manager.

(cherry picked from commit d4dda9b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project
Status: Picked-10.0.3

Development

Successfully merging this pull request may close these issues.

ATS 9.2.6 fails to start as root

6 participants