Repository navigation
Pin GitHub Actions to full-length commit SHAs - #998
Johannes Schindelin (dscho) merged 4 commits into
Conversation
This commit performs a one-time pinning, something that downstream repositories need to maintain from that point on. Such maintenance comes at a high cost when the workflows in question are not actually under the downstream repositories' control, but are inherited from an upstream project, such as (fast-moving) git/git. The intention of this patch is to increase security, which to a certain extent might even be accomplished here, under the assumption that the current SHA-1s refer to non-vulnerable versions. The commit message is a bit secretive about whatever analysis went into that, if any, so we cannot know. While this patch _might? increase security, it also increases the maintenance burden in a non-negligible way, though. For example, it forgot to pin the GitHub Action maintained in the VFS for Git repository to run the VFS for Git Functional Tests, and it pinned the CodeQL Actions to an already-outdated version. Let's drop this patch, for that reason, in preparation for integrating a much more sustainable way to pin the Actions' SHA-1s (ignoring the question whether pinning Actions to SHA-1s actually increases security, or merely shifts blame). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Microsoft Git inherits GitHub workflows from upstreams that use non-pinned versions for convenience. For compliance reasons, Microsoft Git must pin those to SHA-1s. Here is a script that exchanges the moving tags/refs in the `uses:` statements with their fixed SHA-1s. Assisted-by: GPT-6.1 Sol Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Microsoft Git inherits workflows that upstream maintains using symbolic Action refs. Downstream organizational policy requires full commit IDs instead, adding pin maintenance to this project's maintainers' workload. Keep pins aligned with the original upstream Action refs in a fresh downstream snapshot, independent of any earlier pinning commit. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Matthew John Cheetham (mjcheetham)
left a comment
There was a problem hiding this comment.
I appreciate the rework Johannes Schindelin (@dscho) has done to make this a script and therefore a reusable tool to prevent the maintenance burden.
Note that this pinning does not actually guarantee that out dependencies are safe here.
| }).trim(); | ||
| } | ||
|
|
||
| const isSHA = value => /^[0-9a-f]{40}$/i.test(value); |
There was a problem hiding this comment.
Can't wait for SHA-256 🫣
There was a problem hiding this comment.
Well, SHA-256 should make the pinning more secure, anyway: A dedicated attacker with $10k to spare could feasibly create a SHA-1 collision for a slow-moving Action, which means that SHA-1 pinning is most likely providing more of a false than of a true sense of security.
| } | ||
|
|
||
| const isSHA = value => /^[0-9a-f]{40}$/i.test(value); | ||
| const uses = /^( *-? *uses: *)(["']?)([\w./-]+)@([^ \t"'\r\n]+)\2([^\r\n]*)/gm; |
There was a problem hiding this comment.
Local actions get skipped since they don't have an @ (e.g., ./myaction, which I guess is OK here since we only care about unpinned actions, but a local action is already pinned to the current workflow file/repo ref.
There was a problem hiding this comment.
Precisely, they are implicitly pinned to the current revision (i.e. safer than any pinned SHA-1).
e82b652
into
microsoft:vfs-2.55.0
Summary
This PR pins GitHub Actions to full-length commit SHAs for improved security and reproducibility and adds a 7 day cooldown to Dependabot configuration for GitHub Actions. This work is described in more detail at https://aka.ms/action-pinning.
Why?
Pinning actions to commit SHAs prevents supply-chain attacks where a tag could be moved to point to malicious code. This is a recommended security best practice per the GitHub Actions security hardening guide.
This change mitigates the risk of tag retargeting to malicious code as seen in incidents like the tj-actions/changed-files action compromise or codfish/semantic-release-action compromise and improves the integrity and reproducibility of the CI/CD pipeline.
What changed?
Action pinning: Third-party action references in
.github/workflows/that used mutable tag-based references (e.g.,actions/checkout@v4) have been updated to full-length commit SHAs with a version comment (e.g.,actions/checkout@<sha> # v4) using the pinact tool. References that were already pinned to a SHA, or that used immutable release tags, were left unchanged.Dependabot configuration:
.github/dependabot.ymlhas been updated to ensure agithub-actionspackage-ecosystem section is present with acooldownconfiguration (default-days: 7). If the file did not exist, it was created. If agithub-actionssection already existed, only thecooldownblock was added or itsdefault-daysvalue was increased to 7 if it was lower. The 7-day cooldown provides a window for the community to detect and report compromised releases before they are automatically proposed as updates, reducing exposure to supply-chain attacks via newly published malicious versions.Is this safe to merge?
Yes. The pinned SHAs correspond to the same commits that the existing tags pointed to. No behavioral changes in action execution are introduced. You can verify the pinned SHA value using the GitHub REST API (e.g., the commit hash for
actions/checkout@v7can be found in theshaproperty in the JSON response forGET https://api.github.com/repos/actions/checkout/commits/v7).Additional Information
For more information, please see https://aka.ms/action-pinning