> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/commander-cli/service-mode-rest-api/service-tunneling.md).

# サービストンネル

クラウドトンネリングを利用したコマンダーサービスモードREST APIへのアクセス

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

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

### 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に追加済みで、DNSレコードが正しく構成されているドメイン
* ゼロトラストダッシュボードで生成するトンネルトークン

#### 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. トンネルの作成
   * **\[Networking]** > **\[Tunnels]** へ移動
   * **\[Create Tunnel]** をクリックし、トンネル名を入力する (例: `commander-service-tunnel`)
   * コマンダーでのサービス構成に使用するため、トンネルトークン (`ey...`) をコピーする
   * トンネルをすぐに接続しない場合でも、キャンセルすれば作成したトンネルは残ります
2. ルートの作成
   * 作成したトンネルを開き、**\[Routes]** へ移動
   * **\[+ Add route]** をクリックし、**\[Published Application]** を選択する
   * トンネルルートの **Subdomain** と **Domain** を指定する (例: `commander.example.com`)
   * **Service URL** に、コマンダーサービスモードのアプリケーションが動作するローカルのホスト名とポートを入力する (例: `http://localhost:PORT`)。`PORT` はサービスモードで選択したポート番号です
   * **\[Add route]** をクリックする

***

### Tailscale

コマンダーサービスモードをTailscaleで利用するには、[tailscale.com](https://tailscale.com)でアカウント登録を行って認証キーを生成し、tailnetのACLポリシーでFunnelを許可します。

**手順1: 認証キーを生成**

2種類のキーを利用できます。

* **個人用認証キー:** Tailscale管理コンソールで **Settings** > **Keys** > **Generate auth key** の順に開きます。このキーでは、ACLの変更は不要です。
* **OAuthクライアントシークレット:** Tailscale管理コンソールで **Settings** > **OAuth clients** > **Generate client** の順に開き、`auth_keys` スコープとACLタグを1つ以上選択します。ACLポリシーに `tagOwners` のエントリ (手順2) が必要で、`service-create` の実行時に `-tst` フラグも指定する必要があります。

**手順2: ACLポリシーでFunnelへのアクセスを許可**

tailnetでFunnelを初めて使用する際は、tailnetのACLポリシー (**Access Controls**) で、そのノードを明示的に許可する必要があります。許可がない場合、コマンダーは1回限りの手動承認リンクを報告して停止します。以降のノードでこの操作を毎回行わずに済むよう、ACLポリシーに以下を追加します。以下の `tag:commander-service` は一例です。OAuthクライアントで選択したタグ、および `-tst` に渡すタグと一致していれば、任意のタグ名を使用できます。

```json
{
  "tagOwners": {
    "tag:commander-service": ["autogroup:admin"]
  },
  "nodeAttrs": [
    { "target": ["tag:commander-service"], "attr": ["funnel"] },
    { "target": ["autogroup:member"], "attr": ["funnel"] }
  ]
}
```

* `tagOwners` は、タグ付きでOAuthにより発行された認証キーを使用する場合にのみ必要です。`tag:commander-service` は、任意のタグ名に置き換えてください。
* 1つ目の `nodeAttrs` エントリは、そのタグで認証されたノード (OAuthで発行されたキー) にFunnelの権限を付与します。
* 2つ目の `nodeAttrs` エントリは、個人アカウントまたはタグなしのアカウントにFunnelの権限を付与します。通常の個人用認証キーを使用する場合に含めてください。

**手順3: サービスを起動**

```
keeper service-create -p <port> -ts <tailscale-auth-key> -c '<commands>'
```

OAuthで発行されたキーの場合は、そのキーに紐づくタグも指定します。タグ名は、ACLポリシーに定義したものと一致する任意の名前です。`tag:commander-service` は一例です。

```
keeper service-create -p <port> -ts <oauth-client-secret> -tst tag:commander-service -c '<commands>'
```

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

* Keeperのサービスアカウントは最小限の権限で実行すること
* コマンダーは `service-start` のたびに `--force-reauth` で再認証するため、1回限り有効な認証キーは1回しか使用できません。サービスを再起動する場合は、再利用可能なキーを使用すること
* 使用するコマンドは必要なものに限定すること (「コマンド一覧」を参照)

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
