【GitHub】GitHub Actions で Hadolint で Dockerfile をチェックする
【GitHub】GitHub Actions で Hadolint で Dockerfile をチェックする
GitHub Actions で Hadolint で Dockerfile をチェックする
Hadolint
Hadolint という Docker の lint ツールです。
Hadolint CIS ベンチマーク
Hadolintでチェックできるセキュリティ項目は以下のとおりです。 docker / docker-bench-security
- Create a user for the container(コンテナのユーザーを作成します) ✅
- Use trusted base images for containers(コンテナに信頼できるベースイメージを使用する) -
- Do not install unnecessary packages in the container(不要なパッケージをコンテナにインストールしないでください) -
- Scan and rebuild the images to include security patches(イメージをスキャンして再構築し、セキュリティパッチを含めます) -
- Enable Content trust for Docker (Dockerのコンテンツ信頼を有効にする) -
- Add HEALTHCHECK instruction to the container image(コンテナ画像にHEALTHCHECK命令を追加します) -
- Do not use update instructions alone in the Dockerfile(Dockerfileで更新手順を単独で使用しないでください) ✅
- Remove setuid and setgid permissions in the images(画像のsetuidおよびsetgid権限を削除します) -
- Use COPY instead of ADD in Dockerfile(DockerfileでADDの代わりにCOPYを使用する) ✅
- Do not store secrets in Dockerfiles(Dockerfilesにシークレットを保存しないでください) -
- Install verified packages only (検証済みパッケージのみをインストールします)-
GitHub Actions Dokle
name: Docker Check
on:push
jobs:
hadolint:
name: hadolint DockerFile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v2.0.0
with:
dockerfile: ./Dockerfile # チェックするDockerファイル
結果は以下のように出力されます。 内容がわからない時は以下を参照してみてください。 Rules
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