Skip to content
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

Capabilities granularity too low #90

Closed
dumblob opened this issue Apr 2, 2019 · 4 comments
Closed

Capabilities granularity too low #90

dumblob opened this issue Apr 2, 2019 · 4 comments
Labels
wasi:api Issues pertaining to the WASI API, not necessarily specific to Wasmtime.

Comments

@dumblob
Copy link

dumblob commented Apr 2, 2019

Most existing capability-based systems have either of the following issues.

  1. Too low granularity of capabilities (an app can access network, but actually should be allowed to access e.g. just several OSI 4 or higher protocols, have limited bandwidth, shouldn't have access to any OSI 3 or lower information, etc.)

  2. Too high granularity (e.g. SELinux is super complex which is contra-productive as it's therefore quite often ignored or quite incorrectly configured)

To solve this, capabilites shouldn't be fix, but rather shall be a turing-complete executable code/assembly (imagine Linux BPF JIT). Then one can provide a standard library with low-grained capability-building-blocks (like e.g. Android does) and allow for fine-grained specification in all scenarios.

How do you want to approach this granularity/complexity issue in WASI?

@sunfishcode sunfishcode added the wasi:api Issues pertaining to the WASI API, not necessarily specific to Wasmtime. label Apr 2, 2019
@sunfishcode
Copy link
Member

My rough idea is that Mandatory Access Control (MAC) is out of scope for WASI, at least for now. That is, at the point of resolving a filesystem path or configuring a network socket or otherwise obtaining a new resource handle, the host environment may be permitted to apply additional rules to determine if access should be granted, such as SELinux or other systems. As you say, this can be pretty complex.

For filesystem support, WASI currently has a directory-oriented capability model. Wasm code can be granted access to a directory, providing it access to the contents of that directory. This access can be restricted to being readonly or other things, but there's no finer-grained path filtering currently.

For networking support, my rough idea (mentioned here) is that we could introduce a kind of capability which represents a set of sockets that can be created. For TCP-like sockets, this might look like a set of address (source and destination), port (source and destination), and protocol tuples that application code might create and configure a socket on.

My rough idea for both of these is to look for sweet-spot solutions that work for the majority of cases while still being really simple, and leave the more specialized cases to host/environment-specific mechanisms outside of WASI. However, this may also be a result of my lacking experience with BPF-style filtering -- to me, it sounds more complex, sounds like functionality that's only needed in highly specialized circumstances, and any time you add a new turing-complete mechanism to an overall system in a security-relevant area, my generic experience is that you have to be very very cautious.

However, if someone who has more experience with BPF or similar mechanisms wanted to make a writeup showing how it would work for WebAssembly, it'd be a great topic for the CG subgroup to discuss.

@npmccallum
Copy link
Member

@sunfishcode I don't understand how capabilities are in scope for WASI. Could you clarify this? APIs don't enforce capabilities, implementations of those APIs do.

@npmccallum
Copy link
Member

As an example, let's say we have TCP-like sockets. We want to restrict the WASM to connect() only to a single address. If you're running on Linux (most all of us are), you just put the runtime in a cgroup and set iptables rules on that cgroup. The connect() command will fail on everything but the specified address. But this has nothing to do with the API itself. This is entirely enforced by the host OS. Where the host OS doesn't provide such capabilities, the runtime can add them. But it doesn't impact the API.

@sunfishcode
Copy link
Member

Continuing the discussion here now that we have a dedicated repo.

kubkon pushed a commit that referenced this issue Nov 7, 2019
* Mark public API functions as unsafe.

This marks the public hostcalls functions as unsafe.

This is generalizing from Rust's `from_raw_fd` function, which is
unsafe. The observation is that nothing prevents code using this
function from passing a bogus or stale dangling file descriptor and
corrupting an arbitrary open stream.

Technically, some of these functions don't use file descriptors, such as
random, clocks, and a few others. However I expect that in the future,
random and clocks will switch to using file descriptors anyway, and it
keeps the macro definitions simpler if we only have to handle one form.

* Mark WasiCtx functions that operate on file descriptors unsafe too.

* `fd_filestat_set_times_impl` doesn't need to be unsafe.

* Remove unnecessary unsafes
grishasobol pushed a commit to grishasobol/wasmtime that referenced this issue Nov 29, 2021
* Add first bench

* Refactor travis.yml

* Use assert_matches!

* sha3_256 → keccak256
pchickey added a commit to pchickey/wasmtime that referenced this issue May 12, 2023
…rt_preopens_environment_2

Import functions provide environment variables and preopens
pchickey added a commit to pchickey/wasmtime that referenced this issue May 16, 2023
…rt_preopens_environment_2

Import functions provide environment variables and preopens
dhil added a commit to dhil/wasmtime that referenced this issue Feb 5, 2024
This patch adds a few WasmFX + WASI test programs to the testsuite. The
tests are run in both sync and async mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi:api Issues pertaining to the WASI API, not necessarily specific to Wasmtime.
Projects
None yet
Development

No branches or pull requests

3 participants