configuring-tauri-permissions by dchuk/claude-code-tauri-skills
npx skills add https://github.com/dchuk/claude-code-tauri-skills --skill configuring-tauri-permissions本技能涵盖 Tauri v2 权限系统,用于控制前端对后端命令和系统资源的访问。
Tauri 中的权限是明确的特权,用于授予或拒绝对特定命令的访问。它们构成了前端代码与系统资源之间的安全边界。
| 组件 | 用途 |
|---|---|
| Permission | 定义对特定命令的访问权限 |
| Scope | 将命令限制在特定路径/资源 |
| Capability | 将权限链接到窗口/webview |
| Identifier | 引用权限的唯一名称 |
格式:<plugin-name>:<permission-type>
| 模式 | 示例 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 描述 |
|---|
<name>:default | fs:default | 默认权限集 |
<name>:allow-<command> | fs:allow-read-file | 允许特定命令 |
<name>:deny-<command> | fs:deny-write-file | 拒绝特定命令 |
<name>:allow-<scope> | fs:allow-app-read | 允许使用预定义范围 |
[a-z]tauri-plugin-)在编译时自动添加src-tauri/
├── capabilities/
│ ├── default.json # 主能力文件
│ └── admin.toml # 附加能力
├── permissions/
│ └── custom-permission.toml # 自定义应用权限
└── tauri.conf.json
tauri-plugin-example/
├── permissions/
│ ├── default.toml # 默认权限集
│ ├── autogenerated/ # 从命令自动生成
│ │ └── commands/
│ └── custom-scope.toml # 自定义范围
└── src/
├── commands.rs
└── build.rs
能力将权限链接到窗口,并定义前端上下文可以访问的内容。
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "主窗口权限",
"windows": ["main"],
"permissions": [
"core:default",
"fs:default",
"fs:allow-read-text-file",
{
"identifier": "fs:allow-write-text-file",
"allow": [{ "path": "$APPDATA/*" }]
}
]
}
"$schema" = "../gen/schemas/desktop-schema.json"
identifier = "main-capability"
description = "主窗口权限"
windows = ["main"]
permissions = [
"core:default",
"fs:default",
"fs:allow-read-text-file"
]
[[permissions]]
identifier = "fs:allow-write-text-file"
allow = [{ path = "$APPDATA/*" }]
{
"identifier": "admin-capability",
"windows": ["admin", "settings"],
"permissions": ["fs:allow-write-all"]
}
使用 "*" 定位所有窗口:
{
"windows": ["*"],
"permissions": ["core:default"]
}
{
"identifier": "desktop-capability",
"platforms": ["linux", "macOS", "windows"],
"windows": ["main"],
"permissions": ["fs:allow-app-read-recursive"]
}
{
"identifier": "mobile-capability",
"platforms": ["iOS", "android"],
"windows": ["main"],
"permissions": ["fs:allow-app-read"]
}
{
"identifier": "fs:allow-read-file",
"allow": [
{ "path": "$HOME/Documents/*" },
{ "path": "$APPDATA/**" }
],
"deny": [
{ "path": "$HOME/Documents/secrets/*" }
]
}
| 变量 | 描述 |
|---|---|
$APP | 应用程序安装目录 |
$APPCONFIG | 应用配置目录 |
$APPDATA | 应用数据目录 |
$APPLOCALDATA | 应用本地数据目录 |
$APPCACHE | 应用缓存目录 |
$APPLOG | 应用日志目录 |
$HOME | 用户主目录 |
$DESKTOP | 桌面目录 |
$DOCUMENT | 文档目录 |
$DOWNLOAD | 下载目录 |
$RESOURCE | 应用资源目录 |
$TEMP | 临时目录 |
| 模式 | 匹配内容 |
|---|---|
* | 目录中的任何文件 |
** | 递归(所有子目录) |
*.txt | 扩展名为 .txt 的文件 |
拒绝规则始终覆盖允许规则:
{
"permissions": [
{
"identifier": "fs:allow-read-file",
"allow": [{ "path": "$HOME/**" }],
"deny": [{ "path": "$HOME/.ssh/**" }]
}
]
}
{
"permissions": [
"fs:default",
"shell:default",
"http:default",
"dialog:default"
]
}
{
"permissions": [
"fs:default",
"fs:allow-read-text-file",
"fs:allow-write-text-file",
"fs:allow-app-read-recursive",
"fs:allow-app-write-recursive",
"fs:deny-default"
]
}
{
"permissions": [
"http:default",
{
"identifier": "http:default",
"allow": [{ "url": "https://api.example.com/*" }],
"deny": [{ "url": "https://api.example.com/admin/*" }]
}
]
}
{
"permissions": [
"shell:allow-open",
{
"identifier": "shell:allow-execute",
"allow": [
{ "name": "git", "cmd": "git", "args": true }
]
}
]
}
| 权限 | 访问权限 |
|---|---|
fs:allow-appdata-read | 读取 $APPDATA(非递归) |
fs:allow-appdata-read-recursive | 读取 $APPDATA(递归) |
fs:allow-appdata-write | 写入 $APPDATA(非递归) |
fs:allow-appdata-write-recursive | 写入 $APPDATA(递归) |
fs:allow-home-read-recursive | 读取 $HOME(递归) |
fs:allow-temp-write | 写入临时目录 |
创建 src-tauri/permissions/my-permission.toml:
[[permission]]
identifier = "my-app:config-access"
description = "访问应用配置文件"
commands.allow = ["read_config", "write_config"]
[[scope.allow]]
path = "$APPCONFIG/*"
[[scope.deny]]
path = "$APPCONFIG/secrets.json"
分组多个权限:
[[set]]
identifier = "my-app:full-access"
description = "完全应用访问权限"
permissions = [
"my-app:config-access",
"fs:allow-app-read-recursive",
"fs:allow-app-write-recursive"
]
在插件 src/build.rs 中:
const COMMANDS: &[&str] = &["get_user", "save_user", "delete_user"];
fn main() {
tauri_plugin::Builder::new(COMMANDS)
.build();
}
这会生成:
allow-get-user / deny-get-userallow-save-user / deny-save-userallow-delete-user / deny-delete-user创建 permissions/default.toml:
[default]
description = "my-plugin 的默认权限"
permissions = [
"allow-get-user",
"allow-save-user"
]
允许远程 URL 访问 Tauri API(谨慎使用):
{
"identifier": "remote-capability",
"windows": ["main"],
"remote": {
"urls": ["https://*.myapp.com"]
},
"permissions": [
"core:default"
]
}
安全警告:Linux 和 Android 无法区分 iframe 请求和窗口请求。
通过标识符引用能力:
{
"app": {
"security": {
"capabilities": ["main-capability", "admin-capability"]
}
}
}
或直接内联能力:
{
"app": {
"security": {
"capabilities": [
{
"identifier": "inline-capability",
"windows": ["*"],
"permissions": ["core:default"]
}
]
}
}
}
"此命令不允许"
未找到权限
cargo build 重新生成权限src-tauri/gen/schemas/$APPDATA/* 而非 $HOME/**.ssh、凭证等的访问每周安装量
91
仓库
GitHub 星标数
10
首次出现
2026年1月24日
安全审计
安装于
opencode77
gemini-cli76
codex72
claude-code65
github-copilot64
cursor63
This skill covers the Tauri v2 permission system for controlling frontend access to backend commands and system resources.
Permissions in Tauri are explicit privileges that grant or deny access to specific commands. They form the security boundary between frontend code and system resources.
| Component | Purpose |
|---|---|
| Permission | Defines access to specific commands |
| Scope | Restricts commands to specific paths/resources |
| Capability | Links permissions to windows/webviews |
| Identifier | Unique name referencing a permission |
Format: <plugin-name>:<permission-type>
| Pattern | Example | Description |
|---|---|---|
<name>:default | fs:default | Default permission set |
<name>:allow-<command> | fs:allow-read-file | Allow specific command |
<name>:deny-<command> | fs:deny-write-file | Deny specific command |
<name>:allow-<scope> |
[a-z]tauri-plugin-) added automatically at compile timesrc-tauri/
├── capabilities/
│ ├── default.json # Main capability file
│ └── admin.toml # Additional capabilities
├── permissions/
│ └── custom-permission.toml # Custom app permissions
└── tauri.conf.json
tauri-plugin-example/
├── permissions/
│ ├── default.toml # Default permission set
│ ├── autogenerated/ # Auto-generated from commands
│ │ └── commands/
│ └── custom-scope.toml # Custom scopes
└── src/
├── commands.rs
└── build.rs
Capabilities link permissions to windows and define what frontend contexts can access.
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Main window permissions",
"windows": ["main"],
"permissions": [
"core:default",
"fs:default",
"fs:allow-read-text-file",
{
"identifier": "fs:allow-write-text-file",
"allow": [{ "path": "$APPDATA/*" }]
}
]
}
"$schema" = "../gen/schemas/desktop-schema.json"
identifier = "main-capability"
description = "Main window permissions"
windows = ["main"]
permissions = [
"core:default",
"fs:default",
"fs:allow-read-text-file"
]
[[permissions]]
identifier = "fs:allow-write-text-file"
allow = [{ path = "$APPDATA/*" }]
{
"identifier": "admin-capability",
"windows": ["admin", "settings"],
"permissions": ["fs:allow-write-all"]
}
Use "*" to target all windows:
{
"windows": ["*"],
"permissions": ["core:default"]
}
{
"identifier": "desktop-capability",
"platforms": ["linux", "macOS", "windows"],
"windows": ["main"],
"permissions": ["fs:allow-app-read-recursive"]
}
{
"identifier": "mobile-capability",
"platforms": ["iOS", "android"],
"windows": ["main"],
"permissions": ["fs:allow-app-read"]
}
{
"identifier": "fs:allow-read-file",
"allow": [
{ "path": "$HOME/Documents/*" },
{ "path": "$APPDATA/**" }
],
"deny": [
{ "path": "$HOME/Documents/secrets/*" }
]
}
| Variable | Description |
|---|---|
$APP | Application install directory |
$APPCONFIG | App config directory |
$APPDATA | App data directory |
$APPLOCALDATA | App local data directory |
$APPCACHE | App cache directory |
$APPLOG | App log directory |
| Pattern | Matches |
|---|---|
* | Any file in directory |
** | Recursive (all subdirectories) |
*.txt | Files with .txt extension |
Deny rules always override allow rules:
{
"permissions": [
{
"identifier": "fs:allow-read-file",
"allow": [{ "path": "$HOME/**" }],
"deny": [{ "path": "$HOME/.ssh/**" }]
}
]
}
{
"permissions": [
"fs:default",
"shell:default",
"http:default",
"dialog:default"
]
}
{
"permissions": [
"fs:default",
"fs:allow-read-text-file",
"fs:allow-write-text-file",
"fs:allow-app-read-recursive",
"fs:allow-app-write-recursive",
"fs:deny-default"
]
}
{
"permissions": [
"http:default",
{
"identifier": "http:default",
"allow": [{ "url": "https://api.example.com/*" }],
"deny": [{ "url": "https://api.example.com/admin/*" }]
}
]
}
{
"permissions": [
"shell:allow-open",
{
"identifier": "shell:allow-execute",
"allow": [
{ "name": "git", "cmd": "git", "args": true }
]
}
]
}
| Permission | Access |
|---|---|
fs:allow-appdata-read | Read $APPDATA (non-recursive) |
fs:allow-appdata-read-recursive | Read $APPDATA (recursive) |
fs:allow-appdata-write | Write $APPDATA (non-recursive) |
fs:allow-appdata-write-recursive | Write $APPDATA (recursive) |
fs:allow-home-read-recursive | Read $HOME (recursive) |
fs:allow-temp-write |
Create src-tauri/permissions/my-permission.toml:
[[permission]]
identifier = "my-app:config-access"
description = "Access to app configuration files"
commands.allow = ["read_config", "write_config"]
[[scope.allow]]
path = "$APPCONFIG/*"
[[scope.deny]]
path = "$APPCONFIG/secrets.json"
Group multiple permissions:
[[set]]
identifier = "my-app:full-access"
description = "Full application access"
permissions = [
"my-app:config-access",
"fs:allow-app-read-recursive",
"fs:allow-app-write-recursive"
]
In plugin src/build.rs:
const COMMANDS: &[&str] = &["get_user", "save_user", "delete_user"];
fn main() {
tauri_plugin::Builder::new(COMMANDS)
.build();
}
This generates:
allow-get-user / deny-get-userallow-save-user / deny-save-userallow-delete-user / deny-delete-userCreate permissions/default.toml:
[default]
description = "Default permissions for my-plugin"
permissions = [
"allow-get-user",
"allow-save-user"
]
Allow remote URLs to access Tauri APIs (use with caution):
{
"identifier": "remote-capability",
"windows": ["main"],
"remote": {
"urls": ["https://*.myapp.com"]
},
"permissions": [
"core:default"
]
}
Security Warning : Linux and Android cannot distinguish iframe requests from window requests.
Reference capabilities by identifier:
{
"app": {
"security": {
"capabilities": ["main-capability", "admin-capability"]
}
}
}
Or inline capabilities directly:
{
"app": {
"security": {
"capabilities": [
{
"identifier": "inline-capability",
"windows": ["*"],
"permissions": ["core:default"]
}
]
}
}
}
"Not allowed on this command"
Permission not found
cargo build to regenerate permissionssrc-tauri/gen/schemas/$APPDATA/* over $HOME/**.ssh, credentials, etc.Weekly Installs
91
Repository
GitHub Stars
10
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode77
gemini-cli76
codex72
claude-code65
github-copilot64
cursor63
Azure PostgreSQL 无密码身份验证配置指南:Entra ID 迁移与访问管理
34,800 周安装
fs:allow-app-read |
| Allow with predefined scope |
$HOME |
| User home directory |
$DESKTOP | Desktop directory |
$DOCUMENT | Documents directory |
$DOWNLOAD | Downloads directory |
$RESOURCE | App resource directory |
$TEMP | Temporary directory |
| Write to temp directory |