> 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-buildkite.md).

# Buildkite での Device Protection

Buildkite のジョブは Linux 上で実行されるため、Device Protection のインストール方法も他の Linux マシンと同じです。Buildkite 固有なのは、インストール先です。常駐するエージェントホストに 1 回だけインストールするか、毎回のビルド後に破棄されるエージェント上の各ジョブ内でインストールします。

まず [Linux 用 Device Protection をインストールする](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md) まずトークンとパッケージについて、そして [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md) コンテナへのインストールでは、以下のジョブレベルのスニペットを使用します。

## 常駐するエージェント

他のビルドサーバーと同様に、ホストにエージェントをインストールすると、そのエージェントが実行するすべてのジョブが、パイプラインを一切変更することなく検査されます。使用して [Linux への展開](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux.md) Ansible、cloud-init、または自分で作成したイメージを使って、エージェント群全体に展開します。

## 毎回のビルド後に破棄されるエージェント

エフェメラル、コンテナ化、そして Buildkite ホスト型のエージェントには準備するホストがないため、エージェントをジョブ内にインストールし、何かがパッケージをインストールする前に起動してください：

{% code title=".buildkite/pipeline.yml" overflow="wrap" %}

```yaml
agents:
  queue: linux-small

steps:
  - label: ":shield: 依存関係をインストール"
    command: |
      export AIKIDO_TOKEN=$$(buildkite-agent secret get AIKIDO_TOKEN)

      curl -fsSLO https://github.com/AikidoSec/safechain-internals/releases/latest/download/EndpointProtection-amd64.deb
      AIKIDO_CONTAINER=1 AIKIDO_CI_CD=1 apt-get install -y --no-install-recommends ./EndpointProtection-amd64.deb

      aikido-endpoint-protection-start --wait-for-healthy
      for f in /etc/profile.d/aikido-*.sh; do . "$$f"; done

      npm ci
```

{% endcode %}

* **インストール前にトークンをエクスポートします。** パッケージは `AIKIDO_TOKEN` インストール中に。
* **インストール自体は標準的なコンテナインストールです。** モード変数、起動コマンド、そして source については [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md)と、arm64 および Red Hat 系エージェントで使用するパッケージについて。

インストールには root 権限が必要ですが、Docker ベースのエージェントはすでにそれを持っています。ジョブが `buildkite-agent` ユーザーとして実行される場合は、インストールの前に `sudo`.

{% hint style="info" %}
`buildkite-agent secret get` にはエージェント 3.106.0 以降が必要です。そのバージョンでは、 `$$` エスケープ処理を省略し、Buildkite に変数を設定させることもできます：

```yaml
steps:
  - command: .buildkite/install-deps.sh
    secrets:
      AIKIDO_TOKEN: aikido_token
```

{% endhint %}

### パイプラインを編集せずに、すべてのジョブで

ブロックを忘れたステップでは、パッケージが検査されずにインストールされます。次の場所へ移してください。 `pre-command` フックに、リポジトリ内の `.buildkite/hooks/pre-command` またはエージェントの hooks ディレクトリに：

{% code title=".buildkite/hooks/pre-command" overflow="wrap" %}

```bash
#!/bin/bash

export AIKIDO_TOKEN="$(buildkite-agent secret get AIKIDO_TOKEN)"

if ! command -v aikidoctl >/dev/null 2>&1; then
  curl -fsSLO https://github.com/AikidoSec/safechain-internals/releases/latest/download/EndpointProtection-amd64.deb
  AIKIDO_CONTAINER=1 AIKIDO_CI_CD=1 apt-get install -y --no-install-recommends ./EndpointProtection-amd64.deb
  rm -f EndpointProtection-amd64.deb
fi

aikido-endpoint-protection-start --wait-for-healthy

for f in /etc/profile.d/aikido-*.sh; do
  [ -e "$f" ] && . "$f"
完了
```

{% endcode %}

hooks は、パイプライン YAML ではなくディスク上のスクリプトなので、 `$` ここに書き、 `$$`Buildkite は hooks を source するため、フックが export した内容はコマンドに届きます。

## コンテナ内で実行されるジョブ

ステップが Docker または Docker Compose プラグイン経由で実行される場合は、ステップではなくイメージ内にエージェントをインストールしてください。参照： [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md).

{% code title=".buildkite/pipeline.yml" overflow="wrap" %}

```yaml
steps:
  - label: ":shield: 依存関係をインストール"
    command: |
      for f in /etc/profile.d/aikido-*.sh; do . "$$f"; done
      npm ci
    plugins:
      - docker#v5.14.0:
          image: "ghcr.io/your-org/my-app:latest"
          environment:
            - AIKIDO_TOKEN
```

{% endcode %}

このプラグインはイメージの `ENTRYPOINT`を保持するため、エージェントは自動的に起動します。プラグインの `entrypoint` または `command` オプションを設定すると、そのエントリポイントはなくなるため、 `aikido-endpoint-protection-start --wait-for-healthy` コマンドの先頭でこれを実行してください。Kubernetes スタックはコンテナの command を置き換えるため、同じ対応が必要です。

## 動作確認

Aikido がブロックするパッケージをダウンロードするステップを追加してください：

{% code title=".buildkite/pipeline.yml" overflow="wrap" %}

```yaml
steps:
  - label: ":shield: Device Protection を確認"
    command: |
      aikidoctl バージョン
      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
```

{% endcode %}

エージェントがすでに動作しているステップで実行してください。 `curl` を出力します `403`、エージェントがマルウェア検査用パッケージを拒否し、エージェントがあなたの [デバイス一覧](https://app.aikido.dev/endpoint-protection/devices)。さらに確認するには、 [Device Protection が機能しているか確認する方法](/docs/docs-ja/aikido-device-protection/miscellaneous-aikido-endpoint/how-to-test-device-protection.md).

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

| 問題                                                | 修正                                                                                                                                               |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| トークンが空で、エージェントが一度も登録されません                         | 次の `$` はエスケープされていなかったため、Buildkite は `$(buildkite-agent secret get ...)` をアップロード時に解決しました。使用するには `$$` パイプライン YAML 内では 1 つの `$` フックスクリプト内では 1 つの    |
| `buildkite-agent: コマンドが見つかりません`、またはシークレットを読み取れません | エージェントが 3.106.0 より古い、シークレットが別のクラスターにある、またはジョブがエージェントバイナリのないコンテナで実行されている可能性があります。 `mount-buildkite-agent` を Docker プラグインで有効にしてください                |
| ジョブ内のダウンロードはまったく検査されません                           | このプラグインの `entrypoint` または `command` オプションがイメージのエントリポイントを置き換えたため、エージェントは起動しませんでした。 `aikido-endpoint-protection-start --wait-for-healthy` コマンドの最初に |

Buildkite 固有ではないもの、たとえば `npm` または `uv`による証明書エラーなどについては、トラブルシューティング表を参照してください。 [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md#troubleshooting).


---

# 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-buildkite.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.
