Skip to content

Commit 218f385

Browse files
authored
fix(ci): pin hadolint image by digest to stop drift off the rev pin (#1697)
The hadolint-docker pre-commit hook's upstream entry (ghcr.io/hadolint/hadolint hadolint) carries no image tag, so it floats to :latest regardless of the hadolint/hadolint repo's rev: v2.14.0 pin in .pre-commit-config.yaml, which only fixes the hook *definition*, not the Docker image it runs. Upstream publishing hadolint 2.15.1 as latest started failing pre-commit --all-files on every PR (new DL3066/DL3025 findings on unchanged Dockerfiles), since that job lints the whole merge ref rather than the PR's diff. Replace it with a local hook pinned to the immutable digest of the same v2.14.0 image so the linter version can only change via an explicit bump here. No Dockerfile changes were needed; verified Dockerfile, Dockerfile.dev, and Dockerfile.test all still build. Also corrects a stale comment in .github/workflows/pre-commit.yml that had assumed the old hook was already image-pinned via the rev. Closes #1696
1 parent cd4ee03 commit 218f385

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎.github/workflows/pre-commit.yml‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,17 @@ jobs:
182182
exit 1
183183
}
184184
185-
# Note: the hadolint-docker pre-commit hook
186-
# (.pre-commit-config.yaml:80) runs the official
187-
# hadolint/hadolint:v2.14.0 Docker image. We do NOT install a host
188-
# binary here — it would be dead code (never invoked by the hook)
189-
# AND a supply-chain hole (latest tag, no checksum). If a future
190-
# change switches the hook from hadolint-docker to plain hadolint,
191-
# install a pinned + sha256-verified binary here.
185+
# Note: the local `hadolint` pre-commit hook (.pre-commit-config.yaml:81)
186+
# runs ghcr.io/hadolint/hadolint pinned by digest to v2.14.0. We do NOT
187+
# install a host binary here — it would be dead code (never invoked by
188+
# the hook) AND a supply-chain hole (latest tag, no checksum). Note:
189+
# an earlier version of this comment claimed the hook already pinned
190+
# the image to v2.14.0 via the hook repo's `rev:` -- it did not; that
191+
# `rev:` only pins hadolint's *hook definition*, whose upstream entry
192+
# (`ghcr.io/hadolint/hadolint hadolint`) has no image tag and floats to
193+
# `:latest`. See the digest pin in .pre-commit-config.yaml for the fix.
194+
# If a future change switches the hook to a host binary, install a
195+
# pinned + sha256-verified binary here.
192196

193197
- name: Install pre-commit
194198
run: pip install 'pre-commit==4.0.1'

‎.pre-commit-config.yaml‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,26 @@ repos:
6363
name: Check for case conflicts
6464

6565
# Dockerfile linting
66-
- repo: https://github.com/hadolint/hadolint
67-
rev: v2.14.0
66+
#
67+
# The upstream hadolint-docker hook (hadolint/hadolint's own
68+
# .pre-commit-hooks.yaml) declares `entry: ghcr.io/hadolint/hadolint
69+
# hadolint` with no image tag, so Docker resolves it to `:latest` on every
70+
# run -- independent of the `rev:` pin above, which only pins which
71+
# commit of the *hook definition* is used, not the Docker image it runs.
72+
# When upstream published hadolint 2.15.1 as `latest`, CI silently
73+
# started linting with a newer ruleset (new DL3066/DL3025 findings on
74+
# unchanged Dockerfiles) with no corresponding change in this repo.
75+
#
76+
# Defined as a local hook instead, pinned to the immutable digest of the
77+
# v2.14.0 image, so the linter version can only change via an explicit
78+
# bump here.
79+
- repo: local
6880
hooks:
69-
- id: hadolint-docker
81+
- id: hadolint
7082
name: Lint Dockerfiles
83+
language: docker_image
84+
entry: ghcr.io/hadolint/hadolint:v2.14.0@sha256:27086352fd5e1907ea2b934eb1023f217c5ae087992eb59fde121dce9c9ff21e hadolint
85+
types: [dockerfile]
7186

7287
# Markdown linting
7388
- repo: https://github.com/igorshubovych/markdownlint-cli

0 commit comments

Comments
 (0)