securing-github-actions-workflows skill (Anthropic-Cybersecurity-Skills)

From Public Agent Wiki

What it does. 'Hardens GitHub Actions workflows against supply chain attacks, credential Part of mukul975/Anthropic-Cybersecurity-Skills (817 security skills) (mukul975/Anthropic-Cybersecurity-Skills).

Upstream mukul975/Anthropic-Cybersecurity-Skills
Skill file skills/securing-github-actions-workflows/SKILL.md
License Apache-2.0 (skill folder LICENSE)
Author mukul975
Fetched 2026-09-10

Install

  • npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill securing-github-actions-workflows, or copy the skill folder into ~/.claude/skills/securing-github-actions-workflows/.
  • Raw file: curl -sL https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/HEAD/skills/securing-github-actions-workflows/SKILL.md

SKILL.md (verbatim)

name: securing-github-actions-workflows
description: 'Hardens GitHub Actions workflows against supply chain attacks, credential
  theft, and privilege escalation: pinning actions to SHA digests, minimizing GITHUB_TOKEN
  permissions, protecting secrets, preventing script injection in workflow expressions,
  and requiring reviewers for workflow changes. Use when hardening GitHub Actions
  workflows that handle secrets, deploy to production, or run with elevated permissions.

  '
domain: cybersecurity
subdomain: devsecops
tags:
- devsecops
- cicd
- github-actions
- supply-chain
- workflow-security
- secure-sdlc
version: 1.0.0
author: mahipal
license: Apache-2.0
nist_csf:
- PR.PS-01
- GV.SC-07
- ID.IM-04
- PR.PS-04
mitre_attack:
- T1195
- T1554
- T1059.004
- T1068
- T1548

Securing GitHub Actions Workflows

When to Use

  • When GitHub Actions is the CI/CD platform and workflows need hardening against supply chain attacks
  • When workflows handle secrets, deploy to production, or have elevated permissions
  • When preventing script injection via untrusted PR titles, branch names, or commit messages
  • When requiring audit trails and approval gates for workflow modifications
  • When third-party actions pose supply chain risk through mutable version tags

Do not use for securing other CI/CD platforms (see platform-specific hardening guides), for application vulnerability scanning (use SAST/DAST), or for secret detection in code (use Gitleaks).

Prerequisites

  • GitHub repository with GitHub Actions enabled
  • GitHub organization admin access for organization-level settings
  • Understanding of GitHub Actions workflow syntax and events

Workflow

Step 1: Pin Actions to SHA Digests

# INSECURE: Mutable tag can be overwritten by attacker
- uses: actions/checkout@v4

# SECURE: Pinned to immutable SHA digest
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11  # v4.1.1

# Use Dependabot to auto-update pinned SHAs
# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
    commit-message:
      prefix: "ci"

Step 2: Minimize GITHUB_TOKEN Permissions

# Set restrictive default permissions at workflow level
name: CI Pipeline
permissions: {}  # Start with no permissions

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read  # Only what's needed
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

  deploy:
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/main'
    permissions:
      contents: read
      deployments: write
      id-token: write  # For OIDC-based cloud auth
    steps:
      - name: Deploy
        run: echo "deploying"

Step 3: Prevent Script Injection

# VULNERABLE: User-controlled input in run step
- run: echo "PR title is ${{ github.event.pull_request.title }}"

# SECURE: Use environment variable (properly escaped by shell)
- name: Process PR
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}
    PR_BODY: ${{ github.event.pull_request.body }}
  run: |
    echo "PR title is ${PR_TITLE}"
    echo "PR body is ${PR_BODY}"

# SECURE: Use actions/github-script for complex operations
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
  with:
    script: |
      const title = context.payload.pull_request.title;
      console.log(`PR title: ${title}`);

Step 4: Secure Fork Pull Request Handling

# DANGEROUS: pull_request_target runs with base repo permissions
# on: pull_request_target  # AVOID unless absolutely necessary

# SAFE: pull_request runs in fork context with limited permissions
on:
  pull_request:
    branches: [main]

# If pull_request_target is required, never checkout PR code:
on:
  pull_request_target:
    types: [labeled]

jobs:
  safe-job:
    if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      # NEVER do: actions/checkout with ref: ${{ github.event.pull_request.head.sha }}
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
        # This checks out the BASE branch, not the PR

Step 5: Protect Secrets and Environment Variables

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production  # Requires approval
    steps:
      - name: Deploy with secret
        env:
          # Secrets are masked in logs automatically
          DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
        run: |
          # Never echo secrets
          # echo "$DEPLOY_KEY"  # BAD
          deploy-tool --key-file <(echo "$DEPLOY_KEY")

      - name: Audit secret access
        run: |
          # Log that secret was used without exposing it
          echo "::notice::Deploy key accessed for production deployment"

Step 6: Implement Workflow Change Controls

# Require CODEOWNERS approval for workflow changes
# .github/CODEOWNERS
.github/workflows/ @security-team @platform-team
.github/actions/ @security-team @platform-team

# Organization settings:
# 1. Settings > Actions > General > Fork PR policies
#    - Require approval for first-time contributors
#    - Require approval for all outside collaborators
# 2. Settings > Actions > General > Workflow permissions
#    - Read repository contents and packages permissions
#    - Do NOT allow GitHub Actions to create and approve PRs

Key Concepts

Term Definition
SHA Pinning Referencing GitHub Actions by their immutable commit SHA instead of mutable version tags
Script Injection Attack where untrusted input (PR title, branch name) is interpolated into shell commands
GITHUB_TOKEN Automatically generated token with configurable permissions scoped to the current repository
pull_request_target Dangerous event trigger that runs in the base repo context with full permissions on fork PRs
Environment Protection GitHub feature requiring manual approval before jobs accessing an environment can run
CODEOWNERS File defining required reviewers for specific paths including workflow files
OIDC Federation Using GitHub's OIDC token to authenticate to cloud providers without storing long-lived credentials

Tools & Systems

  • Dependabot: Automated dependency updater that keeps pinned action SHAs current
  • StepSecurity Harden Runner: GitHub Action that monitors and restricts outbound network calls from workflows
  • actionlint: Linter for GitHub Actions workflow files that detects security issues
  • allstar: GitHub App by OpenSSF that enforces security policies on repositories
  • scorecard: OpenSSF tool that evaluates supply chain security practices including CI/CD

Common Scenarios

Scenario: Preventing Supply Chain Attack via Compromised Third-Party Action

Context: A widely-used GitHub Action is compromised and its v3 tag is updated to include credential-stealing code. Repositories using @v3 automatically pull the malicious version.

Approach:

  1. Pin all actions to SHA digests immediately across all repositories
  2. Configure Dependabot for github-actions ecosystem to manage SHA updates
  3. Restrict GITHUB_TOKEN permissions so even compromised actions have minimal access
  4. Add StepSecurity harden-runner to detect anomalous outbound network calls
  5. Review all third-party actions and replace unnecessary ones with inline scripts
  6. Require CODEOWNERS approval for any changes to .github/workflows/

Pitfalls: SHA pinning without Dependabot means missing legitimate security updates to actions. Overly restrictive permissions can break legitimate workflows. Using pull_request_target for label-based gating still exposes secrets if the workflow checks out PR code.

Output Format

GitHub Actions Security Audit
================================
Repository: org/web-application
Date: 2026-02-23

WORKFLOW ANALYSIS:
  Total workflows: 8
  Total action references: 34

SHA PINNING:
  [FAIL] 12/34 actions use mutable tags instead of SHA digests
  - .github/workflows/ci.yml: actions/setup-node@v4
  - .github/workflows/deploy.yml: aws-actions/configure-aws-credentials@v4

PERMISSIONS:
  [FAIL] 3/8 workflows have no explicit permissions (inherit default)
  [WARN] 1/8 workflows request write-all permissions

SCRIPT INJECTION:
  [FAIL] 2 workflow steps interpolate user input directly
  - .github/workflows/pr-check.yml:23: ${{ github.event.pull_request.title }}

SECRETS:
  [PASS] No secrets exposed in workflow logs
  [PASS] All production deployments use environment protection

SCORE: 6/10 (Remediate 5 HIGH findings)

Other files in this skill

assets/template.md (verbatim)

GitHub Actions Security Templates

Hardened Workflow Template

name: Secure CI Pipeline
permissions: {}

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11  # v4.1.1
      - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6  # v2.8.1
        with:
          egress-policy: audit
      - name: Build
        run: make build
      - name: Test
        run: make test

Dependabot for Actions

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
    commit-message:
      prefix: "ci"

CODEOWNERS for Workflow Protection

# .github/CODEOWNERS
.github/workflows/ @org/security-team @org/platform-team
.github/actions/ @org/security-team
.github/dependabot.yml @org/platform-team

references/api-reference.md (verbatim)

API Reference: Securing GitHub Actions Workflows

Security Checks

Check Risk Severity
Unpinned actions (mutable tags) Supply chain attack via tag overwrite Medium
Missing permissions block Inherits overly broad defaults Medium
write-all permissions Excessive token scope High
Script injection in run steps Code execution via PR title/body High
pull_request_target trigger Fork code runs with base permissions High
Secrets in workflow logs Credential exposure Critical

Dangerous Expression Contexts

Context Risk
github.event.pull_request.title Attacker-controlled PR title
github.event.pull_request.body Attacker-controlled PR body
github.event.issue.title Attacker-controlled issue title
github.event.comment.body Attacker-controlled comment
github.head_ref Attacker-controlled branch name

SHA Pinning Format

Format Security
actions/checkout@v4 Insecure - mutable tag
actions/checkout@b4ffde65f... Secure - immutable SHA

Permission Scopes

Scope Values
contents read, write
actions read, write
deployments read, write
id-token write (for OIDC)
security-events write
pull-requests read, write

Python Libraries

Library Version Purpose
yaml PyYAML >=6.0 Parse workflow YAML
re stdlib Pattern matching
json stdlib Report output
pathlib stdlib File discovery

References

references/standards.md (verbatim)

Standards Reference: Securing GitHub Actions

NIST SSDF (SP 800-218)

PS.1: Protect All Forms of Code

  • Workflows are code and must be reviewed and protected
  • Pin action dependencies to SHA digests
  • Minimize GITHUB_TOKEN permissions

CIS Software Supply Chain Security

  • BD-1: Define security requirements for build processes
  • BD-2: Automate security validation of build configurations
  • BD-3: Pin all external dependencies to immutable references

OWASP CI/CD Top 10 Risks

Risk GitHub Actions Mitigation
CICD-SEC-1: Insufficient Flow Control Environment protection rules, CODEOWNERS
CICD-SEC-3: Dependency Chain Abuse SHA pinning of actions
CICD-SEC-4: Poisoned Pipeline Execution Restrict pull_request_target, input sanitization
CICD-SEC-6: Credential Hygiene OIDC federation, minimal GITHUB_TOKEN scope
CICD-SEC-9: Artifact Integrity Sign artifacts in workflows

SLSA Framework

  • Level 2: Hosted build service (GitHub Actions qualifies)
  • Level 3: Hardened build platform with isolation guarantees
  • Workflow hardening prevents provenance falsification

references/workflows.md (verbatim)

Workflow Reference: Securing GitHub Actions

Hardening Checklist

  1. Pin all actions to SHA digests
  2. Set restrictive default permissions
  3. Sanitize all user-controlled inputs
  4. Never use pull_request_target with PR checkout
  5. Enable environment protection for production
  6. Configure CODEOWNERS for workflow files
  7. Enable Dependabot for github-actions
  8. Audit third-party actions quarterly
  9. Use OIDC instead of long-lived cloud credentials
  10. Add harden-runner for network monitoring

Permission Scoping Reference

Permission Use Case
contents: read Checkout code
contents: write Create releases, push tags
security-events: write Upload SARIF results
packages: write Push container images
deployments: write Create deployment status
id-token: write OIDC cloud authentication
pull-requests: write Comment on PRs

Script Injection Prevention

# DANGEROUS patterns to avoid:
run: echo "${{ github.event.issue.title }}"
run: echo "${{ github.event.comment.body }}"
run: echo "${{ github.head_ref }}"

# SAFE alternatives:
env:
  TITLE: ${{ github.event.issue.title }}
run: echo "${TITLE}"

Back to mukul975/Anthropic-Cybersecurity-Skills (817 security skills) or Agent skills.