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

feat(unstable): allow specifing gid and uid for subprocess #11586

Merged
merged 8 commits into from
Sep 13, 2021

Conversation

crowlKats
Copy link
Member

Closes #5506

Comment on lines 2044 to 2045
* On unix `opt.gid` and `opt.uid` can be used to define the gid and uid for
* the subprocess.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's going to be clear to most users what this means. Can I suggest copying the description from libstd's CommandExt?

Sets the child process’s user ID. This translates to a setuid call in the child process. Failure in the setuid call will cause the spawn to fail.

And:

Similar to uid, but sets the group ID of the child process. This has the same semantics as the uid field.

I'd argue changing uid/gid without being able to drop group membership is insecure (a mistake I made in libuv) but .groups() is experimental in libstd and tokio doesn't support it at all.

Copy link
Member

Choose a reason for hiding this comment

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

@crowlKats please update doc with Ben's suggestion.

I'd argue changing uid/gid without being able to drop group membership is insecure (a mistake I made in libuv) but .groups() is experimental in libstd and tokio doesn't support it at all.

@bnoordhuis what would you suggest in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either hold off on merging until Tokio grows the right APIs or add a really big warning to the documentation.

The problem with a warning is that it's not actionable. There's no way to detect an insecure situation and act on it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, as you point out the second option is not actionable. Let's hold off merging, and open an feature request to tokio.

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at how libstd implements Command::spawn() (which tokio wraps) and it calls setgroups(0, null()) to drop group membership (barring bug rust-lang/rust#88716) so, on second thought, this is probably good to merge.

If you wanted to be extra secure, you could add a Unix-ony pre_exec hook that calls setgroups(0, null()).

Copy link
Member

Choose a reason for hiding this comment

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

@crowlKats could you add that call to pre_exec that Ben pointed out?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bartlomieju bartlomieju added this to the 1.14.0 milestone Aug 24, 2021
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@bartlomieju bartlomieju merged commit a655a0f into denoland:main Sep 13, 2021
@crowlKats crowlKats deleted the set_gid/uid branch September 14, 2021 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set gid/uid for subprocess
4 participants