Skip to content

Guardrails / docker

Dockerfile base images are pinned ​

docker/base-pinned@v1

Every image a Dockerfile builds from is pinned to a digest, so rebuilding the same commit starts from the same bytes.

Iddocker/base-pinned
Versionv1
Categorydocker
Default severityerror
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsdocker

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

CollectorGathersInputs it is given
dockerEvery Dockerfile in the tree, parsed without a tool: the stages it builds, the image each one starts from and how that image is pinned, the user the image ends as, the ports it exposes, the paths it copies in and the names of the build arguments and environment variables it declares, plus the findings of a hadolint report when the build already left one behind.none

The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "docker/base-pinned@v1",
              "severity": "error",
              "with": {
                  "allowTags": "false",
                  "registries": ""
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
allowTagsWhether a tag other than latest counts as a pin. false requires a digest, the only kind of reference that resolves to the same image every time.falseGUARDRAIL_INPUT_ALLOWTAGS
registriesComma separated registries an image may come from, such as docker.io,ghcr.io. Empty means any registry. An image naming no registry comes from Docker Hub, so name docker.io to allow those.``GUARDRAIL_INPUT_REGISTRIES

How to fix ​

Pin the image to the digest its tag points to today, so the base can't change between rebuilds:

dockerfile
FROM node:20.11.1-alpine@sha256:e4b0d6d6b1a2c2a58e8dd8a0e0b1f0d0c2c9f9c5b3a1e0d9c8b7a6f5e4d3c2b1 AS build

Run docker buildx imagetools inspect node:20.11.1-alpine to print the digest to paste in. Renovate and Dependabot both raise pull requests to update a pinned digest, so the pin stays maintained instead of frozen.

A tag moves whenever the publisher pushes. Two builds of the same commit then produce different images, and the one an auditor asks about is not the one that ran.

More in docker ​

  • docker/healthcheck. Every Dockerfile declares a HEALTHCHECK, so the orchestrator can tell a container that is running from one that is actually working.
  • docker/lint-clean. Every finding the Dockerfile linter reported is below the severity your team gates on.
  • docker/no-build-secrets. No ARG or ENV declared in a Dockerfile has a name that looks like a credential.
  • docker/nonroot-user. Every Dockerfile ends with a USER that is not root, so the container runs its process without privileges.

All 5 docker guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412