# Docker上でのゲートウェイ

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2F5xaEAVxSU4345DLQjBbO%2Fimage.png?alt=media&#x26;token=74a6496b-64dd-48d4-804e-96b40920227d" alt=""><figcaption></figcaption></figure>

## 概要

本ページでは、Docker上でKeeperゲートウェイのインストール、設定、アップデート方法を取り扱います。KeeperゲートウェイコンテナはRocky Linux 9のベースイメージを使用し、[DockerHub](https://hub.docker.com/r/keeper/gateway)でホストされています。

## 要件

* すべてのPAM機能を活用するのに、x86 AMDプロセッサーを搭載したLinuxホスト
* `docker` および `docker compose` がインストールされていること ([LinuxへのDockerインストールのページ](/keeperpam/jp/privileged-access-manager/references/installing-docker-on-linux.md)をご参照ください)

***

## ゲートウェイを作成

新しいゲートウェイの展開は、ウェブボルトかデスクトップアプリから **\[新規作成]** > **\[ゲートウェイ]** をクリックして作成します。

また、コマンダーCLIからゲートウェイと構成ファイルを作成することもできます。

```sh
pam gateway new -n "<Gateway Name>" -a <Application Name or UID> -c b64
```

アプリケーション名とUIDは、`secrets-manager app list`コマンドで確認できます。

## インストールのオプション

ゲートウェイのセットアップ方法は以下の2種類あります。

* [Docker自動インストール](#auto-docker-installation)
* [Docker手動インストール](#manual-installation)

***

## 1. Docker自動インストール <a href="#auto-docker-installation" id="auto-docker-installation"></a>

Keeperの自動インストーラで環境をセットアップします。

{% stepper %}
{% step %}
**Dockerゲートウェイの作成とインストールコマンドのコピー**

Dockerオペレーティングシステム用に、[ゲートウェイウィザード](/keeperpam/jp/privileged-access-manager/getting-started/gateways/one-time-access-token.md#using-the-gateway-wizard)か[Keeperシークレットマネージャー](/keeperpam/jp/privileged-access-manager/getting-started/gateways/one-time-access-token.md#using-keeper-secrets-manager)のいずれかを使用して、新しいゲートウェイを作成します。

作成が完了すると、Linuxホストに貼り付けて実行するためのインストールコマンドが表示されます。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2F05jR4To9uYUbQeyKiD7O%2Fimage.png?alt=media&#x26;token=0a1b1a6d-5292-4be7-b741-c5684f8a2975" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**インストールコマンドの実行**

Linuxホスト上で、任意の作業ディレクトリに移動し、コピーしたインストールコマンドを実行します。

このインストールコマンドにより、以下の処理が行われます。

* DockerおよびDocker Composeのインストール (未インストールの場合)
* Docker Composeファイル、Seccompファイル、AppArmorファイルの生成
* サービスの準備
  {% endstep %}

{% step %}
**サービスの起動**

`docker-compose.yml`、`docker-seccomp.json`、`gateway-apparmor-profile`ファイルが保存されているフォルダで作業していることを確認してください。

以下のコマンドを実行すると、Keeperゲートウェイコンテナがバックグラウンドで起動します。

```bash
docker compose up -d
```

{% endstep %}
{% endstepper %}

***

## 2. Docker手動インストール <a href="#manual-installation" id="manual-installation"></a>

手動でDocker環境をセットアップする場合は、以下の手順を行います。

{% stepper %}
{% step %}
**Docker Compose**

Docker Composeファイルは、ボルトUIを通じて提供されます。通常、このファイルはローカル環境に `docker-compose.yml` として保存し、任意のフォルダに配置します。以下はDocker Composeファイルの例です。

```
services:
      keeper-gateway:
        platform: linux/amd64
        image: keeper/gateway:latest
        shm_size: 16g
        restart: unless-stopped
        security_opt:
          - seccomp:docker-seccomp.json
          - apparmor:gateway-apparmor-profile
        environment:
          LC_ALL: "C.UTF-8"
          ACCEPT_EULA: Y
          GATEWAY_CONFIG: XXXXXXXXXXXXXXXXX
```

{% hint style="warning" %}
`shm_size` は重要なパラメータです。サーバーの利用可能メモリの少なくとも半分を割り当てることを推奨します。本番環境のゲートウェイには、できるだけ多くのメモリとCPUを割り当ててください。リモートブラウザ分離セッションを使用する場合、Chromiumはプロセスごとに多くのメモリを消費します。
{% endhint %}

必要な環境変数は `GATEWAY_CONFIG` のみとなります。この変数はゲートウェイ作成時にKeeperによって生成されるbase64エンコードされた構成です。
{% endstep %}

{% step %}
**Seccompファイル**

`docker-seccomp.json` ファイルをDocker Composeファイルと同じフォルダに配置します。

[こちらから](https://raw.githubusercontent.com/Keeper-Security/KeeperPAM/refs/heads/main/gateway/docker-seccomp.json)ファイルをダウンロードするか以下を実行します。

{% code overflow="wrap" %}

```bash
curl -O https://raw.githubusercontent.com/Keeper-Security/KeeperPAM/refs/heads/main/gateway/docker-seccomp.json
```

{% endcode %}
{% endstep %}

{% step %}
**AppArmorプロファイル (Ubuntu/Debianディストリビューションで必須)**

{% hint style="info" %}
この手順は、UbuntuおよびDebian系ディストリビューションで必須です。\
その他のLinuxディストリビューション (RHEL、CentOS、Fedora、Amazon Linuxなど) の場合は、手順4へお進みください。
{% endhint %}

`gateway-apparmor-profile` ファイルをDocker Composeファイルと同じフォルダに配置します。

[こちら](https://raw.githubusercontent.com/Keeper-Security/KeeperPAM/refs/heads/main/gateway/gateway-apparmor-profile)からファイルをダウンロードするか以下を実行します。

{% code overflow="wrap" %}

```bash
curl -O https://raw.githubusercontent.com/Keeper-Security/KeeperPAM/refs/heads/main/gateway/gateway-apparmor-profile
```

{% endcode %}

apparmor configを有効にします。

{% code overflow="wrap" %}

```bash
sudo apparmor_parser -r gateway-apparmor-profile
sudo cp gateway-apparmor-profile /etc/apparmor.d/
```

{% endcode %}
{% endstep %}

{% step %}
**サービスを開始**

`docker-compose.yml` が保存されているフォルダへ移動し、以下のコマンドを実行すると、Docker Composeファイルで定義された通りにKeeperゲートウェイコンテナがバックグラウンドで実行されます。

```sh
docker compose up -d
```

{% endstep %}
{% endstepper %}

{% hint style="info" %}
ボルトのバージョン 17.4 では、新しいゲートウェイを作成する際に使用される `docker-compose.yml` ファイル内で、`gateway-apparmor-profile` が誤って `gateway-app-armor-profile` と記載されています。

この問題を修正するには、余分なハイフンを削除し、`gateway-apparmor-profile` に修正してください。
{% endhint %}

***

## ログ

最新バージョンのKeeperゲートウェイを実行している場合、ログに以下のような出力が表示されます。

```
docker compose logs keeper-gateway
```

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2Ft2fR9L90R0ue9xn0cikA%2Fimage.png?alt=media&#x26;token=00d78f0d-3670-4ad4-b6bb-01b6d9ba0c81" alt=""><figcaption><p>KeeperゲートウェイのDockerログ</p></figcaption></figure>

ボルト内の **\[シークレットマネージャー]** 画面から、**\[アプリケーション]** > **\[ゲートウェイ]** へ移動します。ゲートウェイが **\[オンライン]** と表示されます。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2F88LKMX10Y2uyPKuBvXhO%2Fimage.png?alt=media&#x26;token=36d294ad-9328-4789-a420-eb81f8ab9ce2" alt=""><figcaption><p>オンライン状態のゲートウェイ</p></figcaption></figure>

***

## ゲートウェイサービスの管理

#### サービス起動

```
docker compose up -d
```

#### サービス停止

```
docker compose stop
```

#### サービスの再起動

```
docker compose restart
```

#### ゲートウェイコンテナへ接続

```
docker compose exec keeper-gateway bash
```

***

## 再起動の際に自動的にゲートウェイを起動

`docker-compose.yml` ファイルで、以下のように再起動ポリシーを設定してください。

```
services:
  keeper-gateway:
    restart: unless-stopped
```

`docker-compose.yml` ファイルに `"restart: unless-stopped"` または `"restart: always"` パラメーターを追加すると、環境に再起動ポリシーが適用されます。

Docker環境でKeeperゲートウェイをホストOSに自動起動させたい場合は、以下の手順を実行してください (Linuxホスト)。

最初に、`/etc/systemd/system/keeper-gateway.service` にファイルを作成します。

```
[Unit]
Description=Keeper Gateway Docker Compose
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/path/to/install
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
User=myusername
Group=docker

[Install]
WantedBy=multi-user.target
```

備考

* `/path/to/install` は、`docker-compose.yml` の配置パスに置き換えます。
* `myusername` は、Dockerを実行するユーザーに置き換えます。
* `docker` グループは、環境で定義されているグループに置き換えます。
* `ExecStart` および `ExecStop` のバイナリパスが正しいことを確認します。

その後サービスを有効にします。

```
sudo systemctl daemon-reload
sudo systemctl enable keeper-gateway.service
sudo systemctl start keeper-gateway.service
```

重要: 再起動後もAppArmorファイルが読み込まれ利用できる状態になっていることを確認してください。

```bash
sudo apparmor_parser -r gateway-apparmor-profile
sudo cp gateway-apparmor-profile /etc/apparmor.d/
```

再起動後、稼働していることを確認します。

```bash
systemctl status keeper-gateway
```

***

## デバッグ

ゲートウェイで詳細なデバッグログを有効化するには、`Docker Compose` ファイルに以下の environment セクションを追加してデバッグロギングを有効化します。

```yaml
services:
  keeper-gateway:
    .....
    environment:
      LC_ALL: "C.UTF-8"
      KEEPER_GATEWAY_LOG_LEVEL: "debug" # ゲートウェイ用のログ
      LOG_LEVEL: "debug"                # guacd用のログ
```

ログレベルを変更した後、以下のコマンドでDockerに反映します。

```bash
docker compose up -d
```

次のコマンドでKeeperゲートウェイのログを確認します。

```bash
docker compose logs -f keeper-gateway
```

***

## アップデート

次のコマンドを実行すると、Keeperゲートウェイコンテナが最新バージョンに更新され、サービスが再起動します。

```bash
docker compose pull
docker compose up -d
```

***

## ヘルスチェック

ゲートウェイサービスの動作状況を確認するために、ヘルスチェックを設定できます。Dockerのオーケストレーションやロードバランサー、自動監視ツールと連携させる際に便利です。設定方法や具体例については、[ヘルスチェック](/keeperpam/jp/privileged-access-manager/getting-started/gateways/health-checks.md)のページをご参照ください。

***

## ホストインスタンスへの接続

Keeperゲートウェイの便利な機能の一つに、ホストマシンへの接続やトンネルを開く機能があります。Docker Composeファイルに `extra_hosts` セクションを追加し、値を `host.docker.internal:host-gateway` と設定すると、ホストへのセッションを直接開くことができます。

以下はゲートウェイコンテナを含むdocker composeの例となります。

```
services:
      keeper-gateway:
        platform: linux/amd64
        image: keeper/gateway:latest
        shm_size: 16g
        restart: always
        extra_hosts:
          - "host.docker.internal:host-gateway"
        security_opt:
          - seccomp:./docker-seccomp.json
          - apparmor=./gateway-apparmor-profile
        environment:
          LC_ALL: "C.UTF-8"
          ACCEPT_EULA: Y
          GATEWAY_CONFIG: xxxxxxxx
```

このオプションを有効にすると、ホストへの接続を確立できます。例えば、SSH接続を開くには、以下の手順を実行します。

* SSH秘密鍵を使用して[PAMユーザー](/keeperpam/jp/privileged-access-manager/getting-started/pam-resources/pam-user.md)レコードを作成します。
* ホスト名を `host.docker.internal`、ポートを `22` にして[PAMマシン](/keeperpam/jp/privileged-access-manager/getting-started/pam-resources/pam-machine.md)Aprレコードを作成します。
* PAM設定でPAMユーザーを指定し、[SSH接続](/keeperpam/jp/privileged-access-manager/connections/session-protocols/ssh-connections.md)を有効にします。

## ホストからKeeperゲートウェイサービスを更新する

KeeperPAMを使用してホストサービスにSSH接続している場合、バックグラウンドでゲートウェイのコンテナ更新を実行することでコンテナを更新できます。

```
docker compose pull
nohup docker compose up -d keeper-gateway &
```

## ネットワーク要件

Keeperゲートウェイはアウトバウンドのみの接続を確立し、インバウンドのファイアウォールルールは不要です。以下のアウトバウンド接続を許可する必要があります。

<table><thead><tr><th width="310.1015625">宛先エンドポイント</th><th>使用ポート</th><th>詳細</th></tr></thead><tbody><tr><td><p><strong>Keeperクラウド</strong><br><code>keepersecurity.[x]</code></p><p>エンドポイント:</p><p>米国: <code>.com</code></p><p>EU: <code>.eu</code></p><p>豪州: <code>.com.au</code></p><p>日本: <code>.jp</code></p><p>カナダ: <code>.ca</code></p><p>US_GOV: <code>.us</code></p></td><td>TLSポート443</td><td>Keeperクラウドと通信し、SSHやRDPなどのネイティブプロトコルで対象のインフラストラクチャにアクセスします</td></tr><tr><td><p><strong>Keeperルーター</strong><br><code>connect.keepersecurity.[x]</code></p><p>エンドポイント:</p><p>米国: <code>.com</code></p><p>EU: <code>.eu</code></p><p>豪州: <code>.com.au</code></p><p>日本: <code>.jp</code></p><p>カナダ: <code>.ca</code></p><p>US_GOV: <code>.us</code></p></td><td>TLSポート443</td><td>Keeperルーターと通信し、安全なリアルタイムのWebSocket接続を確立します</td></tr><tr><td><p><strong>Keeper Stun/Turnサービス</strong></p><p><code>krelay.keepersecurity.[x]</code></p><p>エンドポイント:</p><p>米国: <code>.com</code></p><p>EU: <code>.eu</code></p><p>豪州: <code>.com.au</code></p><p>日本: <code>.jp</code></p><p>カナダ: <code>.ca</code></p><p>US_GOV: <code>.us</code></p></td><td>TCPおよびUDPのポート3478を開放<br><br>TCPおよびUDPのポート49152〜65535へのアウトバウンドアクセス<br></td><td>エンドユーザーのボルトと対象システムの間で、ゲートウェイ経由の安全で暗号化されたWebRTC接続を実現します</td></tr></tbody></table>

ゲートウェイはすべての暗号化および復号をローカルで行うことでゼロ知識を維持します。KeeperシークレットマネージャーのAPIを使用してKeeperクラウドと通信します。

ゲートウェイの初期インストールファイルはkeepersecurity.comから取得されます。インストール後は、ゲートウェイの定常的なアウトバウンド接続を、ドキュメントに記載されているリージョン別エンドポイントのみに制限することが可能です。

***

## **ディスク容量の管理**

時間の経過とともに、新しいゲートウェイのバージョンをデプロイすると、古いDockerイメージがホストサーバー上に蓄積することがあります。これにより、ディスク容量を大きく消費する場合があります。\
円滑な運用とストレージ不足の防止のため、定期的にディスク使用状況を確認し、不要なDockerイメージを削除することを推奨します。

### ディスク使用状況の確認

Keeperゲートウェイサーバーで、次のコマンドを実行します。

```bash
df -h
```

このコマンドは、すべてのマウント済みファイルシステムの空き容量を人間が読みやすい形式で表示します。特に、Dockerのデータが保存されるパーティション (通常は `/var/lib/docker`) に注意してください。

ディスク使用率が高くなっている (例: 80〜90%以上使用) 場合は、古いDockerイメージを削除することを検討してください。

### 古いDockerイメージの削除

Keeperゲートウェイを更新すると、Dockerは以前のイメージをシステム上に保持します。未使用のDockerイメージをすべて削除するには、次のコマンドを使用します。

```bash
docker image prune -a
```

* `-a` フラグを付けることで、未使用のすべてのイメージ (参照されていないものも含む) が削除されます。
* 実行中に確認メッセージが表示されたら、`y` と入力して続行します。

**出力例**

```
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
...
Total reclaimed space: 4.8GB
```

この操作により、実行中のコンテナで使用されていない古いイメージのみが安全に削除されます。

***

## 参考資料

* [DockerHub内のページ](https://hub.docker.com/r/keeper/gateway)
* クイックリファレンス: [LinuxへのDockerのインストール](/keeperpam/jp/privileged-access-manager/references/installing-docker-on-linux.md)[およびLinuxへのDocker Composeのインストール](/keeperpam/jp/privileged-access-manager/references/installing-docker-on-linux.md)


---

# 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/privileged-access-manager/getting-started/gateways/gateway-with-docker.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.
