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

many: implement a poor man's privileges drop, use for auth.json #4990

Closed
wants to merge 1 commit into from

Conversation

chipaca
Copy link
Contributor

@chipaca chipaca commented Apr 5, 2018

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, that
knows 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 around
running 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 might
already be running under sudo and nesting sudos confuses some
things; better stay clear.

So this PR implements sys.Setuid and sys.Setgid, with the same
caveats 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, so
cmd.InternalToolPath would panic at it. Perhaps a second iteration
would rework that so that the current approach of having logic in
dirs is less weird.

This replaces #4983 and fixes lp:1761193.

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, that
knows 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 around
running 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 might
already be running under `sudo` and nesting sudos confuses some
things; better stay clear.

So this PR implements `sys.Setuid` and `sys.Setgid`, with the same
caveats 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`, so
`cmd.InternalToolPath` would panic at it. Perhaps a second iteration
would rework that so that the current approach of having logic in
`dirs` is less weird.
Copy link
Collaborator

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

I liked #4983 better. Any chance we could get that working instead of this one?

// For read/remove we could just call cat and rm, but for write we
// need something custom as we want the write to be atomic. So this
// helper is needed for the latter case at least; the other two are
// done here as well for consistency's sake. Furhtermore using su has
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/Furhtermore/Furthermore/

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about runuser?

@bboozzoo
Copy link
Collaborator

bboozzoo commented Apr 6, 2018

Left some comments in #4983 as well.

@chipaca
Copy link
Contributor Author

chipaca commented Apr 6, 2018

Three cheers for @bboozzoo for reminding me about euids! back to 4983.

@chipaca chipaca closed this Apr 6, 2018
@chipaca chipaca deleted the poorman-drop-privs branch June 4, 2019 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants