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

Tauri ACL/Allowlist v2 Implementation and Plugin System Refactor #8428

Merged
merged 74 commits into from
Jan 23, 2024

Conversation

tweidinger
Copy link
Contributor

@tweidinger tweidinger commented Dec 18, 2023

This PR contains several (breaking) changes related to:

  • Tauri plugins
  • The new allowlist
  • Tauri build process

The current proposal and extended documentation for these changes can be found in a public HackMD document here. This document will be undergoing several changes during the implementation but shows the general approach and architecture. We strongly recommend reading this document before commenting.

We currently believe this is the one big major change needed to make v2.0 feature complete for a beta/rc/release,
therefore work on this PR should be prioritized.

Tauri Plugins

In v2 of Tauri most of the commands were moved into dedicated plugins and outside of the core of Tauri.
The move to plugins rendered the existing allowlist unusable, as the system was not designed to be compatible with plugins or code outside of Tauri. This PR addresses this by adding a new allowlist and access control for Tauri commands written by app or plugin developers.

The plugin-workspace repository contains all of the previous (and more) functionality now available as plugins (see the v2 branch). This reduces the amount of complexity in Tauri itself. Additionally, it allows more fast paced changes of system interaction functionality, as no complete understanding of Tauri itself is needed to contribute. It also allows breaking releases/changes to specific plugins independently from Tauri.

To further define what Tauri plugins are and what they need to implement the tauri-plugin crate was created.
It can be found in core/tauri-plugin in this PR branch.
Plugin developers need to depend on this crate and implement the defined traits, define default permissions and optionally define scope types.

A lot of work (not tracked here) is required to upgrade plugins from v1 to v2 and convenience tooling like tauri plugin init, tauri permission init/add/remove needs to be created, while existing tooling like tauri-cli and create-tauri-app need to be changed to be compatible with the new permissions/capabilities/plugins.

Allowlist

In v1 of Tauri most of the commands were Tauri internal APIs built into the core of Tauri. The allowlist was used to restrict the access from the Webview to the Tauri core and system resources.

With this PR the new allowlist is built in a way to be used by all plugins and application developers and is no longer exclusive for Tauri inbuilt functionality. It also allows more fine grained control, while being able to abstract away a lot of things.

We introduce several new naming conventions and move the allowlist to a capability driven configuration. Permissions define command enablement and scope, while capabilities link permissions with windows of the application.

A simplified example allowlist/capabilities configuration could look like:

"capabilities": [
    {
        "context": "local",
        "windows": [
            "*"
        ],
        "permissions": [
            "fs:full-homefolder-access",
            "fs:block-homefolder-sensitive-access"
        ]
    }
]

with an example permission, which could also be inbuilt/defined by the fs plugin:

{
    "version": 1,
    "identifier": "full-homefolder-access",
    "description": "This allows read write access to the complete $HOME folder.",
    "commands": {
        "allow": [
            "fs:readDirectory",
            "fs:readFile"
        ]
    },
    "scope": {
        "allow": [
            {
                "path": "$HOME/**"
            }
        ]
    }
}

or even simpler when the capabilities are further abstracted:

"capabilities": [
        "default",
        "admin-windows"
]

Tauri Build System

The build system will be enhanced (most likely) in a non-breaking way to understand metadata information provided by plugins and will allow us to pass information from plugins into the Tauri application.
It also will allow us to highlight issues to the application developer when commands are enabled in the capabilities but the plugin implementing these commands is not initialized/used. Also the other way around when no commands of a plugin are enabled but the plugin is initialized.

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Related issues:

@tweidinger tweidinger added scope: core Core packages of Tauri priority: 1 high type: breaking change This issue or pull request will introduce a breaking change and requires major version bump labels Dec 18, 2023
@tweidinger tweidinger requested a review from a team December 18, 2023 08:43
core/tauri-plugin/src/build/mod.rs Outdated Show resolved Hide resolved
core/tauri-plugin/Cargo.toml Outdated Show resolved Hide resolved
core/tauri-utils/src/acl/capability.rs Outdated Show resolved Hide resolved
core/tauri-utils/src/acl/resolved.rs Outdated Show resolved Hide resolved
@chippers chippers marked this pull request as ready for review January 20, 2024 11:06
@chippers chippers requested a review from a team as a code owner January 20, 2024 11:06
chippers
chippers previously approved these changes Jan 20, 2024
Copy link
Member

@chippers chippers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good as a basis for the ACL. There are some improvements I have in a project for this rep that we ideally land before stable, but I think we can mark this PR as complete and a good MVP

chippers
chippers previously approved these changes Jan 20, 2024
chippers
chippers previously approved these changes Jan 22, 2024
@lucasfernog lucasfernog merged commit 3c2f79f into dev Jan 23, 2024
30 checks passed
@lucasfernog lucasfernog deleted the feat/allowlist-v2 branch January 23, 2024 00:24
lucasfernog added a commit that referenced this pull request Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: 1 high scope: core Core packages of Tauri type: breaking change This issue or pull request will introduce a breaking change and requires major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants