JavaScriptを有効にしてください

【Github】Github Actions で Dockle で Docker Image をチェックする

 ·  ☕ 2 分で読めます

【Github】Github Actions で Dockle で Docker Image をチェックする

Github Actions で Dockle で Docker Image をチェックする

Dockle

Dockle は Docker のコンテナイメージのセキュリティチェックツールです。

Dockle CIS ベンチマーク

Dockleでチェックできるセキュリティ項目は以下のとおりです。
docker / docker-bench-security

  1. Create a user for the container(コンテナのユーザーを作成します) ✅
  2. Use trusted base images for containers(コンテナに信頼できるベースイメージを使用する) -
  3. Do not install unnecessary packages in the container(不要なパッケージをコンテナにインストールしないでください) -
  4. Scan and rebuild the images to include security patches(イメージをスキャンして再構築し、セキュリティパッチを含めます) -
  5. Enable Content trust for Docker (Dockerのコンテンツ信頼を有効にする) ✅
  6. Add HEALTHCHECK instruction to the container image(コンテナ画像にHEALTHCHECK命令を追加します) ✅
  7. Do not use update instructions alone in the Dockerfile(Dockerfileで更新手順を単独で使用しないでください) ✅
  8. Remove setuid and setgid permissions in the images(画像のsetuidおよびsetgid権限を削除します) ✅
  9. Use COPY instead of ADD in Dockerfile(DockerfileでADDの代わりにCOPYを使用する) ✅
  10. Do not store secrets in Dockerfiles(Dockerfilesにシークレットを保存しないでください) ✅
  11. Install verified packages only (検証済みパッケージのみをインストールします)-

Github Actions Dokle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
name: Docker Check

on:push

jobs:
  dockle:
    name: Dockle Container Analysis
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Run Dockle
        uses: erzz/dockle-action@v1
        with:
          image: php:8.1.6-fpm-bullseye # チェックするイメージ名

結果は以下のように出力されます。
内容がわからない時は以下を参照してみてください。
Checkpoint Summary

1
2
3
4
Error: .//Dockerfile:5 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
Error: .//Dockerfile:5 DL3015 info: Avoid additional packages by specifying `--no-install-recommends`
Error: .//Dockerfile:18 SC2046 warning: Quote this to prevent word splitting.
Error: .//Dockerfile:28 DL4006 warning: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

参考

共有

こぴぺたん
著者
こぴぺたん
Copy & Paste Engineer