Harden GitHub Actions Security
Intermediatev1.0.0
Secure your GitHub Actions workflows against supply chain attacks — pin actions to SHA, configure least-privilege permissions, protect secrets, and enable OpenID Connect.
Content
Overview
GitHub Actions workflows execute arbitrary code with access to your repository secrets and GITHUB_TOKEN. Without proper hardening, they are a major supply chain attack vector. This guide covers the essential security controls.
Why This Matters
- -Supply chain attacks — compromised Actions can steal secrets
- -Token theft — overly permissive GITHUB_TOKEN enables repo takeover
- -Secret exfiltration — malicious PRs can access workflow secrets
- -Compliance — SOC2/ISO require CI/CD security controls
How It Works
Step 1: Pin Actions to SHA
Step 2: Apply Least-Privilege Permissions
Step 3: Use OIDC Instead of Long-Lived Secrets
Step 4: Protect Against PR-Based Attacks
Step 5: Audit with StepSecurity
Best Practices
- -Pin ALL third-party actions to SHA (use Dependabot to update)
- -Set
permissions: contents: readat workflow level, expand per-job - -Use OIDC for cloud provider authentication (AWS, GCP, Azure)
- -Never use
pull_request_targetwith PR code checkout - -Enable GitHub's "Require approval for all outside collaborators" setting
- -Audit Actions marketplace dependencies before adopting
Common Mistakes
- -Using tag-based action references (vulnerable to tag reassignment)
- -Granting
write-allpermissions (violates least privilege) - -Storing long-lived cloud credentials as repository secrets
- -Using
pull_request_targetwithout understanding the security model - -Not restricting which Actions can run (org-level policy)
FAQ
Discussion
Loading comments...