> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-dev-containers.md).

# Dev Containers 内の Device Protection

Dev Container に Device Protection を Feature として追加する [Feature](https://containers.dev/implementors/features/)、そのため、任意の `devcontainer.json` カスタム Dockerfile なしで任意のベースイメージに追加できます。

まず [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md) まず。Feature は同じパッケージを同じ `--container` モードでインストールするため、エントリーポイント、Aikido CA 変数、およびトークンルールはすべて同じように動作します。

## Feature を追加する

プロジェクトと同じ場所に、たとえば `.devcontainer/features/device-protection/`:

{% code title=".devcontainer/features/device-protection/devcontainer-feature.json" overflow="wrap" %}

```json
{
  "id": "device-protection",
  "version": "1.0.0",
  "name": "Aikido Device Protection",
  "description": "コンテナー内のパッケージマネージャーの通信がマルウェアとして検査されるよう、--container モードで Aikido Device Protection をインストールします。",
  "entrypoint": "aikido-endpoint-protection-container-entrypoint"
}
```

{% endcode %}

`entrypoint` イメージ自身の entrypoint を置き換えるのではなく、エージェントの supervisor を並行して実行します。

{% code title=".devcontainer/features/device-protection/install.sh" overflow="wrap" %}

```bash
#!/usr/bin/env bash
set -euo pipefail

case "$(uname -m)" in
  x86_64) ARCH=amd64 ;;
  aarch64) ARCH=arm64 ;;
  *) echo "Aikido Device Protection: unsupported architecture $(uname -m)" >&2; exit 1 ;;
esac

if command -v apt-get >/dev/null 2>&1; then
  apt-get update
  apt-get install -y --no-install-recommends curl ca-certificates
  curl -fLO "https://github.com/AikidoSec/safechain-internals/releases/latest/download/EndpointProtection-${ARCH}.deb"
  AIKIDO_CONTAINER=1 AIKIDO_CI_CD=1 apt-get install -y --no-install-recommends "./EndpointProtection-${ARCH}.deb"
  rm -f "EndpointProtection-${ARCH}.deb"
  rm -rf /var/lib/apt/lists/*
elif command -v dnf >/dev/null 2>&1; then
  . /etc/os-release
  EL="el${VERSION_ID%%.*}"
  dnf install -y --setopt=install_weak_deps=False curl ca-certificates
  curl -fLO "https://github.com/AikidoSec/safechain-internals/releases/latest/download/EndpointProtection-${ARCH}.${EL}.rpm"
  AIKIDO_CONTAINER=1 AIKIDO_CI_CD=1 dnf install -y --setopt=install_weak_deps=False "./EndpointProtection-${ARCH}.${EL}.rpm"
  rm -f "EndpointProtection-${ARCH}.${EL}.rpm"
else
  echo "Aikido Device Protection: apt-get も dnf も見つからず、サポートされないベースイメージです" >&2
  exit 1
fi
```

{% endcode %}

これは Device Protection in Containers の package-file 版なので、イメージにトークンは埋め込まれません。代わりに `.deb` または `.rpm` ベースイメージのパッケージマネージャーとアーキテクチャに一致するものを選択します。これは手動の Linux インストールで使うのと同じファイルです。

{% hint style="warning" %}
追加しないでください `トークン` を Feature オプションとして。オプションは `devcontainer-features.env` に書き込まれ、インストールスクリプトがイメージビルド中に source するため、その方法で渡したトークンがビルドレイヤーに残る可能性があります。代わりに `AIKIDO_TOKEN` をコンテナー起動時に渡してください。 `containerEnv` を通して下記のようにします。
{% endhint %}

## devcontainer.json で接続する

{% code title=".devcontainer/devcontainer.json" overflow="wrap" %}

```json
{
  "name": "my-app",
  "image": "mcr.microsoft.com/devcontainers/javascript-node:20",
  "features": {
    "./features/device-protection": {}
  },
  "containerEnv": {
    "AIKIDO_TOKEN": "${localEnv:AIKIDO_TOKEN}"
  },
  "postCreateCommand": "echo 'for f in /etc/profile.d/aikido-*.sh; do [ -e \"$f\" ] && . \"$f\"; done' >> ~/.bashrc"
}
```

{% endcode %}

* `features` Feature をローカルパスで参照します。基準は `devcontainer.json`.
* `containerEnv` コンテナー起動時にトークンを渡します。 `AIKIDO_TOKEN` Dev Container を開く前に、シェル（または Codespaces の secret）で
* `postCreateCommand` CA の読み込みを `~/.bashrc`に追記するため、後からコンテナー内で開いたターミナル（VS Code の統合ターミナル、Codespaces）は、インストールを `SELF_SIGNED_CERT_IN_CHAIN`.

Dev Container のデフォルトシェルが bash ではなく zsh なら、 `~/.zshrc` に追記してください:

{% tabs %}
{% tab title="bash" %}

```json
"postCreateCommand": "echo 'for f in /etc/profile.d/aikido-*.sh; do [ -e \"$f\" ] && . \"$f\"; done' >> ~/.bashrc"
```

{% endtab %}

{% tab title="zsh" %}

```json
"postCreateCommand": "echo 'for f in /etc/profile.d/aikido-*.sh; do [ -e \"$f\" ] && . \"$f\"; done' >> ~/.zshrc"
```

{% endtab %}
{% endtabs %}

すでにカスタム `Dockerfile` を別の理由でビルドしている場合でも、 `features` それにも上から適用されます。もうエージェントの install や `ENTRYPOINT` をその `Dockerfile` に自分で追加する必要はなく、Feature がそれを行います。

フォルダーを各リポジトリに vendoring する代わりにリポジトリ間で Feature を再利用するには、チームが管理するレジストリに `devcontainer features publish`で一度公開し、次のように参照します `ghcr.io/<your-org>/devcontainer-features/device-protection:1` パスではなく。次を参照してください: [Dev Containers CLI のドキュメント](https://containers.dev/implementors/features-distribution/) 公開コマンドについて。

## GitHub Codespaces の secret

Codespaces では、これを `AIKIDO_TOKEN` コミットするのではなく、リポジトリまたは組織の Codespaces secret として追加してください。 `${localEnv:AIKIDO_TOKEN}` ローカルのシェル変数を拾うのと同じように、環境変数として公開された secret を拾います。

## 動作確認

Dev Container で新しいターミナルを開き（新規のものなので、 `postCreateCommand` 変更）を拾って、次を実行します:

{% code overflow="wrap" %}

```bash
curl -sS -o /dev/null -w "%{http_code}\n" --max-time 15 https://registry.npmjs.org/safe-chain-test/-/safe-chain-test-0.0.1-security.tgz
aikidoctl バージョン
```

{% endcode %}

次の `curl` を出力します `403`、エージェントがマルウェアのテストパッケージを拒否し、そして `aikidoctl バージョン` はインストール済みバージョンとエージェントの状態を報告します。

## トラブルシューティング

entrypoint と install 手順は他の Linux コンテナーと同じなので、Device Protection in Containers のトラブルシューティング表から始めてください。Dev Container 固有の追加点は 2 つあります:

| 問題                                                                            | 修正                                                                                                                                                  |
| ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| パッケージのインストールが `SELF_SIGNED_CERT_IN_CHAIN` 統合ターミナルでは失敗するが、 `postCreateCommand` | ターミナルは `postCreateCommand` 完了する前に開かれていたか、追記先とは別のシェルです。新しいターミナルを開き、 `~/.bashrc` （または `~/.zshrc`を確認してください（ `aikido-*.sh` の読み込み行                       |
| `apt-get も dnf も見つからず、サポートされないベースイメージ`                                        | ベースイメージは、Feature がまだ扱っていないパッケージマネージャー、たとえば Alpine の `apk`を使っています。これに対応するブランチを追加するか、Device Protection in Containers に示されているようにエージェントを手動でインストールしてください |


---

# 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://help.aikido.dev/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-dev-containers.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.
