Add opt-in github_actions_pin_to_sha option for GitHub Actions#14516
Add opt-in github_actions_pin_to_sha option for GitHub Actions#14516IanButterworth wants to merge 4 commits intodependabot:mainfrom
github_actions_pin_to_sha option for GitHub Actions#14516Conversation
When enabled, the UpdateChecker returns commit SHAs instead of version tags for pinned version references. The FileUpdater adds a version comment (e.g. # v2.2.0) when transitioning from a tag to a SHA pin. Closes dependabot#7913 Co-authored-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an opt-in github_actions_pin_to_sha option to the GitHub Actions ecosystem so Dependabot can prefer updating uses: refs to full commit SHAs (including for security fixes), and adds workflow-file comments indicating the corresponding version when transitioning from tag → SHA.
Changes:
- UpdateChecker: when the option is enabled, choose
commit_shainstead of the tag for version/security-fix updates. - FileUpdater: when converting a version tag ref to a SHA ref, append a
# vX.Y.Zcomment (when safe to do so). - Specs/fixtures: add coverage and a new workflow fixture for tag → SHA transitions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| github_actions/lib/dependabot/github_actions/update_checker.rb | Adds pin_to_sha? and switches updated refs to SHA when enabled. |
| github_actions/lib/dependabot/github_actions/file_updater.rb | Appends a version comment when transitioning from tag → SHA. |
| github_actions/spec/dependabot/github_actions/update_checker_spec.rb | Adds tests ensuring refs become SHAs under the new option (including security fixes). |
| github_actions/spec/dependabot/github_actions/file_updater_spec.rb | Adds tests for tag → SHA replacement and comment behavior (including quoted declarations). |
| github_actions/spec/fixtures/workflow_files/pin_to_sha.yml | New fixture workflow used by FileUpdater specs. |
ef5aada to
3f8a686
Compare
|
This doesn't currently update Update: Now it does. |
When pin_to_sha is enabled, bypass precision filtering so floating tags resolve to the latest version's SHA instead of only matching same-precision tags. Adds tests for major-only and major-minor floating tag scenarios in both UpdateChecker and FileUpdater.
710da3b to
21b91d2
Compare
|
👍 This has been made even more important since the recent Trivy GitHub Actions security incidents12 where part of the GitHub Actions attack involved tags being overridden by a malicious actor. Pinning the GitHub actions to a SHA would have helped prevent downstream repo credential exfiltration vectors. Immutable Releases + SHA pinning is the recommended remediation approach going forward. Therefore, Footnotes
|
|
Thank you @IanButterworth <3 |
Pinning GitHub Actions to SHA is fast becoming more than just best practice, so have Dependabot help.
Closes #7913
Developed with Claude:
What are you trying to accomplish?
Add an opt-in
github_actions_pin_to_shaoption that tells Dependabot to prefer full commit SHAs over version tags when updating GitHub Actions references. This aligns with GitHub's own security hardening guidance which recommends pinning actions to a full length commit SHA.When the option is enabled:
actions/checkout@v2.1.0becomesactions/checkout@aabbfeb2ce60b5bd82389903509092c4648a9713 # v2.2.0The option is read from the existing options (experiments) mechanism in dependabot-core. Enabling it for end users will require the Dependabot service to surface it in the dependabot.yml configuration.
Anything you want to highlight for special attention from reviewers?
UpdateChecker (update_checker.rb):
updated_refnow checkspin_to_sha?and returnsnew_tag.fetch(:commit_sha)instead ofnew_tag.fetch(:tag)when the option is set. This applies to both normal version updates and security fix updates.FileUpdater (file_updater.rb): New
new_version_commentmethod generates a# vX.Y.Zcomment when transitioning from a version tag ref to a SHA ref. This only fires when the old ref is a valid version and the new ref is a commit SHA — it won't add comments in other scenarios.The existing
updated_version_commentpath (SHA→SHA with existing comment) is unchanged.How will you know you've accomplished your goal?
update_checker_spec.rbverify that tag references, full version tags, already-pinned SHAs, and vulnerable tag references all return commit SHAs when the option is enabled.file_updater_spec.rbverify that tag→SHA transitions add version comments for bare, double-quoted, and single-quoted declarations, and don't produce duplicate comments.Checklist