Pin GitHub Action references to commit SHAs#445
Merged
Conversation
Comment on lines
+66
to
+88
| runs-on: ubuntu-latest | ||
| steps: | ||
|
|
||
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Check for versioned GitHub actions | ||
| if: always() | ||
| run: | | ||
| # Get changed GitHub workflow/action files | ||
| CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true) | ||
|
|
||
| if [ -n "$CHANGED_FILES" ]; then | ||
| # Check for any versioned actions, excluding comments and this validation script | ||
| VIOLATIONS=$(grep -Hn "uses:.*@v" $CHANGED_FILES | grep -v "grep.*uses:.*@v" | grep -v "#.*@v" || true) | ||
| if [ -n "$VIOLATIONS" ]; then | ||
| echo "Found versioned GitHub actions. Use commit SHAs instead:" | ||
| echo "$VIOLATIONS" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo "No versioned actions found in changed files" No newline at end of file |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 17 hours ago
- In general, the fix is to explicitly specify a
permissionsblock at the job or workflow level, restricting theGITHUB_TOKENto only what the job needs, typicallycontents: readfor read-only workflows. - For this workflow, the
static-code-checksjob only needs to check out code and rungit/greplocally. It does not push changes, create releases, or modify issues/PRs. So we should addpermissions: contents: readto that job. This mirrors the existing restriction already present on thebuildjob (lines 10–11). - Concretely, in
.github/workflows/pr-build.yml, underjobs: static-code-checks:, add apermissions:block at the same indentation level asruns-on. For example, between lines 65 and 66, insert:permissions: contents: read
- No extra imports or methods are required; this is purely a YAML configuration change within the workflow.
Suggested changeset
1
.github/workflows/pr-build.yml
| @@ -63,6 +63,8 @@ | ||
| path: jacoco/build/reports/jacoco/codeCoverageReport/html | ||
|
|
||
| static-code-checks: | ||
| permissions: | ||
| contents: read | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
|
Copilot is powered by AI and may make mistakes. Always verify output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Pin all GitHub Action references in workflow files to full-length commit SHAs to protect against supply-chain attacks (tag/branch mutation, upstream compromises). A static code check job was also added to
pr-build.ymlto verify pinned actions going forward.Changes
Static Code Check
A new
static-code-checkjob was added topr-build.ymlthat validates all GitHub Actionuses:references are pinned to full 40-character commit SHAs, preventing unpinned references from being merged.