Skip to content

Commit 0271b8a

Browse files
authored
Add a mention of unix_fd as a similar crate. (#233)
* Add a mention of `unix_fd` as a similar crate. `unix_fd` has a `Chroot` type which is also a directory type that performs sandboxing, however similar to `pathrs`, it also resolves absolute paths as being relative to the root. * Add documentation about why cap-std uses `RESOLVE_BENEATH`. * Fix the heading to use the right term.
1 parent 1284204 commit 0271b8a

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,42 @@ sandbox, while `openat` doesn't support following symlinks.
205205

206206
`cap-std` has some similar functionality to [`pathrs`] in that it also
207207
explicitly verifies that `/proc` has actual `procfs` mounted on it and nothing
208-
mounted on top, and it can also use `openat2`. However, `cap-std` uses
209-
`RESOLVE_BENEATH`-style resolution where absolute paths are considered errors,
210-
while `pathrs` uses `RESOLVE_IN_ROOT` where absolute paths are interpreted as
211-
references to the base file descriptor. And overall, `cap-std` seeks to provide
212-
a portable `std`-like API which supports Windows in addition to Unix-like
213-
platforms, while `pathrs` provides a lower-level API that exposes more of the
214-
underlying `openat2` options and only supports Linux.
208+
mounted on top, and it can also use `openat2`. And it has some similar
209+
functionality to [`unix_fd`]. However, `cap-std` uses `RESOLVE_BENEATH`-style
210+
resolution where absolute paths are considered errors, while `pathrs` and
211+
`unix_fd` use `RESOLVE_IN_ROOT`-style resolution, where absolute paths are
212+
interpreted as references to the base file descriptor. And overall, `cap-std`
213+
seeks to provide a portable `std`-like API which supports Windows in addition
214+
to Unix-like platforms, while `pathrs` provides a lower-level API that exposes
215+
more of the underlying `openat2` options and only supports Linux, and `unix_fd`
216+
is specific to Unix-like platforms.
215217

216218
[`obnth`] is a new crate which appears to be very similar to `cap_std::fs`.
217219
It's not mature yet, and it doesn't support Windows. It does support
218220
`openat2`-like features such as `RESOLVE_NO_XDEV`, `RESOLVE_NO_SYMLINKS`,
219221
and `RESOLVE_IN_ROOT`, including emulation when `openat2` isn't available.
220222

223+
### Why use `RESOLVE_BENEATH`?
224+
225+
Capability-based security is all about *granularity*. We want to encourage
226+
applications and users to think about having separate handles for directories
227+
they need, so that they're isolated from each other, rather than in terms of
228+
having "root directories" containing multiple unrelated resources.
229+
230+
Also, some applications have "well known" absolute path strings present, such
231+
as "/etc/resolv.conf", and could accidentally use them within `Dir` methods.
232+
`RESOLVE_BENEATH` catches such errors early, rather than taking chances with
233+
user content inside the `Dir`.
234+
235+
And, `RESOLVE_BENEATH` handles symlinks within a `Dir` consistently. Accessing
236+
a symlink to an absolute path within a `Dir` is always an error. With
237+
`RESOLVE_IN_ROOT`, a symlink to an absolute path in a `Dir` may succeed, and
238+
potentially resolve to something different than it would when resolved through
239+
the process filesystem namespace.
240+
221241
[`arf-strings`]: https://github.com/bytecodealliance/arf-strings/
222242
[`openat`]: https://crates.io/crates/openat
223243
[`pathrs`]: https://crates.io/crates/pathrs
224244
[`obnth`]: https://crates.io/crates/obnth
225245
[`camino`]: https://crates.io/crates/camino
246+
[`unix_fd`]: https://crates.io/crates/unix_fd

0 commit comments

Comments
 (0)