Add digest pinning for Docker images #14071
Open
+187
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
Docker tags are mutable. If someone compromises a registry, they can swap out the image contents without changing the tag. Digests prevent this because they're content-addressed.
Right now, Dependabot only updates digests if you already have one:
But if you start with just a tag, you get just a tag back:
This PR adds an experiment flag (
docker_pin_digests) that makes Dependabot add digests to tag-only images. When enabled:Fixes #14065
Anything you want to highlight for special attention from reviewers?
The code already knows how to fetch digests.
UpdateChecker#digest_of(tag)does exactly this. The change is small:updated_requirementsnow callsdigest_of(updated_tag)whenpin_digests?returns true (not just when there's an existing digest)SharedFileUpdater#update_digest_and_tagappends@sha256:...when the old image had no digest but the new one doesI put it behind an experiment flag because it changes behavior for everyone using Docker.
How will you know you've accomplished your goal?
Added tests for:
UpdateChecker#updated_requirementsreturns a digest for tag-only images when the flag is onUpdateChecker#updated_requirementsreturns no digest when the flag is off (existing behavior)FileUpdatercorrectly appends@sha256:...to DockerfilesFileUpdatercorrectly appends@sha256:...to YAML files (Kubernetes, Helm)Checklist