> 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/kontenaimjisukyan/local-image-scanning/pr-gating-for-container-images-using-local-image-scanner.md).

# ローカルイメージスキャナーを使用したコンテナーイメージのPRゲーティング

Aikido Local Scanner を使用すると、CI パイプラインでセキュリティゲートを強制できます。

PR ゲーティングにより、新しいコードがデフォルトブランチにマージされる前にセキュリティ基準を満たしていることを確認できます。スキャン対象はプルリクエストで追加された変更のみです。スキャンで、設定した重大度しきい値以上の新しい問題が検出されると、CI パイプラインは失敗します。

これにより、新たな脆弱性の混入を防ぎつつ、既存の検出項目は個別に対処できます。

{% hint style="info" %}
また、次もサポートしています [release gating](/docs/docs-ja/kontenaimjisukyan/local-image-scanning/release-gating-for-container-images-using-local-image-scanner.md) リリース時にチェックを強制したいチーム向けです。
{% endhint %}

PR ゲーティングを有効にするには、次を追加します `--fail-on <severity>` オプションで希望する重大度レベルを選択します。次に、次を追加します `--gating-mode pr` オプションで PR ゲーティングを行うことを指定します。さらに、ベース（`--base-commit-id <commit-id>`）とヘッドコミット（`--head-commit-id <commit-id>`）。 以前にベースコミット ID に対してスキャンが実行されている場合、スキャン結果はそれと比較されます。そうでない場合、結果はイメージの最新のスキャンと比較されます。

PRゲーティングの例コマンド:

```
./aikido-local-scanner image-scan your-image-name --apikey AIK_CI_xxx --fail-on critical --gating-mode pr --base-commit-id abc123 --head-commit-id def456 
```

### 例 <a href="#examples" id="examples"></a>

#### GitHub <a href="#github" id="github"></a>

GitHub環境での Local Scanner の設定に関する一般情報については、こちらをご覧ください [この記事](https://help.aikido.dev/code-scanning/local-code-scanning/github-action-setup-for-local-code-scanning).

例 `.github/workflows/aikido-scan.yml` PRゲーティング用:

```yaml
name: Aikido Docker のビルドとスキャン

on:
  pull_request:
    branches:
      - main

jobs:
  build-and-scan:
    runs-on: ubuntu-latest
    steps:
      - name: コードをチェックアウト
        uses: actions/checkout@v4

      - name: Docker Buildx をセットアップ
        uses: docker/setup-buildx-action@v3

      - name: Docker イメージをビルド
        run: docker build -t your-local-image-name .

      - name: Aikido イメージスキャンを実行
        run: |
          docker run --rm \
            -v /var/run/docker.sock:/var/run/docker.sock \
            aikidosecurity/local-scanner \
            image-scan your-local-image-name \
            --apikey ${{ secrets.AIKIDO_API_KEY }} \
            --fail-on critical \
            --gating-mode pr \
            --base-commit-id ${{ github.event.pull_request.base.sha }} \
            --head-commit-id ${{ github.event.pull_request.head.sha }} 
```

#### Azure DevOps Server <a href="#azure-devops-server" id="azure-devops-server"></a>

Azure DevOps 環境で Local Scanner を設定する一般的な情報については、こちらをご覧ください [この記事](https://help.aikido.dev/container-image-scanning/local-image-scanning/azure-devops-server-setup-for-local-image-scanning).

PRゲーティングの例:

```yaml
trigger: none

pr:
  branches:
    include:
      - 'main'

pool:
  vmImage: ubuntu-latest

steps:
- script: docker build -t my-image .
  displayName: 'Docker イメージをビルド'  
- script: | 
    docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aikidosecurity/local-scanner image-scan my-image \
        --apikey $(AIKIDO_API_KEY) \
        --fail-on critical \
        --gating-mode pr \
        --base-commit-id abc123 \
        --head-commit-id def456
  displayName: 'Aikido スキャンを実行'
```

このパイプラインを main ブランチの Build Validation として追加してください:

1. Project Settings → Repositories → Policies → Branch Policies に移動します
2. main ブランチを選択します
3. Build Validation を追加
4. このパイプラインを選択
5. 設定:
   * トリガー: 自動


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.aikido.dev/docs/docs-ja/kontenaimjisukyan/local-image-scanning/pr-gating-for-container-images-using-local-image-scanner.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
