# サービストンネル

## トンネリングを利用したサービスモードの作成

Keeperコマンダーのサービスモードでサードパーティ連携を有効にするには、NgrokやCloudflareと連携します。これにより、専用のドメイン名を使用した直接接続が可能になります。以下の手順に従って、トンネリングサービスを使用したサービスモードの構成を行ってください。

### Ngrok

コマンダーサービスモードをNgrokで利用するには、ngrok.comでアカウント登録を行い、以下のページでAuth tokenを生成します。

* <https://dashboard.ngrok.com/authtokens>

カスタムドメインを利用する場合は、以下のページでドメインを設定し、コマンダーサービスモード起動時にカスタムサブドメインを指定します。

* <https://dashboard.ngrok.com/domains>

Ngrokを利用する際は、以下の点にご注意ください。

* Keeperのサービスアカウントは最小限の権限で実行すること
* サービスへのアクセスはNgrokの「IP Policies」で制限すること
* APIでレコード追加のみ必要な場合は `record-add` のみ許可するなど、使用するコマンドは必要なものに限定すること (詳細は「コマンド一覧」を参照)

***

### Cloudflare

以下は、Cloudflareトンネルを利用して、インターネット経由でコマンダーサービスモードに安全にアクセスする手順です。

#### 要件

開始前に次を準備してください。

* Cloudflareアカウント ([こちら](https://dash.cloudflare.com/)でサインアップ)
* Cloudflareに追加済みのドメイン
* ゼロトラストダッシュボードで生成するトンネルトークン

#### 1. ドメインをCloudflareに追加

1. [Cloudflareのダッシュボード](https://dash.cloudflare.com/)にログインする
2. ドメインを追加
   * ドメイン追加画面で **\[Onboard a Domain]** をクリックする
   * ドメイン名を入力する (example.comなど)
   * Cloudflareのプランを選択する (FreeまたはPaid)
3. DNSレコードを確認する
   * Cloudflareが既存のDNSレコードを自動検出
   * 必要に応じて確認・編集
4. ネームサーバーを更新する
   * Cloudflareが2つのネームサーバーを提示
   * ドメイン登録事業者側で上記に更新
   * DNSの反映を待つ (最大24時間かかる場合あり)
5. SSL/TLSを有効化
   * ダッシュボードでSSL/TLS画面を開く
   * SSLモードを「Full」または「Full (strict)」に設定する

### 2. Cloudflareトンネルを作成

1. ゼロトラストダッシュボードを開く
   * [Cloudflare Zero Trust](https://one.dash.cloudflare.com/)へ移動
   * **\[Networks]** > **\[Connectors]** へ移動
2. トンネルの作成
   * **\[Create a tunnel]** をクリックする
   * Connector Typeに **\[Cloudflared]** を選択する
   * トンネル名を入力する (例: `commander-service-tunnel`)
   * コマンダーでのサービス構成に使用するため、トンネルトークンを保存する
3. 公開ホスト名の作成
   * トンネル設定中に `api.yourdomain.com` などの公開ホスト名を作成する。Pathは空欄のまま。
   * コマンダーサービスモードの構成に応じて、HTTPまたはHTTPSのいずれかを指定します。\
     基本的な例では、localhostとローカルポートを使用するため、HTTPが使用されています。
     1. Type: HTTP
     2. URL: `localhost: <PORT>` か、コマンダーの構成で指定しているURL


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/commander-cli/service-mode-rest-api/service-tunneling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
