Stabilize std::os::unix::process::CommandExt::chroot (process_chroot) - #163067
joshtriplett wants to merge 1 commit into
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This has been around since May 2025, without issue. I think it's more than ready to stabilize. Shall we stabilize it? @rfcbot merge libs |
|
@joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns. |
|
Are there any test cases for this? I don't think I see any in the original PR (#137759) or in grep for chroot in our code. I guess we'd need to condition such a test case on being able to run privileged, but I think in CI we can, so it seems valuable. Absent those, have we confirmed this actually works at least manually? The os::unix::fs::chroot API is documented as:
I assume the same applies here? Can we amend the documentation to note that? That API is also cfg'd away on fuchsia, instead of returning Unsupported like the process one. I assume we want to go with Unsupported as implemented here (and on slightly more targets - fuchsia, vxworks, wasi)? |
|
If you use the unshare syscall you can use chroot without needing to run as root (on Linux). |
|
In addition to the missing tests, there are no examples. They'll have to be |
|
I want to point out that |
|
fwiw, the docs should probably also mention that - strictly speaking - this function is not documented to be async-signal-safe, and we should link to the docs of chroot. otherwise seems good per today's meeting ^^ |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
We have requests for tests (if possible), examples, and improved documentation. I think that's all worth a blocking concern, if anybody is willing to raise one on my behalf. |
|
@rfcbot concern tests, examples and improved documentation |
|
I've posted #163180 to update the documentation. That PR adds an example, adds a manpage link, adds a mention that it requires privileges, and adds an explanation that POSIX doesn't require it to be async-signal-safe but it's safe in practice on our targets. I don't think a runnable test is feasible; our testsuite shouldn't be run as root. On Linux specifically, we could theoretically provide a test that runs via |
I think if we're going to add root-only APIs to std, we should have a test suite that does require root and runs as such. It seems easy to do that in CI. Infra work for that should be pretty trivial. |
|
At the end of the day it is a fairly trivial wrapper around |
Note that this is an issue 8 doc, but However, as far as I can tell, no popular platform's manpages say this is safe to do, e.g. https://man7.org/linux/man-pages/man2/chroot.2.html makes no mention and https://man7.org/linux/man-pages/man7/signal-safety.7.html only describes POSIX. Are we actually comfortable enabling this code unconditionally if it might be completely broken? I'm hesitant to take pervasiveness of a pattern in C on some platforms as truth that this will be sound on all platforms that have a It seems safer to start with Linux and a few other popular platforms that we can confirm are sound, error on spawn otherwise. And leave it up to target maintainers to enable other platforms if they can confirm soundness. Ideally by updating their documentation...
We could also totally forget to actually call |
|
To be clear, I see no reason why we can't sudo in CI specifically (though probably best not to do that locally) but if we just want to make sure that |
|
There is also the I would advise using that, at least on targets where we do definitely call out to libc for all relevant file operations. |
|
Also for docs, I think this was brought up in the meeting but worth restating publicly here that the docs should specify that it's not actually a security boundary and it's possible to e.g. access directories outside of the chroot ^^ |
|
^ agreed, requested at #163180 (comment) |
View all comments
Tracking issue: #141298