Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,484 changes: 2,261 additions & 223 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ members = [
"components/chroot",
"components/readonly",
"components/tracing",
"crates/test-harness",
]

[workspace.dependencies]
chrono = { git = "https://github.com/chronotope/chrono.git", branch = "0.5.x" }
componentized-rt = { path = "./crates/componentized-rt" }
heck = "0.5"
wit-bindgen = "0.62.0"
tempfile = "3"
test-harness = { path = "./crates/test-harness" }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] }
wasmtime = { version = "49", features = ["component-model-async"] }
wasmtime-wasi = { version = "49", features = ["p3"] }
wit-bindgen = { version = "0.62.0", features = ["async-spawn"] }

[profile.release]
opt-level = "s"
Expand Down
7 changes: 7 additions & 0 deletions components/chroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ license = "Apache-2.0"
crate-type = ["cdylib"]

[dependencies]
componentized-rt = { workspace = true, features = ["executor"] }
wit-bindgen = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
test-harness = { workspace = true }
tokio = { workspace = true }
wasmtime = { workspace = true }
16 changes: 15 additions & 1 deletion components/chroot/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# `chroot`

Virtualizes the wasi:filesystem interfaces limiting all access to a specific directory defined by the 'path' key in a wasi:config/store, mimicking the Unix chroot command.
Virtualizes the `wasi:filesystem` interfaces limiting all access to a specific directory defined by the 'path' key in a `wasi:config/store`, mimicking the GNU chroot command.

The chroot is exported as a single preopened directory, `.`, a virtual scope rather than a root, since a wasi preopen need not be rooted. The `path` is a path within one of the imported preopens, the preopen whose name is the longest prefix of the path, e.g. `/srv/jail` with a preopen `/` is the directory `srv/jail` of that preopen. The path must not contain `..`. The directory is opened by the first operation on the root that needs it, an operation on the root fails when the directory doesn't exist.

Paths are resolved like a GNU chroot:

- an absolute path is resolved from the root of the chroot, the exported `.`, from any descriptor
- `..` of the root is the root, e.g. `/../../etc/passwd` is `/etc/passwd` within the chroot
- `..` is resolved lexically before the path is given to the host, `a/b/..` is `a` even when `b` is a symlink
- a descriptor below the root doesn't know where it is, it may have been moved, so like any wasi descriptor a path naming one of its parents, e.g. `../file`, fails with `not-permitted`
- a path containing a NUL byte fails with `illegal-byte-sequence`

Symlinks are followed by the host, which confines them to the descriptor they are followed from, a symlink leading out of the chroot can be created and read, but not followed. A symlink with an absolute target is not followed, it would be resolved from the host's root rather than the chroot's.

The synchronous `read-via-stream`, `write-via-stream`, `append-via-stream` and `read-directory` can't wait for the root to be opened, until it is they run on a background thread and their results are forwarded, so the host must support component model threads, e.g. `wasmtime -W component-model-threading`.
7 changes: 7 additions & 0 deletions components/chroot/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
// componentized_rt::executor's thread is started with thread.new-indirect, which calls through
// the exported function table
if std::env::var("CARGO_CFG_TARGET_FAMILY").as_deref() == Ok("wasm") {
println!("cargo:rustc-link-arg-cdylib=--export-table");
}
}
Loading
Loading