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

# CircleCI での Device Protection

CircleCI のジョブは Linux 実行環境上で実行されるため、Device Protection はどの Linux マシンでも同じようにインストールされます。CircleCI 特有なのは、インストール先です。常駐する self-hosted runner に 1 回だけ入れるか、Docker および machine の各 executor 内で入れるかです。

まず [Linux 用 Device Protection をインストールする](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md) トークンとインストール方式についてお読みください。以下のジョブレベルのスニペットでは container 方式を使用しており、これは [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md) を説明しています。

## Docker および machine の executor

Device Protection トークンを、プロジェクトの環境変数として、またはコンテキストに、名前 `AIKIDO_TOKEN`で追加します。次に、再利用可能なコマンドを定義し、各ジョブで最初に実行します:

{% code title=".circleci/config.yml" overflow="wrap" %}

```yaml
version: 2.1

commands:
  start-device-protection:
    steps:
      - run:
          name: Device Protection を開始
          command: |
            curl -fsSL https://github.com/AikidoSec/safe-chain/raw/refs/heads/main/install-scripts/install-endpoint-linux.sh \
              | sudo AIKIDO_TOKEN="$AIKIDO_TOKEN" sh -s -- --container
            sudo aikido-endpoint-protection-start --wait-for-healthy
            echo 'for f in /etc/profile.d/aikido-*.sh; do . "$f"; done' >> "$BASH_ENV"

jobs:
  build:
    docker:
      - image: cimg/node:lts
    steps:
      - checkout
      - start-device-protection
      - run: npm ci

workflows:
  build:
    jobs:
      - build
```

{% endcode %}

* **トークンはの後に渡します `sudo`.** `sudo` は環境変数の残りを削除します。root として実行され、 `sudo`がないイメージでは、両方の `sudo` プレフィックスを外します。
* **次の `$BASH_ENV` の行は、その後のすべてのステップをカバーします。** CircleCI は各 `run` ステップの開始時にそのファイルを読み込みます。
* **runner は VM ですが、 `--container`.** ジョブから runner を再起動することはできず、container モードでは再起動も不要です。そのため、エージェントは明示的に起動します。参照: [インストール方式を選択](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md#choose-the-install-flavor).

## self-hosted runner

runner ホストにエージェントを `--headless`付きでインストールし、その後再起動します。参照: [Linux 用 Device Protection をインストールする](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md#choose-the-install-flavor).

## 動作確認

{% code title=".circleci/config.yml" overflow="wrap" %}

```yaml
      - run:
          name: Device Protection を検証
          command: 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 %}

`403` は、エージェントがマルウェアのテスト用パッケージをブロックしたことを意味します。 `200` は、ダウンロードがエージェントを回避したことを意味します。

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

| 問題                                                | 修正                                                                                       |
| ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| `トークンが必要です`                                       | ジョブはその変数を参照できません。ジョブが正しいコンテキストを使用しているか確認してください。fork からの pull request には既定では変数が渡されません     |
| `root 権限が必要です`                                    | インストールと開始コマンドの前に `sudo`                                                                  |
| テストパッケージが返す `200`、または `SELF_SIGNED_CERT_IN_CHAIN` | そのステップは bash で実行されないため、 `$BASH_ENV`をスキップします。 `/etc/profile.d/aikido-*.sh` をそのステップで読み込みます |


---

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