On this page
A GitHub Actions workflow is code that runs with your secrets, your GITHUB_TOKEN and often your cloud credentials, triggered by events that outsiders can cause. It pulls third-party code (actions) by reference at run time. That combination makes CI one of the most attractive targets in a software organization, and it is why supply-chain incidents increasingly start in a workflow file.
This guide covers the controls every repository should have: token permissions, action pinning and allowlisting, secret scoping with environments, and runtime monitoring. Untrusted input and pull_request_target get their own guide, as do self-hosted runners and OIDC to cloud providers.
Make GITHUB_TOKEN read-only by default
Each job receives a GITHUB_TOKEN scoped to the repository. Its default permissions are set at the enterprise, organization or repository level under Settings > Actions > General > Workflow permissions. Select Read repository contents and packages permissions everywhere, and leave Allow GitHub Actions to create and approve pull requests unchecked. Approving pull requests from a workflow would let a workflow satisfy your required review rule.
Then declare permissions explicitly in every workflow. An empty top-level block removes all permissions, and each job asks for exactly what it needs:
name: release
on:
push:
tags: ["v*"]
permissions: {}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: make build
publish:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write # create the GitHub release
id-token: write # OIDC for signing or cloud upload
attestations: write # build provenance
steps:
- run: echo "publish steps here"
persist-credentials: false on checkout stops the token from being written to .git/config, where any later step (or an uploaded artifact containing the workspace) could read it.
Pin actions to full commit SHAs
uses: some-org/some-action@v2 resolves the v2 tag at run time. Tags are mutable. Whoever controls the action's repository, legitimately or not, can move the tag to new code, and your next run executes it with your secrets. This is exactly what happened in March 2025 when the widely used tj-actions/changed-files action was compromised: its version tags were pointed at a malicious commit that dumped runner memory, including secrets, into workflow logs (tracked as CVE-2025-30066).
A full 40-character commit SHA is immutable. Pin every third-party action to one and keep the version as a comment so that humans and Dependabot can read it:
- uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
Tools such as pinact or StepSecurity's online tool rewrite existing workflows to SHAs. Dependabot's github-actions ecosystem then updates both the SHA and the comment, as shown in the Dependabot guide.
Two caveats:
- A pinned action can still fetch mutable things at run time (a
latestbinary, an unpinned Docker image, a nested action referenced by tag). Review what an action does before adopting it. Prefer actions that publish immutable releases. - Pinning protects against a moved tag, not against a malicious version you upgrade to. Combine it with a cooldown and review of action updates.
Enforce pinning with policy
Organization and enterprise owners can enforce this under Settings > Actions > General > Policies:
- Allow enterprise, and select non-enterprise, actions and reusable workflows, with Allow actions created by GitHub and an explicit allowlist such as
aws-actions/configure-aws-credentials@*, azure/login@*. - Require actions to be pinned to a full-length commit SHA: any workflow that references an action by tag or branch fails. Pin first, then turn it on, or many workflows will break the same day.
- Block specific actions or versions by adding them to the policy list with a
!prefix, for example!tj-actions/changed-files@*, which is useful during an incident.
The same policies exist per repository for organizations that cannot enforce them globally yet.
Scope secrets with environments
Repository and organization secrets are available to any workflow in the repository, on any branch, including a workflow a contributor adds in a feature branch. Deployment credentials should not be.
Put them in an environment (Settings > Environments) and protect it:
- Deployment branches and tags: only
mainor tags matchingv*. - Required reviewers: one or more people must approve each deployment job; enable Prevent self-review.
- Wait timer if you want a cancellation window.
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
- run: ./deploy.sh
env:
API_KEY: ${{ secrets.PROD_API_KEY }}
Secrets defined in the production environment are only available to jobs that reference it and pass its rules. Combined with OIDC subject claims that include the environment name, a cloud role can only be assumed by a job that went through the approval (see the OIDC guide).
Organization secrets should use Selected repositories access, never All repositories.
Review workflow changes like production code
Anyone who can change a workflow file can run code with that workflow's secrets. Protect .github/workflows/ with CODEOWNERS and required code owner review. Note that a pull request from a branch in the same repository runs the workflow version from that branch, so secrets that are not in protected environments are exposed to anyone with write access before review.
Fork pull request settings
Under Settings > Actions > General, for public repositories:
- Approval for running fork pull request workflows from contributors: choose Require approval for all external contributors (or at least first-time contributors). Approvers should read the diff before approving, since the approval runs the contributor's code.
- For private repositories, leave Run workflows from fork pull requests off unless you need it, and never enable Send write tokens to workflows from pull requests or Send secrets to workflows from pull requests.
Watch what runs: egress and integrity
Static controls reduce the chance of malicious code running; runtime controls limit what it can do. On GitHub-hosted runners, StepSecurity's Harden-Runner monitors network egress, file integrity and process activity per job, and can block outbound traffic to anything outside an allowlist:
steps:
- uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
with:
egress-policy: block
allowed-endpoints: >
github.com:443
api.github.com:443
registry.npmjs.org:443
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Start with egress-policy: audit to learn the endpoints a job uses, then switch to block. On self-hosted runners, enforce egress at the network layer instead.
Protect what the workflow produces
Builds are only trustworthy if you can tell which workflow produced them. Use artifact attestations to generate signed SLSA build provenance:
- uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: dist/app.tar.gz
Consumers verify with gh attestation verify dist/app.tar.gz --repo ACME/app. Treat caches as untrusted inputs too: a cache written by a pull request workflow can be restored by later runs on the same branch scope, so do not cache build outputs that you then ship without verification.
Checklist
- Default workflow permissions set to read;
permissions:declared in every workflow,{}at the top. persist-credentials: falseon checkout unless a later step pushes.- Every action pinned to a full SHA; SHA pinning policy enforced; allowlist of actions.
- Deployment secrets only in protected environments; organization secrets limited to selected repositories.
- Workflows owned by a security-aware team through CODEOWNERS.
- Fork pull request approval required on public repositories.
- No
pull_request_targetorworkflow_runrunning untrusted code (details). - Egress monitoring on sensitive jobs; build provenance on release artifacts.
- CodeQL
actionsanalysis or a linter such aszizmoron workflow files.
References
- Security hardening for GitHub Actions (GitHub Docs)
- Controlling permissions for GITHUB_TOKEN (GitHub Docs)
- GitHub Actions policy now supports blocking and SHA pinning actions (GitHub Changelog)
- Managing environments for deployment (GitHub Docs)
- CVE-2025-30066 (NVD)
- CISA alert on the tj-actions/changed-files supply chain compromise
- step-security/harden-runner (GitHub repository)
- zizmor: static analysis for GitHub Actions
- OWASP Top 10 CI/CD Security Risks
Tags:actionssupply-chainsecrets
Written by
Florian Amette, Security Engineer & EditorSecurity engineer writing practical hardening guides for GitHub organizations, repositories and CI/CD pipelines, with a focus on software supply-chain security.