Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-100163: allow re-assuming root privileges on subprocess invocations#134400
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
duaneg wants to merge4 commits intopython:mainChoose a base branch fromduaneg:gh-100163
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+74 −17
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This is a preparatory refactoring which should have no semantic effect initself but will hopefully make the real changes coming in subsequent patcheseasier to review.
Setting the saved user/group-ID allows the code to re-assume privileges afterdropping them.
When dropping privileges we need to set the new effective UID last, so we havepermission to change the gid/groups. When re-assuming root privileges we needto do the opposite: set the UID first so we then have permission to changegid/groups.
status: I'm marking this as a Draft as we're deciding (see issue) on if this is the right approach. manual testing likely required due to privs. required. |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
The
subprocess.Popen
class takes user/group/extra groups parameters which allow invocations to run as a different user. When dropping privileges (i.e. the main program is running as root but wants to run a subprocess as an unprivileged user) this works fine. However, it fails if a program wants to drop privileges and re-assume them to run a subprocess.To allow this there are a couple of changes required:
setresuid
/setresgid
instead ofsetreuid
/setregid
so the saved user/group identity can be re-assumed after it has been dropped.Naturally we need to continue to set the user identity last when going from root to an unprivileged user, so the order of calls needs to be determined dynamically based on whether we are switching to or from root.