-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create sandbox for host file system access #783
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #783 +/- ##
==========================================
+ Coverage 68.95% 70.27% +1.32%
==========================================
Files 20 21 +1
Lines 2757 2981 +224
==========================================
+ Hits 1901 2095 +194
- Misses 856 886 +30 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
a8ff49a
to
38e7e46
Compare
This comment was marked as outdated.
This comment was marked as outdated.
d14cb43
to
0b243c1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
cf4b61a
to
6a11855
Compare
678b672
to
2f5355f
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
677c06e
to
d9d750c
Compare
@@ -150,9 +152,11 @@ pub struct UhyveVm<VirtBackend: VirtualizationBackend> { | |||
pub virtio_device: Arc<Mutex<VirtioNetPciDevice>>, | |||
#[allow(dead_code)] // gdb is not supported on macos | |||
pub(super) gdb_port: Option<u16>, | |||
pub(crate) mount: Mutex<UhyveFileMap>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above: mount
is a maybe misleading name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to investigate whether it's possible to add multiple different types of mounts, such as from an .img
file like in QEMU, together with the current UhyveFileMap approach. Additionally, we did discuss that we wanted to have a "similar interface" to Docker's, including by using the -v
parameter. It's not 100% "accurate", but I think it's close enough and leaves room for more features in the future.
Is this surely not the best option, compared to, say, mapping
?
I don't fully understand, what you mean by "adds all directories and the file itself in the map"? I think the map should not be altered once created (besides when new files/directories are created from the kernel). I see a lot of issues with dead entries in the map if this route is taken.
I am not sure if this is really that costly. How deep are directories typically nested? 10 entries deep? 10 string splits and lookups in a HashMap should not create a lot of overhead. |
Hm, I see. We could just check for the parent directory every time a file is opened then - the modifications should be minor. Do you think that we should check for child directories / files during the creation of the UhyveFileMap? |
this rebase will be fun :D adding you as a co-author to relevant commits |
No, why should we? A recursive lookup will be just fine. Also, this allows to reflect file/directory changes outside uhyve in the kernel during runtime. |
Well, you have a point (plus, this does make my job much easier, so even less of a reason to object, and it can be revisited later :D). I'll integrate it once the initial changes get an OK and once I'm done with rebasing and fixing up a few additional details that I've noticed. |
25fb0b3
to
426d061
Compare
Initial round of rebases is complete (based on your suggestions), I'll do one or two rounds to fix the remaining comments and the test. |
426d061
to
9bc1b51
Compare
* Add --mount parameter for "whitelisting" guest_paths and defining their respective filesystem paths on the host FS * Add UhyveFileMap structure * Add sandbox support to open() syscall A few points that could be further worked are unit tests, handling more of the parsing using the clap library directly and performance optimizations. Helped-by: Çağatay Yiğit Şahin <[email protected]> Helped-by: Jonathan Klimt <[email protected]> Co-authored-by: Jonathan Klimt <[email protected]>
Introduces a test for UhyveFileMap and adjusts existing tests accordingly.
- Rename file_map to mount - Temporarily remove short parameter - Temporarily remove environment variable - Don't split file_map params with commas - Change documentation, remove references to file_map variable - Minor improvements to tests
This commit modifies existing tests to support this new feature. An additional measure of modifying sysopen.flags was also introduced. Co-authored-by: Jonathan Klimt <[email protected]>
Also removes the "Introduction" header, as the header takes more space than the text itself now. Originally introduced in e7869a9.
9bc1b51
to
9a9937c
Compare
Co-authored-by: Jonathan Klimt <[email protected]>
... as it was deemed unnecessary and redundant. The tests were also modified accordingly.
9a9937c
to
42e1818
Compare
Depending on the error, we return EINVAL (like in the kernel itself) when O_DIRECTORY is used together with O_CREAT, EIO when the kernel requests to open a file that does not have a UTF-8 filename, and -ENOENT when the file is not present in the file map. The sysopen flags were moved to uhyve-interface for now.
new_file_test now runs a kernel called open_close_file, which attempts to open foo.txt, write to it, then closes the file, and attempts to open it again so as to read from it. This is more of a workaround because of the fact that we cannot read the temporary file easily, but it should work just as well and expand the test's coverage to "reading the contents of a file that is a temporary file on the host filesystem".
8c84686
to
c80cbe2
Compare
If the guest path is part of a directory that is not mapped, we'll recursively look for the parent directories and check if the parent directories are mapped. If that's the case, we'll use the file in the mapped host directory instead. This feature also comes with a unit test. We partially rely on PathBuf to prevent any funny behavior from taking place. A current flaw of this approach is that the filename that can be found in the OpenParams struct is "relative" instead of absolute, and providing paths that are otherwise whitelisted (e.g. "/root/file.txt" instead of "file.txt") will result in the map not return a result.
I pushed a new feature for directory support for A problem with the current implementation is that However, the current design needs to be reworked with the answers to the following questions in mind:
|
https://man7.org/linux/man-pages/man7/path_resolution.7.html
We could use |
/// | ||
/// Example: --mount host_dir:guest_dir --mount file.txt:guest_file.txt | ||
#[clap(long)] | ||
mount: Vec<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend to let the user define parameters using the UHYVE_<PARAMETER>
syntax. It was mentioned that "mount" is misleading here: #783 (comment)
However, there's an actual technical reason to adjust the name either on the Uhyve end or the Hermit end: HERMIT_MOUNT
is used by the kernel to define the mountpoint used by Uhyve: #783 (comment)
A few points that could be further worked are unit tests, handling more of the parsing using the clap library directly and performance optimizations.
Fixes #767