From 91612eb3830102d5345a1561b4c4863471d24c87 Mon Sep 17 00:00:00 2001 From: J1-takai Date: Thu, 7 Aug 2025 16:24:51 +0900 Subject: [PATCH 1/7] i18n(ja): Japanese texts for 3 files in / Learn/Security --- ...capabilities-for-windows-and-platforms.mdx | 204 +++++++++++ .../security/using-plugin-permissions.mdx | 327 ++++++++++++++++++ .../security/writing-plugin-permissions.mdx | 260 ++++++++++++++ 3 files changed, 791 insertions(+) create mode 100644 src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx create mode 100644 src/content/docs/ja/learn/security/using-plugin-permissions.mdx create mode 100644 src/content/docs/ja/learn/security/writing-plugin-permissions.mdx diff --git a/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx b/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx new file mode 100644 index 0000000000..4d2f38d654 --- /dev/null +++ b/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx @@ -0,0 +1,204 @@ +--- +title: さまざまなウィンドウやプラットフォームでのセキュリティ・レベル +sidebar: + order: 11 +i18nReady: true +--- + +import { Steps } from '@astrojs/starlight/components'; +import ShowSolution from '@components/ShowSolution.astro'; +import Cta from '@fragments/cta.mdx'; +import TranslationNote from '@components/i18n/TranslationNote.astro'; + +この章は、Tauri アプリのセキュリティ・レベルをカスタマイズする方法について説明いたします。 + +## この章の内容 + +- Tauri アプリで複数のウィンドウを作成する +- ウィンドウごとに異なるセキュリティ・レベルを使用する +- プラットフォームをに依存するセキュリティ・レベルを使用する + +## 事前準備 + +この章の演習内容は、「[プラグイン・アクセス権の使用](/ja/learn/security/using-plugin-permissions/)」を読了後に行なうことを前提としています。 + +## 手順 + + +1. ### Tauri アプリで複数のウィンドウを作成する + +この演習では、`first`(第一)と `second`(第二)というラベルの付いた二つのウィンドウを持つアプリを作成します。 +Tauri アプリケーションでウィンドウを作成する方法はいくつかあります。 + +#### Tauri 設定ファイルを使用してウィンドウを作成 + +Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では次のようになります: + + + ```javascript + "productName": "multiwindow", + ... + "app": { + "windows": [ + { + "label": "first", + "title": "First", + "width": 800, + "height": 600 + }, + { + "label": "second", + "title": "Second", + "width": 800, + "height": 600 + } + ], + }, + ... + } + ``` + + +#### プログラムでウィンドウを作成 + + Rust コード内で Tauri アプリを作成します: + + + ```rust + tauri::Builder::default() + .invoke_handler(tauri::generate_handler![greet]) + .setup(|app| { + let webview_url = tauri::WebviewUrl::App("index.html".into()); + // First window(第一ウィンドウ) + tauri::WebviewWindowBuilder::new(app, "first", webview_url.clone()) + .title("First") + .build()?; + // Second window(第二ウィンドウ) + tauri::WebviewWindowBuilder::new(app, "second", webview_url) + .title("Second") + .build()?; + Ok(()) + }) + .run(context) + .expect("error while running tauri application"); + ``` + + +2. ### 異なるウィンドウに異なるセキュリティ・レベルを適用 + + Tauri アプリのウィンドウでは、Tauri バックエンドのさまざまな機能やプラグインを使用できます。 + セキュリティをより強固にするために、各ウィンドウに必要なセキュリティ機能のみを付与することをお勧めします。 + この演習では、「第一の `first`」ウィンドウでファイルシステムとダイアログ機能を使用し、「第二の `second`」ウィンドウではダイアログ機能のみを必要としている状況を想定して進めます。 + + #### カテゴリごとの個別「セキュリティ・レベル」ファイル + + 有効化するアクションのカテゴリごとに「セキュリティ・レベル」ファイルを分割することをお勧めします。 + + + + `src-tauri/capabilities` 内の JSON ファイルは、「セキュリティ・レベル」システムに対応済みです。 + そこで、ファイルシステムとダイアログ・ウィンドウに関連するセキュリティ・レベルを `filesystem.json` と `dialog.json` に分割します。 + + _Tauri プロジェクトのファイルツリー:_ + + ``` + /src + /src-tauri + /capabilities + filesystem.json + dialog.json + tauri.conf.json + package.json + README.md + ``` + + + + #### 「第一 `first`」ウィンドウにファイルシステムのセキュリティ・レベルを付与 + + 「`first`」ウィンドウに、`$HOME` ディレクトリの内容への読み取りアクセス権を付与するようにセキュリティ・レベルを設定します。 + + + + 一つまたは複数のウィンドウ・ラベルを持つ「セキュリティ機能 capability」ファイル内の「`windows` フィールド」を使用します。 + + ```json title="filesystem.json" + { + "identifier": "fs-read-home", + "description": "Allow access file access to home directory", + "local": true, + "windows": ["first"], + "permissions": ["fs:allow-home-read"] + } + ``` + + + + 「filesystem.json」ファイルの内容抄訳: + + - identifier: 識別子名 + - description: セキュリティ内容説明(home ディレクトリへのファイル・アクセスを許可) + - local: true + - windows: ウィンドウ名 + - permissions: アクセス権設定 + + + + + + #### 「第一 `first`」と「第二 `second`」ウィンドウにダイアログ機能を付与 + + 「`first`」と「`second`」ウィンドウに「Yes/No」ダイアログを作成する機能を追加します。 + + + + 一つまたは複数のウィンドウ・ラベルを持つ「セキュリティ機能」ファイル内の `windows` フィールドを使用します。 + + ```json title="dialog.json" + { + "identifier": "dialog", + "description": "Allow to open a dialog", + "local": true, + "windows": ["first", "second"], + "permissions": ["dialog:allow-ask"] + } + ``` + + + +3. ### セキュリティ機能をプラットフォーム依存にする + + 次に、特定のプラットフォームでのみアクティブになるようにセキュリティ機能をカスタマイズします。 + 以下の事例では、ファイルシステムのセキュリティ機能を `linux` と `windows` でのみ有効にします。 + + + + プラットフォーム別に設定するには、セキュリティ機能ファイルの「`platforms` フィールド」で対象プラットフォームを指定します。 + + ```json title="filesystem.json" + { + "identifier": "fs-read-home", + "description": "Allow access file access to home directory", + "local": true, + "windows": ["first"], + "permissions": ["fs:allow-home-read"], + "platforms": ["linux", "windows"] + } + ``` + + 現在指定可能なプラットフォームは、`linux`、`windows`、`macos`、`android`、および `ios` です。 + + + + + +## 本章のまとめ と 参考資料 + +Tauri アプリで複数のウィンドウを作成し、それぞれに別々のセキュリティ機能を与える方法を学びました。さらに、こうしたセキュリティ機能は特定のプラットフォーム向けにカスタマイズすることも可能です。 + +ウィンドウ機能を使用したサンプル・アプリケーションは、[Tauri Github リポジトリ](https://github.com/tauri-apps/tauri) の [`api` サンプル](https://github.com/tauri-apps/tauri/tree/dev/examples/api) 内にあります。 +「セキュリティ機能ファイル capability file」で使用できるフィールドは、TAURI Doc の「メニュー Menu」内にある「Reference」の [Capability](/reference/acl/capability/) 部分にリストされています。 + +
+ 【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】 +
diff --git a/src/content/docs/ja/learn/security/using-plugin-permissions.mdx b/src/content/docs/ja/learn/security/using-plugin-permissions.mdx new file mode 100644 index 0000000000..3554d77342 --- /dev/null +++ b/src/content/docs/ja/learn/security/using-plugin-permissions.mdx @@ -0,0 +1,327 @@ +--- +title: プライグン・アクセス権の使用 +sidebar: + order: 10 +i18nReady: true +--- + +import { Steps } from '@astrojs/starlight/components'; +import ShowSolution from '@components/ShowSolution.astro'; +import Cta from '@fragments/cta.mdx'; +import TranslationNote from '@components/i18n/TranslationNote.astro'; + + + +本訳稿では、Permissions / Capabilities に主に以下の訳語を当てています。 + +- Permissions 「アクセス権」(アクセスの許可権) +- Capabilities 「セキュリティ・レベル」(セキュリティの度合いを示す権限レベル) + + + +この章の目的は、プラグイン・アクセス権がどのように有効化または無効化されるのか、どこに記述されているのか、さらにはプラグインのデフォルト・アクセス権の使用方法について、より深く理解することです。 + +この章を読み終わる頃には、どのようなプラグインでも、そのアクセス権を見つけて使用し、既存のアクセス権をカスタマイズする方法を理解できるようになります。 +以下で、プラグインとプラグイン固有のアクセス権を使用する Tauri アプリケーションの事例を見ることもできます。 + + + +1. ### Tauri アプリケーションの作成 + + Tauri アプリケーションを作成します。 + この事例では、[`create-tauri-app`](https://github.com/tauri-apps/create-tauri-app) を実行します。 + + + + この段階を踏んだ説明手順では `pnpm` を使用して進めていきますが、別のパッケージ・マネージャーも選択可能です。選択したパッケージ・マネージャーに応じてコマンドを置き換えてください。 + + + +``` +pnpm create tauri-app +``` + +``` +✔ Project name · plugin-permission-demo +✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun) +✔ Choose your package manager · pnpm +✔ Choose your UI template · Vanilla +✔ Choose your UI flavor · TypeScript + +Template created! To get started run: +cd plugin-permission-demo +pnpm install +pnpm tauri dev +``` + + + + ※ 処理内容の参考訳: + ✔ プロジェクト名 ・・・ + ✔ フロントエンドに用いる言語を選択 ・・・ + ✔ パッケージ・マネージャーを選択 ・・・ + ✔ UI テンプレートを選択 ・・・ + ✔ UI フレーバーを選択 ・・・ + + テンプレートが作成されました! 始めるには以下を実行: + cd (作成するプロジェクトのディレクトリ名) + pnpm install + pnpm tauri dev + + + + + +2. ### 「ファイルシステム」プラグインをアプリケーションに追加 + + 既存のプラグインを検索するには、複数のリソースを使用できます。 + + いちばん簡単な方法は、プラグインがすでに『Tauri Guides』ドキュメントの「[Plugins](/ja/plugin/)」の中にあるか、つまり、Tauri が管理するプラグイン・セットの中に存在しているかどうかを確認することです。 + たとえば、「ファイルシステム(fs)」プラグインは **Tauri Plugins** メニューのワークスペース(共有エリア)に掲載されており、そのリンク先の[設定手順](/ja/plugin/file-system/#setup) に従って自分のプロジェクトに追加可能です。 + + また、プラグインが Tauri コミュニティの取り組みとして行なわれているものであれば、[crates.io](https://crates.io/search?q=tauri-plugin-) 上で十中八九見つかるはずです。「`tauri-plugin-<プラグイン名>`」のように検索してみてください: + + + + + + 以下、「ファイルシステム fs」プラグインを例に、① メニュー「Plaugins」部にリストされていた場合と、② 「crates.io」サイトから入手する場合、の処理手順が示されます。 + + + + お探しのプラグインが「ワークスペース(共有エリア)」にある既存のフラグインであれば、自動化された方法を使用可能です: + + ``` + pnpm tauri add fs + ``` + + そのプラグインを「[crates.io](https://crates.io/crates/tauri-plugin-fs)」サイトで見つけた場合は、依存関係を手作業で追加し、プラグインを初期化するために Tauri ビルダーを修正する必要があります: + + ```sh + cargo add tauri-plugin-fs + ``` + + プラグイン初期化のために `lib.rs` を修正: + + ```rust title="src-tauri/src/lib.rs" ins={4} + #[cfg_attr(mobile, tauri::mobile_entry_point)] + fn run() { + tauri::Builder::default() + .plugin(tauri_plugin_fs::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + + +3. ### 「ファイルシステム」プラグインのデフォルト・アクセス権の確認 + + 各プラグインには「デフォルト」のアクセス権のセットがあり、これには、適切で最小限の機能と、プラグインをすぐにそのまま使用するためのアクセス権とスコープ(適用範囲)がすべて含まれています。 + + 公式にメンテナンスされているプラグインの場合は、ドキュメントに提供された説明が記載されています(例: [fs default](/ja/plugin/file-system/#default-permission))。 + + コミュニティ製プラグインに関するデフォルトのアクセス権設定を調べるには、そのプラグインのソース・コードを精査する必要があります。 + その内容は `your-plugin/permissions/default.toml` に定義されているはずです。 + + + +``` +"$schema" = "schemas/schema.json" + + [default] + description = """ + + # Tauri `fs` default permissions + + This configuration file defines the default permissions granted to the filesystem. + + ### Granted Permissions + + This default permission set enables all read-related commands and allows access to the `$APP` folder and sub directories created in it. + The location of the `$APP` folder depends on the operating system, where the application is run. + + In general the `$APP` folder needs to be manually created + by the application at runtime, before accessing files or folders + in it is possible. + + ### Denied Permissions + + This default permission set prevents access to critical components + of the Tauri application by default. + On Windows the webview data folder access is denied. + + """ + permissions = ["read-all", "scope-app-recursive", "deny-default"] + +``` + + + + 〔参考訳〕 + + # Tauri 'fs' デフォルト・アクセス権 + + この設定ファイルは、「ファイルシステム fs」プラグインに付与されるデフォルトのアクセス権を定義します。 + + ### 許可されたアクセス権 + + このデフォルトのアクセス「許可」権セットは、すべての読み取り関連コマンドを有効にし、「`$APP`」フォルダとその中に作成されているサブディレクトリへのアクセスを許可します。 + 「`$APP`」フォルダの場所は、アプリケーションが実行されるオペレーティング・システムによって異なります。 + + 通常、「`$APP`」フォルダ内のファイルやフォルダがアクセス可能になるには、アプリケーションによって実行時に手作業で「`$APP`」フォルダを生成する必要があります。 + + ### 拒否されたアクセス権 + + このデフォルトのアクセス「拒否」権セットは、デフォルトで Tauri アプリケーションの重要なコンポーネントへのアクセスを防止します。 + Windows では、Webview データ・フォルダーへのアクセスが拒否されます。 + + + + + +```` + +4. ### 適切なアクセス権の見つけ方 + +手順 4 では、システムへの最小限のアクセスで、コマンドをフロントエンドに公開するために必要なアクセス権を見つける方法について説明します。 + +「`fs`」プラグインには自動生成されたアクセス権があり、個々のコマンドの無効化/有効化や、グローバル・スコープの許可/禁止を行ないます。 +アクセス権の詳細は、[公式ドキュメント](/ja/plugin/file-system/#permission-table) またはプラグインのソースコード(`fs/permissions/autogenerated`)を参照してください。 + +たとえば、ユーザーの `$HOME` フォルダにあるテキスト・ファイル「`test.txt`」への書き込みを有効にしたいとします。 + +そのためは、「自動生成されたアクセス権」の中で、`allow-write-text-file` のようなテキスト・ファイルへの書き込みを許可する権限を検索し、次に `$HOME/test.txt` ファイルへのアクセスを許可するスコープを検索します。 + +これらのアクセス権を `src-tauri/tauri.conf.json` の「セキュリティ・レベル `capabilities`」セクション、または「`src-tauri/capabilities/` フォルダー内のファイル」に追加する必要があります。 +デフォルトでは、`src-tauri/capabilities/default.json` の中には既に修正可能な「セキュリティ機能」があります。 + + + +```json title="src-tauri/capabilities/default.json" del={18} ins={19} +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Capability for the main window", + "windows": ["main"], + "permissions": [ + "path:default", + "event:default", + "window:default", + "app:default", + "image:default", + "resources:default", + "menu:default", + "tray:default", + "shell:allow-open", + "fs:default", + "fs:allow-write-text-file" + ] +} +```` + + + +「`fs`」プラグインには `$HOME` フォルダー全体にアクセスするための自動生成されたスコープしか設定されていないため、自分に必要な独自のスコープを設定する必要があります。 +この独自のスコープは `write-text-file` コマンドのみを有効にして、`test.txt` ファイルだけが公開可能になるようにすべきです。 + + +```json title="src-tauri/capabilities/default.json" del={18} ins={19-22} + { + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Capability for the main window", + "windows": [ + "main" + ], + "permissions": [ + "path:default", + "event:default", + "window:default", + "app:default", + "image:default", + "resources:default", + "menu:default", + "tray:default", + "shell:allow-open", + "fs:allow-write-text-file", + { + "identifier": "fs:allow-write-text-file", + "allow": [{ "path": "$HOME/test.txt" }] + }, + ] +} +``` + + +5. ### アクセス権の実地テスト + + 必要なアクセス権限を追加したら、アプリケーションがファイルにアクセスしてその内容を書き込むことができることを確認します。 + + + + アプリケーションで以下のスニペットを使用すれば、ファイルに書き込むことができます: + + ```ts title="src/main.ts" + import { writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs'; + + let greetInputEl: HTMLInputElement | null; + + async function write(message: string) { + await writeTextFile('test.txt', message, { baseDir: BaseDirectory.Home }); + } + + window.addEventListener('DOMContentLoaded', () => { + greetInputEl = document.querySelector('#greet-input'); + document.querySelector('#greet-form')?.addEventListener('submit', (e) => { + e.preventDefault(); + if (!greetInputEl) return; + + write( + greetInputEl.value == '' ? 'No input provided' : greetInputEl.value + ); + }); + }); + ``` + + `src/main.ts` をこのスニペットで置き換えると、基本的(プレーン)な Vanilla+Typescript アプリを使用する場合に、デフォルトの `index.html` を変更する必要がなくなります。 + 実行中のアプリの入力フィールドに入力すると、送信時にファイルに書き込まれます。 + + では、実際にテストしてみましょう: + + ``` + pnpm run tauri dev + ``` + + 入力して「送信 Submit」をクリックしたあとで、ターミナル・エミュレーターを使用するか、ホーム・フォルダー内のファイルを自分で開くと結果が確認できます。 + + ``` + cat $HOME/test.txt + ``` + + 入力した内容が表示されているばずで、これで Tauri アプリケーションでプラグインからのアクセス権を使用する方法についての学習は完了です。 + 🥳 + + 以下のエラーが発生した場合には: + + ```sh + [Error] Unhandled Promise Rejection: fs.write_text_file not allowed. Permissions associated with this command: fs:allow-app-write, fs:allow-app-write-recursive, fs:allow-appcache-write, fs:allow-appcache-write-recursive, fs:allow-appconf... + (anonymous function) (main.ts:5) + ``` + + + + [エラー内容抄訳] 未処理の Promise 戻り値「拒否」: fs.write_text_file は許可されていません。このコマンドに関連付けられたアクセス権は: fs:allow-app-write、fs:allow-app-write-recursive、・・・です。 + (匿名関数)(main,ts:5) + + + + この場合、[上記の手順 4](#適切なアクセス権の見つけ方) を正しく実行していない可能性が非常に高くなります。 + + + + + +
+ 【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】 +
diff --git a/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx b/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx new file mode 100644 index 0000000000..fce8bfa98e --- /dev/null +++ b/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx @@ -0,0 +1,260 @@ +--- +title: プラグイン・アクセス権の記述 +sidebar: + order: 11 +i18nReady: true +--- + +import { Steps } from '@astrojs/starlight/components'; +import ShowSolution from '@components/ShowSolution.astro'; +import Cta from '@fragments/cta.mdx'; +import TranslationNote from '@components/i18n/TranslationNote.astro'; + +この章での演習目的は、自分自身でプラグインを記述する際の、プラグイン・アクセス権をどのように作成するかをより深く理解することです。 + +演習の終わりには、自分のプラグインに簡単なアクセス権を設定できる能力が身についていることでしょう。 +アクセス権が部分的に自動生成と手作業とで作成される Tauri プラグインの例を示します。 + + + +1. ### Tauri プラグインの作成 + + この例では、Tauri [`cli`](/reference/cli/)〔英語サイト〕を利用して Tauri プラグインのソース・コード構造体をブートストラップ(起動)します。 + すべての[必要事項](/ja/start/prerequisites/)がインストールされているかを点検し、`cargo tauri info` を実行して Tauri CLI が正しいバージョンであることを確認してください。 + + 出力結果には、`tauri-cli` のバージョンが「`2.x`」であることが示されるはずです。 + このステップ別の説明手順では `pnpm` を使用して進めていきますが、別のパッケージ・マネージャーも選択可能です。選択したパッケージ・マネージャーに応じてコマンドを置き換えてください。 + + 最新バージョンのインストールが行なわれていれば、Tauri CLI を使用してプラグインの作成を開始できます。 + + + ```sh mkdir -p tauri-learning cd tauri-learning cargo tauri plugin new + test cd tauri-plugin-test pnpm install pnpm build cargo build ``` + + +2. ### 新しいコマンドの作成 + + 実用的でシンプルな例をお見せするために、コマンドがユーザー入力を一時フォルダー内のファイルに書き込み、そのファイルにカスタム・ヘッダーを追加する処理を想定しましょう。 + + このコマンドに「`write_custom_file`」という名前を付け、「`src/commands.rs`」に実装し、プラグイン・ビルダーに追加してフロントエンドに公開します。 + + Tauri のコア・ユーティリティはこのコマンドの `allow`(許可)および `deny`(拒否)権限を自動生成するため、このアクセス権について考慮する必要はありません。 + + + + コマンドの実装:(以下の最後の部分が「`write_custome_file`」コマンドを追加している箇所) + + ```rust title="src/commands.rs" ins={15-22} ins=", Manager" + use tauri::{AppHandle, command, Runtime}; + + use crate::models::*; + use crate::Result; + use crate::TestExt; + + #[command] + pub(crate) async fn ping( + app: AppHandle, + payload: PingRequest, + ) -> Result { + app.test1().ping(payload) + } + + #[command] + pub(crate) async fn write_custom_file( + user_input: String, + app: AppHandle, + ) -> Result { + std::fs::write(app.path().temp_dir().unwrap(), user_input)?; + Ok("success".to_string()) + } + + ``` + + 新しいコマンドに組み込みアクセス権限を自動生成します: + + ```rust title="src/build.rs" ins=""write_custom_file"" + const COMMANDS: &[&str] = &["ping", "write_custom_file"]; + ``` + + このような組み込みアクセス権限は Tauri ビルド・システムによって自動的に生成され、`permissions/autogenerated/commands` フォルダーに表示されます。 + デフォルトでは、`enable-`(〇〇を許可)および `deny-`(〇〇を拒否)のアクセス権限が作成されます。 + + + +3. ### 新しいコマンドの公開 + + 「ステップ 2」は、実際のコマンド実装を記述するためのものでした。 + つづいて、そのコマンドをフロントエンドに公開して使用できるようにします。 + + + + 新たに実装したコマンドにフロントエンド IPC 要求を渡すための「呼び出しハンドラー」を生成するように Tauri ビルダーを設定します: + + ```rust title="src/lib.rs" ins="commands::write_custom_file," + pub fn init() -> TauriPlugin { + Builder::new("test") + .invoke_handler(tauri::generate_handler![ + commands::ping, + commands::write_custom_file, + ]) + .setup(|app, api| { + #[cfg(mobile)] + let test = mobile::init(app, api)?; + #[cfg(desktop)] + let test = desktop::init(app, api)?; + app.manage(test); + + // コマンドからアクセスできるように「状態」を管理(manage) + app.manage(MyState::default()); + Ok(()) + }) + .build() + } + ``` + + フロントエンド・モジュールに新しいコマンドを公開します。 + + このステップは、このサンプル・アプリケーションがフロントエンド・モジュールを正常にインポートするために不可欠です。 + この処理は便宜上のものであり、セキュリティへの影響はありません。というのも、コマンド・ハンドラーがすでに生成されており、コマンドをフロントエンドから手動で呼び出すことができるためです。 + + ```ts title="guest-js/index.ts" ins={11-13} + import { invoke } from '@tauri-apps/api/core'; + + export async function ping(value: string): Promise { + return await invoke<{ value?: string }>('plugin:test|ping', { + payload: { + value, + }, + }).then((r) => (r.value ? r.value : null)); + } + + export async function writeCustomFile(user_input: string): Promise { + return await invoke('plugin:test|write_custom_file', { + userInput: user_input, + }); + } + ``` + + :::tip + 呼び出しパラメータは「キャメルケース CamelCase」(結合する単語の語頭を大文字)で記述する必要があります。この例では、「`user_input`」ではなく「`userInput`」という書き方になります。 + ::: + + 自分のパッケージがビルドされることを確認します: + + ``` + pnpm build + ``` + + + +4. ### デフォルトのプラグイン・アクセス権を定義 + + このプラグイン例ではデフォルトで `write_custom_file` コマンドを公開する必要があるため、このコマンドを `default.toml` のアクセス権限(permissions)に追加する必要があります。 + + + + 先ほど公開した新しいコマンドを許可するために、このコマンドをデフォルトのアクセス権限のセットに追加します。 + + ```toml title="permissions/default.toml" ins=", "allow-write-custom-file"" + "$schema" = "schemas/schema.json" + [default] + description = "Default permissions for the plugin" + permissions = ["allow-ping", "allow-write-custom-file"] + ``` + + + +5. ### サンプル・アプリケーションからテスト・コマンドを呼び出す + + 作成されたプラグイン・ディレクトリ構造には `examples/tauri-app` フォルダーがあり、そこにはプラグインをテストするためにすぐに使用できる Tauri アプリケーションが含まれています。 + + 新しいコマンドを追加したので、その新しいコマンドを呼び出すようにフロントエンドを少し変更する必要があります。 + + + +```svelte title="src/App.svelte" del={11-13,42-45} ins={14-16,45-49} + + +
+

Welcome to Tauri!

+ + {' '} + + + {' '} +

Click on the Tauri, Vite, and Svelte logos to learn more.

+ + {' '} +
+ +
+ +
+ +
{@html response}
+
+
+ +
{@html response}
+
+ +
+ + + +``` + +これを実行して「書き込み」ボタンを押すと、次のような画面が表示されるはずです: + +``` + +success (成功) + +``` + +仮フォルダーには、新しく実装されたプラグイン・コマンドからのメッセージが含まれている `test.txt` ファイルができているはずです。 +🥳 + +
+ ``` + +
+ +
+ 【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】 +
From 547dc96e726b421a2cf0fb136c678427e3520fcc Mon Sep 17 00:00:00 2001 From: Ayres Vitor Date: Sat, 16 Aug 2025 09:19:09 -0300 Subject: [PATCH 2/7] fix typo - Puraguin -> Puraigun --- src/content/docs/ja/learn/security/using-plugin-permissions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/ja/learn/security/using-plugin-permissions.mdx b/src/content/docs/ja/learn/security/using-plugin-permissions.mdx index 3554d77342..caed87e870 100644 --- a/src/content/docs/ja/learn/security/using-plugin-permissions.mdx +++ b/src/content/docs/ja/learn/security/using-plugin-permissions.mdx @@ -1,5 +1,5 @@ --- -title: プライグン・アクセス権の使用 +title: プラグイン・アクセス権の使用 sidebar: order: 10 i18nReady: true From a6ce99ee9083f05e016c24f5a67777fa4dcad008 Mon Sep 17 00:00:00 2001 From: Ayres Vitor Date: Sat, 16 Aug 2025 09:30:38 -0300 Subject: [PATCH 3/7] fix format --- .prettierignore | 4 + ...capabilities-for-windows-and-platforms.mdx | 41 +-- .../security/using-plugin-permissions.mdx | 20 +- .../security/writing-plugin-permissions.mdx | 291 +++++++++--------- 4 files changed, 182 insertions(+), 174 deletions(-) diff --git a/.prettierignore b/.prettierignore index 3c3c84978a..5b32c0478f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -38,5 +38,9 @@ src/content/docs/zh-cn/start/frontend/qwik.mdx src/content/docs/learn/splashscreen.mdx src/content/docs/zh-cn/learn/splashscreen.mdx +src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx +src/content/docs/ja/learn/Security/using-plugin-permissions.mdx +src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx + src/content/docs/security/http-headers.mdx diff --git a/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx b/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx index 4d2f38d654..a64a5c29fd 100644 --- a/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx +++ b/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx @@ -84,7 +84,8 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では ``` -2. ### 異なるウィンドウに異なるセキュリティ・レベルを適用 +{/* prettier-ignore */} +2. ### 異なるウィンドウに異なるセキュリティ・レベルを適用 Tauri アプリのウィンドウでは、Tauri バックエンドのさまざまな機能やプラグインを使用できます。 セキュリティをより強固にするために、各ウィンドウに必要なセキュリティ機能のみを付与することをお勧めします。 @@ -94,7 +95,7 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では 有効化するアクションのカテゴリごとに「セキュリティ・レベル」ファイルを分割することをお勧めします。 - + `src-tauri/capabilities` 内の JSON ファイルは、「セキュリティ・レベル」システムに対応済みです。 そこで、ファイルシステムとダイアログ・ウィンドウに関連するセキュリティ・レベルを `filesystem.json` と `dialog.json` に分割します。 @@ -112,7 +113,7 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では README.md ``` - + #### 「第一 `first`」ウィンドウにファイルシステムのセキュリティ・レベルを付与 @@ -166,29 +167,29 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では -3. ### セキュリティ機能をプラットフォーム依存にする +3. ### セキュリティ機能をプラットフォーム依存にする - 次に、特定のプラットフォームでのみアクティブになるようにセキュリティ機能をカスタマイズします。 - 以下の事例では、ファイルシステムのセキュリティ機能を `linux` と `windows` でのみ有効にします。 + 次に、特定のプラットフォームでのみアクティブになるようにセキュリティ機能をカスタマイズします。 + 以下の事例では、ファイルシステムのセキュリティ機能を `linux` と `windows` でのみ有効にします。 - + - プラットフォーム別に設定するには、セキュリティ機能ファイルの「`platforms` フィールド」で対象プラットフォームを指定します。 +プラットフォーム別に設定するには、セキュリティ機能ファイルの「`platforms` フィールド」で対象プラットフォームを指定します。 - ```json title="filesystem.json" - { - "identifier": "fs-read-home", - "description": "Allow access file access to home directory", - "local": true, - "windows": ["first"], - "permissions": ["fs:allow-home-read"], - "platforms": ["linux", "windows"] - } - ``` +```json title="filesystem.json" +{ + "identifier": "fs-read-home", + "description": "Allow access file access to home directory", + "local": true, + "windows": ["first"], + "permissions": ["fs:allow-home-read"], + "platforms": ["linux", "windows"] +} +``` - 現在指定可能なプラットフォームは、`linux`、`windows`、`macos`、`android`、および `ios` です。 +現在指定可能なプラットフォームは、`linux`、`windows`、`macos`、`android`、および `ios` です。 - + diff --git a/src/content/docs/ja/learn/security/using-plugin-permissions.mdx b/src/content/docs/ja/learn/security/using-plugin-permissions.mdx index caed87e870..4cfbd63f84 100644 --- a/src/content/docs/ja/learn/security/using-plugin-permissions.mdx +++ b/src/content/docs/ja/learn/security/using-plugin-permissions.mdx @@ -35,7 +35,7 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; この段階を踏んだ説明手順では `pnpm` を使用して進めていきますが、別のパッケージ・マネージャーも選択可能です。選択したパッケージ・マネージャーに応じてコマンドを置き換えてください。 - + ``` pnpm create tauri-app @@ -70,7 +70,7 @@ pnpm tauri dev - + 2. ### 「ファイルシステム」プラグインをアプリケーションに追加 @@ -81,7 +81,7 @@ pnpm tauri dev また、プラグインが Tauri コミュニティの取り組みとして行なわれているものであれば、[crates.io](https://crates.io/search?q=tauri-plugin-) 上で十中八九見つかるはずです。「`tauri-plugin-<プラグイン名>`」のように検索してみてください: - + @@ -113,7 +113,7 @@ pnpm tauri dev } ``` - + 3. ### 「ファイルシステム」プラグインのデフォルト・アクセス権の確認 @@ -124,7 +124,7 @@ pnpm tauri dev コミュニティ製プラグインに関するデフォルトのアクセス権設定を調べるには、そのプラグインのソース・コードを精査する必要があります。 その内容は `your-plugin/permissions/default.toml` に定義されているはずです。 - + ``` "$schema" = "schemas/schema.json" @@ -178,9 +178,7 @@ pnpm tauri dev - - -```` + 4. ### 適切なアクセス権の見つけ方 @@ -218,14 +216,14 @@ pnpm tauri dev "fs:allow-write-text-file" ] } -```` +``` - + 「`fs`」プラグインには `$HOME` フォルダー全体にアクセスするための自動生成されたスコープしか設定されていないため、自分に必要な独自のスコープを設定する必要があります。 この独自のスコープは `write-text-file` コマンドのみを有効にして、`test.txt` ファイルだけが公開可能になるようにすべきです。 - + ```json title="src-tauri/capabilities/default.json" del={18} ins={19-22} { "$schema": "../gen/schemas/desktop-schema.json", diff --git a/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx b/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx index fce8bfa98e..da14633e68 100644 --- a/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx +++ b/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx @@ -17,22 +17,30 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; -1. ### Tauri プラグインの作成 - - この例では、Tauri [`cli`](/reference/cli/)〔英語サイト〕を利用して Tauri プラグインのソース・コード構造体をブートストラップ(起動)します。 - すべての[必要事項](/ja/start/prerequisites/)がインストールされているかを点検し、`cargo tauri info` を実行して Tauri CLI が正しいバージョンであることを確認してください。 - - 出力結果には、`tauri-cli` のバージョンが「`2.x`」であることが示されるはずです。 - このステップ別の説明手順では `pnpm` を使用して進めていきますが、別のパッケージ・マネージャーも選択可能です。選択したパッケージ・マネージャーに応じてコマンドを置き換えてください。 - - 最新バージョンのインストールが行なわれていれば、Tauri CLI を使用してプラグインの作成を開始できます。 - - - ```sh mkdir -p tauri-learning cd tauri-learning cargo tauri plugin new - test cd tauri-plugin-test pnpm install pnpm build cargo build ``` - - -2. ### 新しいコマンドの作成 +1. ### Tauri プラグインの作成 + + この例では、Tauri [`cli`](/reference/cli/)〔英語サイト〕を利用して Tauri プラグインのソース・コード構造体をブートストラップ(起動)します。 + すべての[必要事項](/ja/start/prerequisites/)がインストールされているかを点検し、`cargo tauri info` を実行して Tauri CLI が正しいバージョンであることを確認してください。 + + 出力結果には、`tauri-cli` のバージョンが「`2.x`」であることが示されるはずです。 + このステップ別の説明手順では `pnpm` を使用して進めていきますが、別のパッケージ・マネージャーも選択可能です。選択したパッケージ・マネージャーに応じてコマンドを置き換えてください。 + + 最新バージョンのインストールが行なわれていれば、Tauri CLI を使用してプラグインの作成を開始できます。 + +{/* prettier-ignore */} + +```sh +mkdir -p tauri-learning +cd tauri-learning +cargo tauri plugin new test +cd tauri-plugin-test +pnpm install +pnpm build +cargo build +``` + + +2. ### 新しいコマンドの作成 実用的でシンプルな例をお見せするために、コマンドがユーザー入力を一時フォルダー内のファイルに書き込み、そのファイルにカスタム・ヘッダーを追加する処理を想定しましょう。 @@ -81,77 +89,77 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; -3. ### 新しいコマンドの公開 - - 「ステップ 2」は、実際のコマンド実装を記述するためのものでした。 - つづいて、そのコマンドをフロントエンドに公開して使用できるようにします。 - - - - 新たに実装したコマンドにフロントエンド IPC 要求を渡すための「呼び出しハンドラー」を生成するように Tauri ビルダーを設定します: - - ```rust title="src/lib.rs" ins="commands::write_custom_file," - pub fn init() -> TauriPlugin { - Builder::new("test") - .invoke_handler(tauri::generate_handler![ - commands::ping, - commands::write_custom_file, - ]) - .setup(|app, api| { - #[cfg(mobile)] - let test = mobile::init(app, api)?; - #[cfg(desktop)] - let test = desktop::init(app, api)?; - app.manage(test); - - // コマンドからアクセスできるように「状態」を管理(manage) - app.manage(MyState::default()); - Ok(()) - }) - .build() - } - ``` +3. ### 新しいコマンドの公開 + + 「ステップ 2」は、実際のコマンド実装を記述するためのものでした。 + つづいて、そのコマンドをフロントエンドに公開して使用できるようにします。 + + + + 新たに実装したコマンドにフロントエンド IPC 要求を渡すための「呼び出しハンドラー」を生成するように Tauri ビルダーを設定します: + + ```rust title="src/lib.rs" ins="commands::write_custom_file," + pub fn init() -> TauriPlugin { + Builder::new("test") + .invoke_handler(tauri::generate_handler![ + commands::ping, + commands::write_custom_file, + ]) + .setup(|app, api| { + #[cfg(mobile)] + let test = mobile::init(app, api)?; + #[cfg(desktop)] + let test = desktop::init(app, api)?; + app.manage(test); + + // コマンドからアクセスできるように「状態」を管理(manage) + app.manage(MyState::default()); + Ok(()) + }) + .build() + } + ``` - フロントエンド・モジュールに新しいコマンドを公開します。 + フロントエンド・モジュールに新しいコマンドを公開します。 - このステップは、このサンプル・アプリケーションがフロントエンド・モジュールを正常にインポートするために不可欠です。 - この処理は便宜上のものであり、セキュリティへの影響はありません。というのも、コマンド・ハンドラーがすでに生成されており、コマンドをフロントエンドから手動で呼び出すことができるためです。 + このステップは、このサンプル・アプリケーションがフロントエンド・モジュールを正常にインポートするために不可欠です。 + この処理は便宜上のものであり、セキュリティへの影響はありません。というのも、コマンド・ハンドラーがすでに生成されており、コマンドをフロントエンドから手動で呼び出すことができるためです。 - ```ts title="guest-js/index.ts" ins={11-13} - import { invoke } from '@tauri-apps/api/core'; + ```ts title="guest-js/index.ts" ins={11-13} + import { invoke } from '@tauri-apps/api/core'; - export async function ping(value: string): Promise { - return await invoke<{ value?: string }>('plugin:test|ping', { - payload: { - value, - }, - }).then((r) => (r.value ? r.value : null)); - } + export async function ping(value: string): Promise { + return await invoke<{ value?: string }>('plugin:test|ping', { + payload: { + value, + }, + }).then((r) => (r.value ? r.value : null)); + } - export async function writeCustomFile(user_input: string): Promise { - return await invoke('plugin:test|write_custom_file', { - userInput: user_input, - }); - } - ``` + export async function writeCustomFile(user_input: string): Promise { + return await invoke('plugin:test|write_custom_file', { + userInput: user_input, + }); + } + ``` - :::tip - 呼び出しパラメータは「キャメルケース CamelCase」(結合する単語の語頭を大文字)で記述する必要があります。この例では、「`user_input`」ではなく「`userInput`」という書き方になります。 - ::: + :::tip + 呼び出しパラメータは「キャメルケース CamelCase」(結合する単語の語頭を大文字)で記述する必要があります。この例では、「`user_input`」ではなく「`userInput`」という書き方になります。 + ::: - 自分のパッケージがビルドされることを確認します: + 自分のパッケージがビルドされることを確認します: - ``` - pnpm build - ``` + ``` + pnpm build + ``` - + -4. ### デフォルトのプラグイン・アクセス権を定義 +4. ### デフォルトのプラグイン・アクセス権を定義 - このプラグイン例ではデフォルトで `write_custom_file` コマンドを公開する必要があるため、このコマンドを `default.toml` のアクセス権限(permissions)に追加する必要があります。 + このプラグイン例ではデフォルトで `write_custom_file` コマンドを公開する必要があるため、このコマンドを `default.toml` のアクセス権限(permissions)に追加する必要があります。 - + 先ほど公開した新しいコマンドを許可するために、このコマンドをデフォルトのアクセス権限のセットに追加します。 @@ -162,82 +170,80 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; permissions = ["allow-ping", "allow-write-custom-file"] ``` - + -5. ### サンプル・アプリケーションからテスト・コマンドを呼び出す +5. ### サンプル・アプリケーションからテスト・コマンドを呼び出す - 作成されたプラグイン・ディレクトリ構造には `examples/tauri-app` フォルダーがあり、そこにはプラグインをテストするためにすぐに使用できる Tauri アプリケーションが含まれています。 + 作成されたプラグイン・ディレクトリ構造には `examples/tauri-app` フォルダーがあり、そこにはプラグインをテストするためにすぐに使用できる Tauri アプリケーションが含まれています。 - 新しいコマンドを追加したので、その新しいコマンドを呼び出すようにフロントエンドを少し変更する必要があります。 + 新しいコマンドを追加したので、その新しいコマンドを呼び出すようにフロントエンドを少し変更する必要があります。 - + -```svelte title="src/App.svelte" del={11-13,42-45} ins={14-16,45-49} - - - -
-

Welcome to Tauri!

- - {' '} - - - {' '} -

Click on the Tauri, Vite, and Svelte logos to learn more.

- - {' '} -
- -
- -
- -
{@html response}
-
-
- -
{@html response}
-
- -
- - +
+

Welcome to Tauri!

-``` + + +

+ Click on the Tauri, Vite, and Svelte logos to learn more. +

+ +
+ +
+ +
+ +
{@html response}
+
+
+ +
{@html response}
+
+ + +
+ + + ``` これを実行して「書き込み」ボタンを押すと、次のような画面が表示されるはずです: @@ -250,8 +256,7 @@ success (成功) 仮フォルダーには、新しく実装されたプラグイン・コマンドからのメッセージが含まれている `test.txt` ファイルができているはずです。 🥳 -
- ``` +
From c9c2d3a02a5c67e1169588117644658b4a55f3d6 Mon Sep 17 00:00:00 2001 From: Ayres Vitor Date: Sat, 16 Aug 2025 16:32:49 -0300 Subject: [PATCH 4/7] uppercase dir --- .../capabilities-for-windows-and-platforms.mdx | 0 .../ja/learn/{security => Security}/using-plugin-permissions.mdx | 0 .../learn/{security => Security}/writing-plugin-permissions.mdx | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/content/docs/ja/learn/{security => Security}/capabilities-for-windows-and-platforms.mdx (100%) rename src/content/docs/ja/learn/{security => Security}/using-plugin-permissions.mdx (100%) rename src/content/docs/ja/learn/{security => Security}/writing-plugin-permissions.mdx (100%) diff --git a/src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx b/src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx similarity index 100% rename from src/content/docs/ja/learn/security/capabilities-for-windows-and-platforms.mdx rename to src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx diff --git a/src/content/docs/ja/learn/security/using-plugin-permissions.mdx b/src/content/docs/ja/learn/Security/using-plugin-permissions.mdx similarity index 100% rename from src/content/docs/ja/learn/security/using-plugin-permissions.mdx rename to src/content/docs/ja/learn/Security/using-plugin-permissions.mdx diff --git a/src/content/docs/ja/learn/security/writing-plugin-permissions.mdx b/src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx similarity index 100% rename from src/content/docs/ja/learn/security/writing-plugin-permissions.mdx rename to src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx From 87863b682b72ae159b0c3c2dce5d3cf603356317 Mon Sep 17 00:00:00 2001 From: Ayres Vitor Date: Sat, 16 Aug 2025 16:58:17 -0300 Subject: [PATCH 5/7] manually format --- ...capabilities-for-windows-and-platforms.mdx | 106 ++++--- .../Security/using-plugin-permissions.mdx | 280 +++++++++--------- .../Security/writing-plugin-permissions.mdx | 44 +-- 3 files changed, 214 insertions(+), 216 deletions(-) diff --git a/src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx b/src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx index a64a5c29fd..d31f14d6dd 100644 --- a/src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx +++ b/src/content/docs/ja/learn/Security/capabilities-for-windows-and-platforms.mdx @@ -27,39 +27,39 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; 1. ### Tauri アプリで複数のウィンドウを作成する -この演習では、`first`(第一)と `second`(第二)というラベルの付いた二つのウィンドウを持つアプリを作成します。 -Tauri アプリケーションでウィンドウを作成する方法はいくつかあります。 - -#### Tauri 設定ファイルを使用してウィンドウを作成 - -Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では次のようになります: - - - ```javascript - "productName": "multiwindow", - ... - "app": { - "windows": [ - { - "label": "first", - "title": "First", - "width": 800, - "height": 600 + この演習では、`first`(第一)と `second`(第二)というラベルの付いた二つのウィンドウを持つアプリを作成します。 + Tauri アプリケーションでウィンドウを作成する方法はいくつかあります。 + + #### Tauri 設定ファイルを使用してウィンドウを作成 + + Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では次のようになります: + + + ```javascript + "productName": "multiwindow", + ... + "app": { + "windows": [ + { + "label": "first", + "title": "First", + "width": 800, + "height": 600 + }, + { + "label": "second", + "title": "Second", + "width": 800, + "height": 600 + } + ], }, - { - "label": "second", - "title": "Second", - "width": 800, - "height": 600 - } - ], - }, - ... - } - ``` - + ... + } + ``` + -#### プログラムでウィンドウを作成 + #### プログラムでウィンドウを作成 Rust コード内で Tauri アプリを作成します: @@ -84,7 +84,7 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では ```
-{/* prettier-ignore */} + 2. ### 異なるウィンドウに異なるセキュリティ・レベルを適用 Tauri アプリのウィンドウでは、Tauri バックエンドのさまざまな機能やプラグインを使用できます。 @@ -96,7 +96,6 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では 有効化するアクションのカテゴリごとに「セキュリティ・レベル」ファイルを分割することをお勧めします。 - `src-tauri/capabilities` 内の JSON ファイルは、「セキュリティ・レベル」システムに対応済みです。 そこで、ファイルシステムとダイアログ・ウィンドウに関連するセキュリティ・レベルを `filesystem.json` と `dialog.json` に分割します。 @@ -112,14 +111,13 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では package.json README.md ``` - #### 「第一 `first`」ウィンドウにファイルシステムのセキュリティ・レベルを付与 「`first`」ウィンドウに、`$HOME` ディレクトリの内容への読み取りアクセス権を付与するようにセキュリティ・レベルを設定します。 - + 一つまたは複数のウィンドウ・ラベルを持つ「セキュリティ機能 capability」ファイル内の「`windows` フィールド」を使用します。 @@ -145,13 +143,13 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では - + #### 「第一 `first`」と「第二 `second`」ウィンドウにダイアログ機能を付与 「`first`」と「`second`」ウィンドウに「Yes/No」ダイアログを作成する機能を追加します。 - + 一つまたは複数のウィンドウ・ラベルを持つ「セキュリティ機能」ファイル内の `windows` フィールドを使用します。 @@ -165,31 +163,31 @@ Tauri 設定ファイル(通常は `tauri.conf.json` という名前)では } ``` - + 3. ### セキュリティ機能をプラットフォーム依存にする - 次に、特定のプラットフォームでのみアクティブになるようにセキュリティ機能をカスタマイズします。 - 以下の事例では、ファイルシステムのセキュリティ機能を `linux` と `windows` でのみ有効にします。 + 次に、特定のプラットフォームでのみアクティブになるようにセキュリティ機能をカスタマイズします。 + 以下の事例では、ファイルシステムのセキュリティ機能を `linux` と `windows` でのみ有効にします。 - + -プラットフォーム別に設定するには、セキュリティ機能ファイルの「`platforms` フィールド」で対象プラットフォームを指定します。 + プラットフォーム別に設定するには、セキュリティ機能ファイルの「`platforms` フィールド」で対象プラットフォームを指定します。 -```json title="filesystem.json" -{ - "identifier": "fs-read-home", - "description": "Allow access file access to home directory", - "local": true, - "windows": ["first"], - "permissions": ["fs:allow-home-read"], - "platforms": ["linux", "windows"] -} -``` + ```json title="filesystem.json" + { + "identifier": "fs-read-home", + "description": "Allow access file access to home directory", + "local": true, + "windows": ["first"], + "permissions": ["fs:allow-home-read"], + "platforms": ["linux", "windows"] + } + ``` -現在指定可能なプラットフォームは、`linux`、`windows`、`macos`、`android`、および `ios` です。 + 現在指定可能なプラットフォームは、`linux`、`windows`、`macos`、`android`、および `ios` です。 - + diff --git a/src/content/docs/ja/learn/Security/using-plugin-permissions.mdx b/src/content/docs/ja/learn/Security/using-plugin-permissions.mdx index 4cfbd63f84..449422a35f 100644 --- a/src/content/docs/ja/learn/Security/using-plugin-permissions.mdx +++ b/src/content/docs/ja/learn/Security/using-plugin-permissions.mdx @@ -35,42 +35,42 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; この段階を踏んだ説明手順では `pnpm` を使用して進めていきますが、別のパッケージ・マネージャーも選択可能です。選択したパッケージ・マネージャーに応じてコマンドを置き換えてください。 - - -``` -pnpm create tauri-app -``` - -``` -✔ Project name · plugin-permission-demo -✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun) -✔ Choose your package manager · pnpm -✔ Choose your UI template · Vanilla -✔ Choose your UI flavor · TypeScript - -Template created! To get started run: -cd plugin-permission-demo -pnpm install -pnpm tauri dev -``` - - - - ※ 処理内容の参考訳: - ✔ プロジェクト名 ・・・ - ✔ フロントエンドに用いる言語を選択 ・・・ - ✔ パッケージ・マネージャーを選択 ・・・ - ✔ UI テンプレートを選択 ・・・ - ✔ UI フレーバーを選択 ・・・ - - テンプレートが作成されました! 始めるには以下を実行: - cd (作成するプロジェクトのディレクトリ名) - pnpm install - pnpm tauri dev - - - - + + + ``` + pnpm create tauri-app + ``` + + ``` + ✔ Project name · plugin-permission-demo + ✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun) + ✔ Choose your package manager · pnpm + ✔ Choose your UI template · Vanilla + ✔ Choose your UI flavor · TypeScript + + Template created! To get started run: + cd plugin-permission-demo + pnpm install + pnpm tauri dev + ``` + + + + ※ 処理内容の参考訳: + ✔ プロジェクト名 ・・・ + ✔ フロントエンドに用いる言語を選択 ・・・ + ✔ パッケージ・マネージャーを選択 ・・・ + ✔ UI テンプレートを選択 ・・・ + ✔ UI フレーバーを選択 ・・・ + + テンプレートが作成されました! 始めるには以下を実行: + cd (作成するプロジェクトのディレクトリ名) + pnpm install + pnpm tauri dev + + + + 2. ### 「ファイルシステム」プラグインをアプリケーションに追加 @@ -81,7 +81,7 @@ pnpm tauri dev また、プラグインが Tauri コミュニティの取り組みとして行なわれているものであれば、[crates.io](https://crates.io/search?q=tauri-plugin-) 上で十中八九見つかるはずです。「`tauri-plugin-<プラグイン名>`」のように検索してみてください: - + @@ -113,7 +113,7 @@ pnpm tauri dev } ``` - + 3. ### 「ファイルシステム」プラグインのデフォルト・アクセス権の確認 @@ -124,133 +124,133 @@ pnpm tauri dev コミュニティ製プラグインに関するデフォルトのアクセス権設定を調べるには、そのプラグインのソース・コードを精査する必要があります。 その内容は `your-plugin/permissions/default.toml` に定義されているはずです。 - + -``` -"$schema" = "schemas/schema.json" + ``` + "$schema" = "schemas/schema.json" - [default] - description = """ + [default] + description = """ - # Tauri `fs` default permissions + # Tauri `fs` default permissions - This configuration file defines the default permissions granted to the filesystem. + This configuration file defines the default permissions granted to the filesystem. - ### Granted Permissions + ### Granted Permissions - This default permission set enables all read-related commands and allows access to the `$APP` folder and sub directories created in it. - The location of the `$APP` folder depends on the operating system, where the application is run. + This default permission set enables all read-related commands and allows access to the `$APP` folder and sub directories created in it. + The location of the `$APP` folder depends on the operating system, where the application is run. - In general the `$APP` folder needs to be manually created - by the application at runtime, before accessing files or folders - in it is possible. + In general the `$APP` folder needs to be manually created + by the application at runtime, before accessing files or folders + in it is possible. - ### Denied Permissions + ### Denied Permissions - This default permission set prevents access to critical components - of the Tauri application by default. - On Windows the webview data folder access is denied. + This default permission set prevents access to critical components + of the Tauri application by default. + On Windows the webview data folder access is denied. - """ - permissions = ["read-all", "scope-app-recursive", "deny-default"] + """ + permissions = ["read-all", "scope-app-recursive", "deny-default"] -``` + ``` - - - 〔参考訳〕 + + + 〔参考訳〕 - # Tauri 'fs' デフォルト・アクセス権 + # Tauri 'fs' デフォルト・アクセス権 - この設定ファイルは、「ファイルシステム fs」プラグインに付与されるデフォルトのアクセス権を定義します。 + この設定ファイルは、「ファイルシステム fs」プラグインに付与されるデフォルトのアクセス権を定義します。 - ### 許可されたアクセス権 + ### 許可されたアクセス権 - このデフォルトのアクセス「許可」権セットは、すべての読み取り関連コマンドを有効にし、「`$APP`」フォルダとその中に作成されているサブディレクトリへのアクセスを許可します。 - 「`$APP`」フォルダの場所は、アプリケーションが実行されるオペレーティング・システムによって異なります。 + このデフォルトのアクセス「許可」権セットは、すべての読み取り関連コマンドを有効にし、「`$APP`」フォルダとその中に作成されているサブディレクトリへのアクセスを許可します。 + 「`$APP`」フォルダの場所は、アプリケーションが実行されるオペレーティング・システムによって異なります。 - 通常、「`$APP`」フォルダ内のファイルやフォルダがアクセス可能になるには、アプリケーションによって実行時に手作業で「`$APP`」フォルダを生成する必要があります。 + 通常、「`$APP`」フォルダ内のファイルやフォルダがアクセス可能になるには、アプリケーションによって実行時に手作業で「`$APP`」フォルダを生成する必要があります。 - ### 拒否されたアクセス権 + ### 拒否されたアクセス権 - このデフォルトのアクセス「拒否」権セットは、デフォルトで Tauri アプリケーションの重要なコンポーネントへのアクセスを防止します。 - Windows では、Webview データ・フォルダーへのアクセスが拒否されます。 + このデフォルトのアクセス「拒否」権セットは、デフォルトで Tauri アプリケーションの重要なコンポーネントへのアクセスを防止します。 + Windows では、Webview データ・フォルダーへのアクセスが拒否されます。 - + - + 4. ### 適切なアクセス権の見つけ方 -手順 4 では、システムへの最小限のアクセスで、コマンドをフロントエンドに公開するために必要なアクセス権を見つける方法について説明します。 - -「`fs`」プラグインには自動生成されたアクセス権があり、個々のコマンドの無効化/有効化や、グローバル・スコープの許可/禁止を行ないます。 -アクセス権の詳細は、[公式ドキュメント](/ja/plugin/file-system/#permission-table) またはプラグインのソースコード(`fs/permissions/autogenerated`)を参照してください。 - -たとえば、ユーザーの `$HOME` フォルダにあるテキスト・ファイル「`test.txt`」への書き込みを有効にしたいとします。 - -そのためは、「自動生成されたアクセス権」の中で、`allow-write-text-file` のようなテキスト・ファイルへの書き込みを許可する権限を検索し、次に `$HOME/test.txt` ファイルへのアクセスを許可するスコープを検索します。 - -これらのアクセス権を `src-tauri/tauri.conf.json` の「セキュリティ・レベル `capabilities`」セクション、または「`src-tauri/capabilities/` フォルダー内のファイル」に追加する必要があります。 -デフォルトでは、`src-tauri/capabilities/default.json` の中には既に修正可能な「セキュリティ機能」があります。 - - - -```json title="src-tauri/capabilities/default.json" del={18} ins={19} -{ - "$schema": "../gen/schemas/desktop-schema.json", - "identifier": "default", - "description": "Capability for the main window", - "windows": ["main"], - "permissions": [ - "path:default", - "event:default", - "window:default", - "app:default", - "image:default", - "resources:default", - "menu:default", - "tray:default", - "shell:allow-open", - "fs:default", - "fs:allow-write-text-file" - ] -} -``` - - - -「`fs`」プラグインには `$HOME` フォルダー全体にアクセスするための自動生成されたスコープしか設定されていないため、自分に必要な独自のスコープを設定する必要があります。 -この独自のスコープは `write-text-file` コマンドのみを有効にして、`test.txt` ファイルだけが公開可能になるようにすべきです。 - - -```json title="src-tauri/capabilities/default.json" del={18} ins={19-22} - { - "$schema": "../gen/schemas/desktop-schema.json", - "identifier": "default", - "description": "Capability for the main window", - "windows": [ - "main" - ], - "permissions": [ - "path:default", - "event:default", - "window:default", - "app:default", - "image:default", - "resources:default", - "menu:default", - "tray:default", - "shell:allow-open", - "fs:allow-write-text-file", + 手順 4 では、システムへの最小限のアクセスで、コマンドをフロントエンドに公開するために必要なアクセス権を見つける方法について説明します。 + + 「`fs`」プラグインには自動生成されたアクセス権があり、個々のコマンドの無効化/有効化や、グローバル・スコープの許可/禁止を行ないます。 + アクセス権の詳細は、[公式ドキュメント](/ja/plugin/file-system/#permission-table) またはプラグインのソースコード(`fs/permissions/autogenerated`)を参照してください。 + + たとえば、ユーザーの `$HOME` フォルダにあるテキスト・ファイル「`test.txt`」への書き込みを有効にしたいとします。 + + そのためは、「自動生成されたアクセス権」の中で、`allow-write-text-file` のようなテキスト・ファイルへの書き込みを許可する権限を検索し、次に `$HOME/test.txt` ファイルへのアクセスを許可するスコープを検索します。 + + これらのアクセス権を `src-tauri/tauri.conf.json` の「セキュリティ・レベル `capabilities`」セクション、または「`src-tauri/capabilities/` フォルダー内のファイル」に追加する必要があります。 + デフォルトでは、`src-tauri/capabilities/default.json` の中には既に修正可能な「セキュリティ機能」があります。 + + + + ```json title="src-tauri/capabilities/default.json" del={18} ins={19} { - "identifier": "fs:allow-write-text-file", - "allow": [{ "path": "$HOME/test.txt" }] - }, - ] -} -``` - + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Capability for the main window", + "windows": ["main"], + "permissions": [ + "path:default", + "event:default", + "window:default", + "app:default", + "image:default", + "resources:default", + "menu:default", + "tray:default", + "shell:allow-open", + "fs:default", + "fs:allow-write-text-file" + ] + } + ``` + + + + 「`fs`」プラグインには `$HOME` フォルダー全体にアクセスするための自動生成されたスコープしか設定されていないため、自分に必要な独自のスコープを設定する必要があります。 + この独自のスコープは `write-text-file` コマンドのみを有効にして、`test.txt` ファイルだけが公開可能になるようにすべきです。 + + + ```json title="src-tauri/capabilities/default.json" del={18} ins={19-22} + { + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Capability for the main window", + "windows": [ + "main" + ], + "permissions": [ + "path:default", + "event:default", + "window:default", + "app:default", + "image:default", + "resources:default", + "menu:default", + "tray:default", + "shell:allow-open", + "fs:allow-write-text-file", + { + "identifier": "fs:allow-write-text-file", + "allow": [{ "path": "$HOME/test.txt" }] + }, + ] + } + ``` + 5. ### アクセス権の実地テスト diff --git a/src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx b/src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx index da14633e68..7382ce4023 100644 --- a/src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx +++ b/src/content/docs/ja/learn/Security/writing-plugin-permissions.mdx @@ -27,18 +27,18 @@ import TranslationNote from '@components/i18n/TranslationNote.astro'; 最新バージョンのインストールが行なわれていれば、Tauri CLI を使用してプラグインの作成を開始できます。 -{/* prettier-ignore */} - -```sh -mkdir -p tauri-learning -cd tauri-learning -cargo tauri plugin new test -cd tauri-plugin-test -pnpm install -pnpm build -cargo build -``` - + {/* prettier-ignore */} + + ```sh + mkdir -p tauri-learning + cd tauri-learning + cargo tauri plugin new test + cd tauri-plugin-test + pnpm install + pnpm build + cargo build + ``` + 2. ### 新しいコマンドの作成 @@ -159,7 +159,7 @@ cargo build このプラグイン例ではデフォルトで `write_custom_file` コマンドを公開する必要があるため、このコマンドを `default.toml` のアクセス権限(permissions)に追加する必要があります。 - + 先ほど公開した新しいコマンドを許可するために、このコマンドをデフォルトのアクセス権限のセットに追加します。 @@ -170,7 +170,7 @@ cargo build permissions = ["allow-ping", "allow-write-custom-file"] ``` - + 5. ### サンプル・アプリケーションからテスト・コマンドを呼び出す @@ -178,7 +178,7 @@ cargo build 新しいコマンドを追加したので、その新しいコマンドを呼び出すようにフロントエンドを少し変更する必要があります。 - + ```svelte title="src/App.svelte" del={11-13,42-45} ins={14-16,45-49}