GeezerVison is showing github.com — Add host_env feature for sandbox isolation · RustPython/RustPython@dd10bf2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .cspell.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 113 | 113 | "pytype", | 114 | 114 | "reducelib", | 115 | 115 | "richcompare", | | 116 | + "rustix", | 116 | 117 | "RustPython", | 117 | 118 | "significand", | 118 | 119 | "struc", | |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/ci.yaml +15-2Lines changed: 15 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,8 +16,8 @@ concurrency: | 16 | 16 | cancel-in-progress: true | 17 | 17 |
| 18 | 18 | env: | 19 | | - CARGO_ARGS: --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls | 20 | | - CARGO_ARGS_NO_SSL: --no-default-features --features stdlib,importlib,stdio,encodings,sqlite | | 19 | + CARGO_ARGS: --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls,host_env | | 20 | + CARGO_ARGS_NO_SSL: --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,host_env | 21 | 21 | # Crates excluded from workspace builds: | 22 | 22 | # - rustpython_wasm: requires wasm target | 23 | 23 | # - rustpython-compiler-source: deprecated | @@ -153,6 +153,19 @@ jobs: | 153 | 153 | - name: check compilation without threading | 154 | 154 | run: cargo check ${{ env.CARGO_ARGS }} | 155 | 155 |
| | 156 | + - name: check compilation without host_env (sandbox mode) | | 157 | + run: | | | 158 | + cargo check -p rustpython-vm --no-default-features --features compiler | | 159 | + cargo check -p rustpython-stdlib --no-default-features --features compiler | | 160 | + cargo build --no-default-features --features stdlib,importlib,stdio,encodings,freeze-stdlib | | 161 | + if: runner.os == 'Linux' | | 162 | + | | 163 | + - name: sandbox smoke test | | 164 | + run: | | | 165 | + target/debug/rustpython extra_tests/snippets/sandbox_smoke.py | | 166 | + target/debug/rustpython extra_tests/snippets/stdlib_re.py | | 167 | + if: runner.os == 'Linux' | | 168 | + | 156 | 169 | - name: Test openssl build | 157 | 170 | run: cargo build --no-default-features --features ssl-openssl | 158 | 171 | if: runner.os == 'Linux' | |
Collapse file Copy file name to clipboardExpand all lines: Cargo.toml +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,8 @@ repository.workspace = true | 10 | 10 | license.workspace = true | 11 | 11 |
| 12 | 12 | [features] | 13 | | -default = ["threading", "stdlib", "stdio", "importlib", "ssl-rustls"] | | 13 | +default = ["threading", "stdlib", "stdio", "importlib", "ssl-rustls", "host_env"] | | 14 | +host_env = ["rustpython-vm/host_env", "rustpython-stdlib?/host_env"] | 14 | 15 | importlib = ["rustpython-vm/importlib"] | 15 | 16 | encodings = ["rustpython-vm/encodings"] | 16 | 17 | stdio = ["rustpython-vm/stdio"] | |
Collapse file Copy file name to clipboardExpand all lines: crates/stdlib/Cargo.toml +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,8 @@ license.workspace = true | 11 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 12 | 12 |
| 13 | 13 | [features] | 14 | | -default = ["compiler"] | | 14 | +default = ["compiler", "host_env"] | | 15 | +host_env = ["rustpython-vm/host_env"] | 15 | 16 | compiler = ["rustpython-vm/compiler"] | 16 | 17 | threading = ["rustpython-common/threading", "rustpython-vm/threading"] | 17 | 18 | sqlite = ["dep:libsqlite3-sys"] | |
Collapse file Copy file name to clipboardExpand all lines: crates/stdlib/src/lib.rs +105-48Lines changed: 105 additions & 48 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,12 +34,15 @@ mod sha512; | 34 | 34 |
| 35 | 35 | mod json; | 36 | 36 |
| 37 | | -#[cfg(not(any(target_os = "ios", target_arch = "wasm32")))] | | 37 | +#[cfg(all( | | 38 | + feature = "host_env", | | 39 | + not(any(target_os = "ios", target_arch = "wasm32")) | | 40 | +))] | 38 | 41 | mod locale; | 39 | 42 |
| 40 | 43 | mod _opcode; | 41 | 44 | mod math; | 42 | | -#[cfg(any(unix, windows))] | | 45 | +#[cfg(all(feature = "host_env", any(unix, windows)))] | 43 | 46 | mod mmap; | 44 | 47 | mod pyexpat; | 45 | 48 | mod pystruct; | @@ -48,57 +51,83 @@ mod statistics; | 48 | 51 | mod suggestions; | 49 | 52 | // TODO: maybe make this an extension module, if we ever get those | 50 | 53 | // mod re; | 51 | | -#[cfg(not(target_arch = "wasm32"))] | | 54 | +#[cfg(all(feature = "host_env", not(target_arch = "wasm32")))] | 52 | 55 | pub mod socket; | 53 | | -#[cfg(all(unix, not(target_os = "redox")))] | | 56 | +#[cfg(all(feature = "host_env", unix, not(target_os = "redox")))] | 54 | 57 | mod syslog; | 55 | 58 | mod unicodedata; | 56 | 59 |
| | 60 | +#[cfg(feature = "host_env")] | 57 | 61 | mod faulthandler; | 58 | | -#[cfg(any(unix, target_os = "wasi"))] | | 62 | +#[cfg(all(feature = "host_env", any(unix, target_os = "wasi")))] | 59 | 63 | mod fcntl; | 60 | | -#[cfg(not(target_arch = "wasm32"))] | | 64 | +#[cfg(all(feature = "host_env", not(target_arch = "wasm32")))] | 61 | 65 | mod multiprocessing; | 62 | | -#[cfg(all(unix, not(target_os = "redox"), not(target_os = "android")))] | | 66 | +#[cfg(all( | | 67 | + feature = "host_env", | | 68 | + unix, | | 69 | + not(target_os = "redox"), | | 70 | + not(target_os = "android") | | 71 | +))] | 63 | 72 | mod posixshmem; | 64 | | -#[cfg(unix)] | | 73 | +#[cfg(all(feature = "host_env", unix))] | 65 | 74 | mod posixsubprocess; | 66 | 75 | // libc is missing constants on redox | 67 | 76 | #[cfg(all( | 68 | 77 | feature = "sqlite", | 69 | 78 | not(any(target_os = "android", target_arch = "wasm32")) | 70 | 79 | ))] | 71 | 80 | mod _sqlite3; | 72 | | -#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))] | | 81 | +#[cfg(all( | | 82 | + feature = "host_env", | | 83 | + unix, | | 84 | + not(any(target_os = "android", target_os = "redox")) | | 85 | +))] | 73 | 86 | mod grp; | 74 | | -#[cfg(windows)] | | 87 | +#[cfg(all(feature = "host_env", windows))] | 75 | 88 | mod overlapped; | 76 | | -#[cfg(all(unix, not(target_os = "redox")))] | | 89 | +#[cfg(all(feature = "host_env", unix, not(target_os = "redox")))] | 77 | 90 | mod resource; | 78 | | -#[cfg(target_os = "macos")] | | 91 | +#[cfg(all(feature = "host_env", target_os = "macos"))] | 79 | 92 | mod scproxy; | 80 | | -#[cfg(any(unix, windows, target_os = "wasi"))] | | 93 | +#[cfg(all(feature = "host_env", any(unix, windows, target_os = "wasi")))] | 81 | 94 | mod select; | 82 | 95 |
| 83 | | -#[cfg(all(not(target_arch = "wasm32"), feature = "ssl-openssl"))] | | 96 | +#[cfg(all( | | 97 | + feature = "host_env", | | 98 | + not(target_arch = "wasm32"), | | 99 | + feature = "ssl-openssl" | | 100 | +))] | 84 | 101 | mod openssl; | 85 | | -#[cfg(all(not(target_arch = "wasm32"), feature = "ssl-rustls"))] | | 102 | +#[cfg(all( | | 103 | + feature = "host_env", | | 104 | + not(target_arch = "wasm32"), | | 105 | + feature = "ssl-rustls" | | 106 | +))] | 86 | 107 | mod ssl; | 87 | 108 | #[cfg(all(feature = "ssl-openssl", feature = "ssl-rustls"))] | 88 | 109 | compile_error!("features \"ssl-openssl\" and \"ssl-rustls\" are mutually exclusive"); | 89 | 110 |
| 90 | | -#[cfg(all(unix, not(target_os = "redox"), not(target_os = "ios")))] | | 111 | +#[cfg(all( | | 112 | + feature = "host_env", | | 113 | + unix, | | 114 | + not(target_os = "redox"), | | 115 | + not(target_os = "ios") | | 116 | +))] | 91 | 117 | mod termios; | 92 | | -#[cfg(not(any( | 93 | | - target_os = "android", | 94 | | - target_os = "ios", | 95 | | - target_os = "windows", | 96 | | - target_arch = "wasm32", | 97 | | - target_os = "redox", | 98 | | -)))] | | 118 | +#[cfg(all( | | 119 | + feature = "host_env", | | 120 | + not(any( | | 121 | + target_os = "android", | | 122 | + target_os = "ios", | | 123 | + target_os = "windows", | | 124 | + target_arch = "wasm32", | | 125 | + target_os = "redox", | | 126 | + )) | | 127 | +))] | 99 | 128 | mod uuid; | 100 | 129 |
| 101 | | -#[cfg(feature = "tkinter")] | | 130 | +#[cfg(all(feature = "host_env", feature = "tkinter"))] | 102 | 131 | mod tkinter; | 103 | 132 |
| 104 | 133 | use rustpython_common as common; | @@ -122,69 +151,97 @@ pub fn stdlib_module_defs(ctx: &Context) -> Vec<&'static builtins::PyModuleDef> | 122 | 151 | cmath::module_def(ctx), | 123 | 152 | contextvars::module_def(ctx), | 124 | 153 | csv::module_def(ctx), | | 154 | + #[cfg(feature = "host_env")] | 125 | 155 | faulthandler::module_def(ctx), | 126 | | - #[cfg(any(unix, target_os = "wasi"))] | | 156 | + #[cfg(all(feature = "host_env", any(unix, target_os = "wasi")))] | 127 | 157 | fcntl::module_def(ctx), | 128 | | - #[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))] | | 158 | + #[cfg(all( | | 159 | + feature = "host_env", | | 160 | + unix, | | 161 | + not(any(target_os = "android", target_os = "redox")) | | 162 | + ))] | 129 | 163 | grp::module_def(ctx), | 130 | 164 | hashlib::module_def(ctx), | 131 | 165 | json::module_def(ctx), | 132 | | - #[cfg(not(any(target_os = "ios", target_arch = "wasm32")))] | | 166 | + #[cfg(all( | | 167 | + feature = "host_env", | | 168 | + not(any(target_os = "ios", target_arch = "wasm32")) | | 169 | + ))] | 133 | 170 | locale::module_def(ctx), | 134 | 171 | #[cfg(not(any(target_os = "android", target_arch = "wasm32")))] | 135 | 172 | lzma::module_def(ctx), | 136 | 173 | math::module_def(ctx), | 137 | 174 | md5::module_def(ctx), | 138 | | - #[cfg(any(unix, windows))] | | 175 | + #[cfg(all(feature = "host_env", any(unix, windows)))] | 139 | 176 | mmap::module_def(ctx), | 140 | | - #[cfg(not(target_arch = "wasm32"))] | | 177 | + #[cfg(all(feature = "host_env", not(target_arch = "wasm32")))] | 141 | 178 | multiprocessing::module_def(ctx), | 142 | | - #[cfg(all(not(target_arch = "wasm32"), feature = "ssl-openssl"))] | | 179 | + #[cfg(all( | | 180 | + feature = "host_env", | | 181 | + not(target_arch = "wasm32"), | | 182 | + feature = "ssl-openssl" | | 183 | + ))] | 143 | 184 | openssl::module_def(ctx), | 144 | | - #[cfg(windows)] | | 185 | + #[cfg(all(feature = "host_env", windows))] | 145 | 186 | overlapped::module_def(ctx), | 146 | | - #[cfg(unix)] | | 187 | + #[cfg(all(feature = "host_env", unix))] | 147 | 188 | posixsubprocess::module_def(ctx), | 148 | | - #[cfg(all(unix, not(target_os = "redox"), not(target_os = "android")))] | | 189 | + #[cfg(all( | | 190 | + feature = "host_env", | | 191 | + unix, | | 192 | + not(target_os = "redox"), | | 193 | + not(target_os = "android") | | 194 | + ))] | 149 | 195 | posixshmem::module_def(ctx), | 150 | 196 | pyexpat::module_def(ctx), | 151 | 197 | pystruct::module_def(ctx), | 152 | 198 | random::module_def(ctx), | 153 | | - #[cfg(all(unix, not(target_os = "redox")))] | | 199 | + #[cfg(all(feature = "host_env", unix, not(target_os = "redox")))] | 154 | 200 | resource::module_def(ctx), | 155 | | - #[cfg(target_os = "macos")] | | 201 | + #[cfg(all(feature = "host_env", target_os = "macos"))] | 156 | 202 | scproxy::module_def(ctx), | 157 | | - #[cfg(any(unix, windows, target_os = "wasi"))] | | 203 | + #[cfg(all(feature = "host_env", any(unix, windows, target_os = "wasi")))] | 158 | 204 | select::module_def(ctx), | 159 | 205 | sha1::module_def(ctx), | 160 | 206 | sha256::module_def(ctx), | 161 | 207 | sha3::module_def(ctx), | 162 | 208 | sha512::module_def(ctx), | 163 | | - #[cfg(not(target_arch = "wasm32"))] | | 209 | + #[cfg(all(feature = "host_env", not(target_arch = "wasm32")))] | 164 | 210 | socket::module_def(ctx), | 165 | 211 | #[cfg(all( | 166 | 212 | feature = "sqlite", | 167 | 213 | not(any(target_os = "android", target_arch = "wasm32")) | 168 | 214 | ))] | 169 | 215 | _sqlite3::module_def(ctx), | 170 | | - #[cfg(all(not(target_arch = "wasm32"), feature = "ssl-rustls"))] | | 216 | + #[cfg(all( | | 217 | + feature = "host_env", | | 218 | + not(target_arch = "wasm32"), | | 219 | + feature = "ssl-rustls" | | 220 | + ))] | 171 | 221 | ssl::module_def(ctx), | 172 | 222 | statistics::module_def(ctx), | 173 | 223 | suggestions::module_def(ctx), | 174 | | - #[cfg(all(unix, not(target_os = "redox")))] | | 224 | + #[cfg(all(feature = "host_env", unix, not(target_os = "redox")))] | 175 | 225 | syslog::module_def(ctx), | 176 | | - #[cfg(all(unix, not(any(target_os = "ios", target_os = "redox"))))] | | 226 | + #[cfg(all( | | 227 | + feature = "host_env", | | 228 | + unix, | | 229 | + not(any(target_os = "ios", target_os = "redox")) | | 230 | + ))] | 177 | 231 | termios::module_def(ctx), | 178 | | - #[cfg(feature = "tkinter")] | | 232 | + #[cfg(all(feature = "host_env", feature = "tkinter"))] | 179 | 233 | tkinter::module_def(ctx), | 180 | 234 | unicodedata::module_def(ctx), | 181 | | - #[cfg(not(any( | 182 | | - target_os = "android", | 183 | | - target_os = "ios", | 184 | | - target_os = "windows", | 185 | | - target_arch = "wasm32", | 186 | | - target_os = "redox" | 187 | | - )))] | | 235 | + #[cfg(all( | | 236 | + feature = "host_env", | | 237 | + not(any( | | 238 | + target_os = "android", | | 239 | + target_os = "ios", | | 240 | + target_os = "windows", | | 241 | + target_arch = "wasm32", | | 242 | + target_os = "redox" | | 243 | + )) | | 244 | + ))] | 188 | 245 | uuid::module_def(ctx), | 189 | 246 | zlib::module_def(ctx), | 190 | 247 | ] | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/Cargo.toml +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,8 @@ repository.workspace = true | 10 | 10 | license.workspace = true | 11 | 11 |
| 12 | 12 | [features] | 13 | | -default = ["compiler", "wasmbind", "stdio", "gc"] | | 13 | +default = ["compiler", "wasmbind", "gc", "host_env", "stdio"] | | 14 | +host_env = [] | 14 | 15 | stdio = [] | 15 | 16 | importlib = [] | 16 | 17 | encodings = ["importlib"] | |
|