-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[feat] Re-design the Tauri APIs around capability-based security #6107
Comments
Since this will be a breaking change - if we do this, can we add some static analysis in the cli / console that offers them support when they hit this wall? |
good point! migration-wise or just general support with this? |
Migrations would be a positive way to show good faith and wanting to help people transition to 2.0. |
I started to research possible ways to integrate the capabilities approach into tauri and it seems like that The big but is that there is no other public crate (known to me) which tries to implement the capabilities approach into rust (async) std and we should take the chance to slowly migrate our API code to facilitate the methods offered by The lower layer ( As we need to re-design our API for supporting all operating systems properly, as mentioned in the initial issue post, this could be our chance to figure out where we can plug-in the cap based code and where we need workarounds for now. Footnotes |
Removed this from 2.0 as we have a new allow list system (named capabilities) and the work to go full "real" capability is not feasible for the next foreseeable future. Marked as stale. |
Describe the problem
With mobile on the horizon we face the problem that most of Tauri's APIs do not work on mobile. This has several reasons:
dirs-next
)Problem one can be resolved by contributing fixes, working with upstream authors, forking or replacing crates etc. But problem two is a major blocker in my opinion. While Tauri can technically run on both iOS and Android (which is already frigging awesome!) theres not much you can do with it yet.
Scopes
As my proposal going forward focuses mostly on permissions, I want to bring up another big problem in the current implementation: Scopes.
There is also absolutely no feedback to the user if they made an error in their scope pattern.
Describe the solution you'd like
Since we need to re-design large parts of the API anyway, due to the aforementioned mobile compatibility issues we should seize this opportunity of that major bump and redesign our API in a way that makes Tauri applications much more secure by default.
What is the solution I am proposing?
We redesign the API from the ground up with two Concepts in mind: Capability-based security and Host/Guests. A big inspiration here is the WASI specification.
Host/Guest
This term comes from Virtual Machines and just formalizes how we have been thinking about Tauri.
The Host is the trusted Rust process that is at the heart of a Tauri app. It owns all resources and has unfettered access to the OS.
A Guest is a process that is connected to the Host through the IPC bridge. It may request access to resources, and ask the Host to perform actions on its behalf. We currently consider the WebView to be the Guest but going forward we consider each window to be a Guest. Another example of a Guest would be a running WASM extension, or a running Deno v8 isolate.
Capability-based security
Capabilities is an unforgeable references to something the Host owns. A Guest may request a reference to that resource, which is represented by a random integer. That integer is used a key in the Resource Table (
resource_table = HashMap<u64, Resource>
).The key takeaways are:
Read
andWrite
. A Resource can have zero, one or more permissions attached to it. Restricting the type of usage of a resource is currently not possible.pledge
andunveil
from OpenBSD.fs
module. The Guest requests access to thedocument_dir
, the Host returns aDir
reference.Dir
only has relative APIs, so the guest may open files within thatDir
, but not outside of it. When opening another directory withinDir
, aDir
is returned again.UNUserNotificationCenter
instance and the options we created it with (wether needed access to icon badges for example) we then return a reference to that Resource. This way each Resource and in turn each Guest only has access to the least amount of privileges required.I want us to also consider this as an overarching mental model of the whole crate, all interactions fall neatly into Host/Guest relations that can be modeled using capabilities. This opens the door for implementing much requested features like WASM runtime extensions and Deno support in a uniform and easy to reason about manner.
It also allows us model the more restrictive APIs on iOS and Android in an elegant way. In fact, it increases cross-platform security by implementing the strictest-common-denominator and giving us much more fine-grained control.
I believe the proposed solution is one that not only advances the current state-of-the-art in app security, but also one that fullfills Tauris goal of being the leader is security.
Alternatives considered
No response
Additional context
Much of this is based on the design of WASI: https://github.com/WebAssembly/WASI
and the implementation of a capabilities-based rust
std
crate used in the Wasmtime engine: https://github.com/bytecodealliance/cap-stdExample: File-Picker
An improved File-Picker API
The above example is a bit bare, so let me show you how we can improve the security of this API even further:
Permission is a simple bitflag like so:
we can also drop permissions (but never increase them important!) by calling
setPermissions
The text was updated successfully, but these errors were encountered: