|
| 1 | +# How to Pin GitHub Actions to a Specific Commit Hash |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +When creating or updating GitHub workflows in the Hiero Python SDK, **all GitHub Actions must be pinned to a specific commit hash** rather than using floating tags. |
| 6 | + |
| 7 | +This document explains **why pinning is required**, **how to find the correct commit hash**, and **best practices** for maintaining pinned GitHub Actions. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Why Pin GitHub Actions? |
| 12 | + |
| 13 | +GitHub Actions can be referenced in multiple ways: |
| 14 | + |
| 15 | +```yaml |
| 16 | +uses: owner/action@v1 # ❌ floating tag |
| 17 | +uses: owner/action@v4 # ⚠️ major version tag |
| 18 | +uses: owner/action@<commit> # ✅ pinned commit SHA (v2.14.0) |
| 19 | +``` |
| 20 | +
|
| 21 | +### Security and supply-chain risk |
| 22 | +
|
| 23 | +GitHub Actions referenced using tags such as `latest`, `v1`, or `v4` are **mutable** and can be updated to point to a different commit at any time. This means the code executed by a workflow can change without any modification to the workflow file itself. |
| 24 | + |
| 25 | +If an action repository is compromised or a malicious change is introduced upstream, workflows that rely on floating tags may unknowingly execute untrusted code. This represents a significant **software supply-chain risk**. |
| 26 | + |
| 27 | +By pinning a GitHub Action to a specific commit SHA, the exact code being executed is known and cannot change unexpectedly. This makes workflows more secure, auditable, and resistant to supply-chain attacks. |
| 28 | + |
| 29 | +For this reason, many security tools (for example, StepSecurity) require GitHub Actions to be pinned to commit SHAs. |
| 30 | + |
| 31 | +### Reproducibility and stability |
| 32 | + |
| 33 | +Pinning GitHub Actions to a specific commit SHA ensures workflows are fully reproducible. The same workflow will always execute the same version of an action, regardless of new releases or tag updates made upstream. |
| 34 | + |
| 35 | +This prevents unexpected behavior changes caused by automatic updates to floating tags and makes CI runs more predictable. |
| 36 | + |
| 37 | +Reproducible workflows are easier to debug, audit, and maintain, since any failures can be traced back to a known and immutable version of the action. |
| 38 | + |
| 39 | +## Step-by-step: How to find the correct commit SHA |
| 40 | + |
| 41 | +### Step 1: Open the action’s GitHub repository |
| 42 | + |
| 43 | +Start with the official GitHub repository for the action. Prefer repositories linked from the GitHub Marketplace and ensure the project is actively maintained. |
| 44 | + |
| 45 | +Examples: |
| 46 | +- actions/checkout |
| 47 | +- step-security/harden-runner |
| 48 | + |
| 49 | +### Step 2: Go to the Releases page |
| 50 | + |
| 51 | +In the repository, navigate to **Releases** and open the **Latest** release. |
| 52 | + |
| 53 | +### Step 3: Open the release tag |
| 54 | + |
| 55 | +Click the release version (for example `v2.14.0`) to open the release details page. |
| 56 | + |
| 57 | +### Step 4: Copy the commit SHA |
| 58 | + |
| 59 | +From the release page, open the commit associated with the release and copy the full 40-character commit SHA. |
| 60 | + |
| 61 | +Example SHA: 20cf305ff2072d973412fa9b1e3a4f227bda3c76 |
| 62 | + |
| 63 | +### Step 5: Update the workflow |
| 64 | + |
| 65 | +Replace any floating or version-based reference: |
| 66 | + |
| 67 | +```yaml |
| 68 | +uses: step-security/harden-runner@v2 |
| 69 | +uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 70 | +``` |
| 71 | + |
| 72 | +## Best practices |
| 73 | + |
| 74 | +- Always pin GitHub Actions to a full commit SHA |
| 75 | +- Avoid floating tags such as `latest`, `v1`, or `v4` |
| 76 | +- Keep a version comment (for example `# v2.14.0`) |
| 77 | +- Review release notes before updating pinned SHAs |
| 78 | +- Periodically update pinned actions to include security fixes |
| 79 | +- Avoid deprecated or archived action repositories |
0 commit comments