many: implement a poor man's privileges drop, use for auth.json #4990
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.
This PR conceptually implements support for allowing you to do i/o on
a file as a less privileged user than you're currently running.
The nice, in-process approach doesn't work, as it needs Go 1.10's
semantics around runtime.LockOSThread.
This instead uses a helper,
privhelper
, that lives in libexec, thatknows how to read, write and remove a file, changing to a certain user
ahead of time.
We can't just use
su
, because su has strange requirements aroundrunning from a terminal, and the test suite barfs on it (in practice
it might work acceptably, but it being untestable is a big deal).
We'd rather not use
sudo
, as this is for something that mightalready be running under
sudo
and nesting sudos confuses somethings; better stay clear.
So this PR implements
sys.Setuid
andsys.Setgid
, with the samecaveats as they had in Go 1.3: it only affects the current thread (so
LockOSThread rears its head again).
This is the first helper that's meant to be run from
snap
, socmd.InternalToolPath
would panic at it. Perhaps a second iterationwould rework that so that the current approach of having logic in
dirs
is less weird.This replaces #4983 and fixes lp:1761193.