Local Image Scannerによるコンテナイメージ用PR Gating
Aikido Local Scannerを使用すると、CIパイプラインにセキュリティゲートを設定できます。
PR gatingは、新しいコードがデフォルトブランチにマージされる前に、セキュリティ基準を満たしていることを保証します。プルリクエストで導入された変更のみをスキャンします。スキャンで設定した深刻度のしきい値以上の新しいissueが検出された場合、CIパイプラインは失敗します。
これにより、既存の検出結果は別途対処しつつ、新たな脆弱性の混入を防ぐことができます。
PR gatingを有効にするには、--fail-on <severity> オプションを追加して希望する深刻度レベルを選択します。次に、--gating-mode pr オプションを追加してPR gatingを実行することを指定します。base commit(--base-commit-id <commit-id>)とhead commit(--head-commit-id <commit-id>)も指定する必要があります。base commit IDに対して過去にスキャンが実行されていた場合、そのスキャン結果と比較されます。そうでない場合は、そのイメージの直近のスキャン結果と比較されます。
PR gatingコマンドの例:
./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 def456Examples
Section titled “Examples ”GitHub
Section titled “GitHub ”GitHub環境でのLocal Scannerのセットアップに関する一般的な情報は、こちらの記事をご覧ください。
PR gating用の.github/workflows/aikido-scan.ymlの例:
name: Aikido Docker build and scan
on: pull_request: branches: - main
jobs: build-and-scan: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Build Docker image run: docker build -t your-local-image-name .
- name: Run Aikido image scan 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
Section titled “Azure DevOps Server ”Azure DevOps環境でのLocal Scannerのセットアップに関する一般的な情報は、こちらの記事をご覧ください。
PR gatingの例:
trigger: none
pr: branches: include: - 'main'
pool: vmImage: ubuntu-latest
steps:- script: docker build -t my-image . displayName: 'Build docker image'- 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: 'Run Aikido scan'このパイプラインをmainブランチのBuild Validationとして必ず追加してください。
- Project Settings → Repositories → Policies → Branch Policies に移動します
- mainブランチを選択します
- Build Validationを追加します
- このパイプラインを選択します
- 以下を設定します:
- Trigger: Automatic