-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
subprocess.call(..., user=xx, group=xxx) is not able to gain privileges #100163
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
Comments
Why? Because sequences to up and down privileges are DIFFERENT (reversed order of functions call). To down privileges (this logic is hard-coded in Python now): # have to find username by uid or....
# we definitely have to drop supplementary groups. either to empty list or new user's groups
initgroups(username, gid)
setresgid(gid, gid, gid)
setresuid(uid, uid, uid) To up: setresuid(0, 0, 0)
setresgid(0, 0, 0)
initgroups('root', 0) # or, replace with os.setgroups([]) I think, Python should detect what caller wants (up or down) and chose the correct sequence. Possibly add |
That is true, but is not the only issue... The I have a WIP patch which does all that but I'm not completely confident this won't have any unintended side-effects, won't change behaviour of any existing working code, and is worth the extra complexity/risk. If the maintainers (CC @giampaolo and @gpshead) think it might be worth doing I'll polish it off and push it out for consideration. If not this should probably be closed as "not planned": anyone needing to drop and then reacquire perms can always do it manually, e.g. by using |
Yeah, @duaneg - Could you make a Draft PR for what you were thinking at least for reference here even before anything has been decided? |
Right, that workaround does seem inherently unsafe. I've polished up the change and will push it out shortly. Unfortunately I don't think it is practical to unit test, as it requires root privileges. |
This is a preparatory refactoring which should have no semantic effect in itself but will hopefully make the real changes coming in subsequent patches easier to review.
Setting the saved user/group-ID allows the code to re-assume privileges after dropping them.
When dropping privileges we need to set the new effective UID last, so we have permission to change the gid/groups. When re-assuming root privileges we need to do the opposite: set the UID first so we then have permission to change gid/groups.
Uh oh!
There was an error while loading. Please reload this page.
for the last subprocess,
strace
of child process:Python 3.10.7
Linked PRs
The text was updated successfully, but these errors were encountered: