> 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-gitlab-ci.md).

# GitLab CI/CD での Device Protection

GitLab CI/CD ジョブは Linux ランナーで実行されるため、Device Protection は他の Linux マシンと同じ方法でインストールされます。GitLab 特有なのはインストール先です。常駐する shell executor のホストに 1 回だけ行うか、Docker および Kubernetes 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 および Kubernetes の executor

これは GitLab.com のホストされたランナーにも当てはまります。Device Protection トークンを、次の名前のマスクされた CI/CD 変数として追加してください `AIKIDO_TOKEN`、その後、エージェントを起動します `before_script`:

{% code title=".gitlab-ci.yml" overflow="wrap" %}

```yaml
default:
  before_script:
    - curl -fsSL https://github.com/AikidoSec/safe-chain/raw/refs/heads/main/install-scripts/install-endpoint-linux.sh | sh -s -- --container
    - aikido-endpoint-protection-start --wait-for-healthy
    - for f in /etc/profile.d/aikido-*.sh; do . "$f"; done

install:
  image: node:20-bookworm
  script:
    - npm ci
```

{% endcode %}

* **`before_script` はシェルを共有します `script`**、そのため読み込まれた設定がコマンドに反映されます。独自の `before_script` ものを使うジョブでは、デフォルトのものが置き換えられるため、そこでも 3 行を繰り返してください。
* **ジョブは root として実行する必要があり、イメージには `curl`.**

## Shell executor

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=".gitlab-ci.yml" overflow="wrap" %}

```yaml
verify-device-protection:
  image: node:20-bookworm
  script:
    - 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` は、ダウンロードがエージェントを回避したことを意味します。

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

| 問題                                                | 修正                                                      |
| ------------------------------------------------- | ------------------------------------------------------- |
| `トークンが必要です`                                       | ジョブはその変数を参照できません。保護された変数は保護されたブランチとタグにのみ届きます            |
| `root 権限が必要です`                                    | イメージは non-root ユーザーとして実行されます。root として実行されるイメージを使用してください |
| テストパッケージが返す `200`、または `SELF_SIGNED_CERT_IN_CHAIN` | ジョブが上書きします `before_script`。そこに 3 行を追加してください             |


---

# 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-gitlab-ci.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.
