-
Notifications
You must be signed in to change notification settings - Fork 2
Automate GitHub Actions pinning to full-length commit SHAs for improved security #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…umentation Co-authored-by: sonnyquinn24 <[email protected]>
Co-authored-by: sonnyquinn24 <[email protected]>
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
sonnyquinn24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Implements comprehensive automation to pin GitHub Actions to full-length commit SHAs instead of version tags, significantly improving supply chain security by preventing potential malicious code injection through updated action versions.
What This PR Does
This PR adds a complete automation solution that:
.github/workflows/to identify unpinned GitHub Actions (e.g.,actions/checkout@v3)Security Impact
Before:
After:
This change prevents supply chain attacks where malicious actors could compromise action repositories and inject harmful code into new releases while maintaining the same version tag.
Implementation Details
Core Script:
scripts/pin-github-actions.js.ymland.yamlworkflow filesUsage Examples
Comprehensive Testing
Added
test/pin-github-actions.test.jswith 7 test cases covering:Documentation Updates
Updated README.md with:
Edge Cases Handled
✅ Already pinned actions - Skipped automatically
✅ Non-existent repositories - Graceful error handling
✅ Version tag resolution - Handles
v3,v3.8.1,main, etc.✅ YAML validation - Ensures workflows remain valid
✅ Multiple workflow files - Processes entire
.github/workflows/directoryReal-World Application
This automation successfully processed the existing
ci-cd.ymlworkflow, pinning 6 action references:actions/checkout@v3→actions/checkout@f43a0e5ff2bd294...actions/setup-node@v3→actions/setup-node@3235b876344d2a9a...Running the script again correctly detects that all actions are already pinned and makes no changes, demonstrating the idempotent behavior.
Dependencies Added
js-yaml@^4.1.0- For safe YAML parsing and serialization@octokit/rest@^20.0.2- For GitHub API integrationThis automation can be integrated into CI/CD pipelines to automatically maintain security best practices for GitHub Actions across all workflow files.
This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.