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
397 changes: 307 additions & 90 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
resolver = "2"
members = [
"components/chroot",
"components/readonly",
"components/gate",
"components/latch-defer-all",
"components/latch-deny-all",
"components/latch-deny-random",
"components/latch-deny-symlink-at",
"components/latch-n2",
"components/latch-n3",
"components/latch-n4",
"components/latch-n5",
"components/latch-path-glob",
"components/latch-readonly",
"components/trace",
"crates/filesystem-latch",
"crates/filesystem-latch-n",
"crates/test-harness",
]

[workspace.dependencies]
chrono = { git = "https://github.com/chronotope/chrono.git", branch = "0.5.x" }
componentized-rt = { path = "./crates/componentized-rt" }
filesystem-latch = { path = "./crates/filesystem-latch" }
filesystem-latch-n = { path = "./crates/filesystem-latch-n" }
heck = "0.5"
tempfile = "3"
test-harness = { path = "./crates/test-harness" }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] }
wac-graph = "0.12"
wasmtime = { version = "49", features = ["component-model-async"] }
wasmtime-wasi = { version = "49", features = ["p3"] }
wit-bindgen = { version = "0.62.0", features = ["async-spawn"] }
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ clean: clean-components clean-wit
clean-all: clean-components clean-tools clean-wit
cargo clean


.PHONY: test
test: components
cargo test --workspace
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ A collection of utility components that remix wasi:filesystem types and interfac
## Components

- [`chroot`](./components/chroot/)
- [`readonly`](./components/readonly/)
- [`gate`](./components/gate/)
- [`latch-deny-all`](./components/latch-deny-all/)
- [`latch-deny-random`](./components/latch-deny-random/)
- [`latch-deny-symlink-at`](./components/latch-deny-symlink-at/)
- [`latch-defer-all`](./components/latch-defer-all/)
- [`latch-n2`](./components/latch-n2/)
- [`latch-n3`](./components/latch-n3/)
- [`latch-n4`](./components/latch-n4/)
- [`latch-n5`](./components/latch-n5/)
- [`latch-readonly`](./components/latch-readonly/)
- [`trace`](./components/trace/)

## Build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "readonly"
name = "gate"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
Expand All @@ -8,7 +8,9 @@ license = "Apache-2.0"
crate-type = ["cdylib"]

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

[dev-dependencies]
Expand Down
41 changes: 41 additions & 0 deletions components/gate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# `gate`

Filesystem gate access control for preopens and descriptors.

Each operation is authorized by the imported latch before it reaches the filesystem, then the latch is told the final decision with `observe-decision`. Descriptor operations are authorized with the descriptor, its path, and the operation's arguments. The path of a preopen is its name, e.g. `/`, a descriptor opened with `open-at` has the path it was opened at, with `.` and `..` applied and symlinks followed where the host follows them. Testing whether two descriptors are the same object with `is-same-object` is not gated.

How a denial is enforced depends on the operation:

- Most operations fail with the error code the latch denied them with.
- `read-via-stream` and `read-directory` return an empty stream, and the future resolves to the error.
- `write-via-stream` and `append-via-stream` do not read the data stream, and the future resolves to the error.
- Getting the preopens is authorized once, a denial returns no preopens. Each preopen is then authorized individually, a denied preopen is left out and the other preopens are returned.
- Directory entries are authorized individually as they are read. A denied entry is left out of the stream and the read continues with the next entry.

Denials are logged as warnings, except denied preopens and directory entries, which are left out rather than failed and are logged at the trace level:

```
Denied REASON=access OPERATION=wasi:filesystem/types#descriptor.open-at FD=/ PATH-FLAGS=() PATH=file.txt OPEN-FLAGS=(create) FLAGS=(read|write)
Denied REASON=access OPERATION=wasi:filesystem/types#descriptor.read-directory FD=/ NAME=file.txt TYPE=regular-file
```

A latch error, or a failure to observe the decision, fails the operation with `other`, prefixed with `latch-error:`, and is logged as an error. A latch error for a directory entry ends the stream and fails the read. Getting the preopens can not fail, a latch error traps instead.

```
Latch error CODE=invalid-config<latch-path-glob> OPERATION=wasi:filesystem/types#descriptor.stat FD=/file.txt
```

## Interfaces

Imports:

- `componentized:filesystem/latch@0.3.0-dev`: decides whether each operation may proceed
- `wasi:logging/logging@0.1.0-draft`: logs denials and latch errors
- `wasi:clocks/system-clock@0.3.0`: types used by wasi:filesystem/types
- `wasi:filesystem/types@0.3.0`: the descriptors the gated descriptors wrap
- `wasi:filesystem/preopens@0.3.0`: the preopens the gated preopens wrap

Exports:

- `wasi:filesystem/types@0.3.0`: descriptors gated by the latch
- `wasi:filesystem/preopens@0.3.0`: preopens gated by the latch
File renamed without changes.
Loading
Loading