ebkalderon / bastille

Process sandboxing library written in Rust
Apache License 2.0
7 stars 0 forks source link

Configure stdio using std::process::Command builder #2

Open ebkalderon opened 4 years ago

ebkalderon commented 4 years ago

Because we cannot extract and inspect the std::process::Stdio from the std::process::Command builder passed to Sandbox::spawn(), we cannot determine at runtime whether to pipe or inherit our stdin/stdout/stderr descriptors. As a result, Bastille currently defaults to Stdio::inherit() for all three by default and can be switched to piped stdin/stdout/stderr if compiled with the piped Cargo feature.

This is not at all ideal, but fixing this requires resolving rust-lang/rust#44434 and also finding some way to inspect whether a given std::process::Stdio is set to "inherit," "piped," or "null."

An alternative but less desirable approach would be to implement our own in-crate Stdio type like how we currently do with Child. Still, it would be best to reuse as many std::process types as possible when configuring and spawning commands in Bastille.

ebkalderon commented 4 years ago

Documented the current limitation in commit a252d44.

ebkalderon commented 4 years ago

At the time of writing, we use Cargo features to set the stdio configuration for the launched process. This is not ideal and will be replaced by a dedicated Rust API in the future, but the approach works well enough for now. The following modes are available, as defined in the Cargo.toml:

Feature stdin stdout stderr
default Inherit Inherit Inherit
piped Piped Piped Piped
piped-merged Piped Piped Merged with stdout