feat: support read-only filesystem mounts#85
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for marking preopened host filesystem mounts as read-only, and enforces that policy in the host-side fs_* tool handlers so guest write-like operations are denied while reads continue to work.
Changes:
- Extend
Preopenwith aread_only: boolflag and a builder-style.read_only()helper. - Track the read-only flag per mount in
FsRouterand gate write operations viarequire_writable(). - Add unit tests covering read-only behavior across the affected fs_* operations; bump host crate version to
0.7.0.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| host/src/lib.rs | Adds Preopen::read_only, propagates mount RO state into FsRouter, gates write operations, and adds RO mount tests. |
| host/Cargo.toml | Bumps crate version to 0.7.0. |
| host/Cargo.lock | Updates lockfile to reflect version bump. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+200
to
+204
| /// Return a copy of this preopen with `read_only` set to `true`. | ||
| pub fn read_only(mut self) -> Self { | ||
| self.read_only = true; | ||
| self | ||
| } |
Comment on lines
+1720
to
+1725
| fn require_writable<'a>(&'a self, path: &'a str) -> Result<(&'a FsSandbox, &'a str)> { | ||
| let (fs, rel, ro) = self.route(path)?; | ||
| if ro { | ||
| return Err(anyhow!("read-only mount: write to {:?} denied", path)); | ||
| } | ||
| Ok((fs, rel)) |
Signed-off-by: danbugs <danilochiarlone@gmail.com>
Signed-off-by: danbugs <danilochiarlone@gmail.com>
e3c59a2 to
399c361
Compare
Contributor
There was a problem hiding this comment.
Linux Benchmarks
Details
| Benchmark suite | Current: 399c361 | Previous: 05c4d64 | Ratio |
|---|---|---|---|
hello_world (median) |
20 ms |
20 ms |
1 |
pandas (median) |
110 ms |
110 ms |
1 |
density (per VM) |
11 MB |
11 MB |
1 |
snapshot (disk) |
656 MiB |
656 MiB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
Contributor
There was a problem hiding this comment.
Windows Benchmarks
Details
| Benchmark suite | Current: 399c361 | Previous: 05c4d64 | Ratio |
|---|---|---|---|
hello_world (median) |
379 ms |
320 ms |
1.18 |
pandas (median) |
1090 ms |
855 ms |
1.27 |
density (per VM) |
11 MB |
11 MB |
1 |
snapshot (disk) |
663 MiB |
663 MiB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
read_only: boolfield toPreopenwith a builder-style.read_only()methodFsRoutercarries the flag per-mount and exposesrequire_writable()which gates all write operationsfs_write,fs_write_bytes,fs_truncate,fs_mkdir, andfs_unlinkreturn"read-only mount: write to <path> denied"when targeting a read-only preopenfs_read,fs_read_bytes,fs_list,fs_stat) work normally on read-only mountsTest plan
readonly_mount_allows_reads— reads succeed on RO mountreadonly_mount_blocks_fs_write— text write deniedreadonly_mount_blocks_fs_write_bytes— binary write deniedreadonly_mount_blocks_fs_truncate— truncate deniedreadonly_mount_blocks_fs_mkdir— mkdir deniedreadonly_mount_blocks_fs_unlink— unlink denied, file preservedmixed_rw_and_ro_mounts— RW and RO mounts coexist correctly