Permissions, OIDC & Pinning by SHA
A release pipeline holds the most valuable credentials a project has: the right to push tags, publish packages and deploy. Attacks on CI (compromised third-party actions, script injection through pull-request titles, stolen long-lived tokens) target exactly that. Four habits remove most of the risk: least-privilege tokens, short-lived credentials through OIDC, actions pinned to commit SHAs, and never interpolating untrusted text into scripts. The deeper supply-chain picture (SLSA, provenance, Sigstore) is in Software Supply Chain Security.
The GITHUB_TOKEN and permissions
Every job gets an automatic GITHUB_TOKEN, valid for the job's duration and scoped to the repository. What it may do is set by permissions, at workflow or job level:
permissions:
contents: read # workflow default for every job
jobs:
test:
runs-on: ubuntu-24.04
steps: [ ... ] # inherits contents: read
release:
runs-on: ubuntu-24.04
permissions:
contents: write # push tags, create releases
id-token: write # request an OIDC token (below)
attestations: write # write artifact attestations
steps: [ ... ]- As soon as you list any permission, every scope you didn't list becomes
none.permissions: {}removes all;read-allandwrite-allexist but defeat the purpose. - Scopes include
actions,attestations,checks,contents,deployments,discussions,id-token,issues,packages,pages,pull-requests,security-eventsandstatuses, eachread,writeornone(id-tokeniswriteornone). - Set the repository or organisation default to read-only (Settings → Actions → Workflow permissions) and grant
writeper job. Then a compromised test step can't push to your repository.
OIDC instead of stored cloud secrets
A stored AWS_SECRET_ACCESS_KEY works forever, for anyone who copies it. With OpenID Connect, the job asks GitHub for a signed, short-lived identity token (permissions: id-token: write), and the cloud provider exchanges it for temporary credentials if the token's claims match a trust policy you configured:
jobs:
deploy:
runs-on: ubuntu-24.04
environment: production
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/release-deployer
aws-region: eu-central-1
- run: aws s3 cp dist/ s3://acme-downloads/v1.4.2/ --recursiveThe trust policy on the AWS side pins who may assume the role through the token's sub claim, for example repo:acme/tad:environment:production (only jobs of that repository using the production environment) or repo:acme/tad:ref:refs/tags/v*. Azure (azure/login), Google Cloud (google-github-actions/auth), HashiCorp Vault and package registries work the same way. npm and PyPI trusted publishing use this too: the registry trusts "workflow release.yml in repository acme/tad", and no publish token is stored anywhere.
Pinning actions by commit SHA
uses: some-org/some-action@v3 runs whatever commit the tag v3 points to today. Tags can be moved; if the action's repository is compromised, every workflow using @v3 runs the attacker's code on its next run, with its secrets. This has happened to popular actions. A full commit SHA can't be moved:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
- uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3- Keep the version in a comment; Dependabot and Renovate understand the
# vX.Y.Zcomment and open PRs that update SHA and comment together:yaml# .github/dependabot.yml version: 2 updates: - package-ecosystem: github-actions directory: / schedule: interval: weekly - Organisations can enforce it: the Actions policy can require every action to be pinned to a full-length commit SHA, and can restrict which actions are allowed at all.
- Pinning only freezes the action's own code. An action that downloads "latest" of something at run time, or a Docker-based action using a mutable image tag, still changes underneath you; prefer actions that pin their own dependencies.
- An annotated tag's SHA is not the commit SHA: pin the commit (
git ls-remoteshows it on the^{}line, as in Tags).
Script injection
Expressions (${{ … }}) are substituted into the script text before the shell sees it. If the value is attacker-controlled (a PR title, a branch name, an issue body, a commit message), the attacker writes shell code. The session reproduces the substitution with a plain text replacement, exactly as the runner does it, for a malicious PR title:
title='fix: typo"; echo "stealing $SECRET_TOKEN"; echo "'
export SECRET_TOKEN=s3cr3t-value
# the workflow step: run: echo "Checking title: ${{ github.event.pull_request.title }}"
cat > step.sh <<'STEP'
echo "Checking title: ${{ github.event.pull_request.title }}"
STEP
echo "--- unsafe: the expression is pasted into the script"
placeholder='${{ github.event.pull_request.title }}'
script=$(cat step.sh)
printf '%s\n' "${script//"$placeholder"/"$title"}" > rendered.sh
cat rendered.sh
bash rendered.sh 2>&1
# the safe step: env: { TITLE: ${{ github.event.pull_request.title }} } run: echo "Checking title: $TITLE"
echo "--- safe: the value arrives as an environment variable"
TITLE="$title" bash -c 'echo "Checking title: $TITLE"'--- unsafe: the expression is pasted into the script
echo "Checking title: fix: typo"; echo "stealing $SECRET_TOKEN"; echo ""
Checking title: fix: typo
stealing s3cr3t-value
--- safe: the value arrives as an environment variable
Checking title: fix: typo"; echo "stealing $SECRET_TOKEN"; echo "
In the unsafe version the title closed the string and ran its own command with access to the job's secrets. Passed through env:, the same text is just data. The rule: never put ${{ github.event.* }} (or any untrusted input) inside run:; map it to an environment variable and quote it. The same applies to actions/github-script code and to inputs of workflow_dispatch.
More hardening for release workflows
| Measure | Why |
|---|---|
actions/checkout with persist-credentials: false in jobs that don't push |
the token isn't left in the workspace for later steps to read |
no pull_request_target + checkout of PR code |
that trigger runs with secrets; building fork code there hands them over |
release jobs only on push to protected branches/tags, in an environment |
forks and PRs can't reach release credentials |
| separate build and publish jobs; publish downloads artifacts and only publishes | the job with write tokens runs no build scripts or dependency code |
| tag and release rulesets, immutable releases | a stolen token can't rewrite history (Tags) |
artifact attestations (actions/attest-build-provenance@v4) |
users can verify which workflow built an artifact (Signing Releases) |
Test yourself
A job declares permissions: { contents: write }. What is its issues permission?
- read
- write
- none: unspecified scopes become none once any is listed
- Inherited from the repository default
What does OIDC give a deploy job instead of a stored cloud secret?
- A permanent API key
- A short-lived signed identity token that the cloud exchanges for temporary credentials if its claims match a trust policy
- SSH access to the runner
- A copy of the repository secrets
Why is run: echo "${{ github.event.pull_request.title }}" dangerous?
- Titles can be long
- The title is pasted into the script before the shell runs, so a crafted title can execute commands
- Echo can't print Unicode
- It leaks the PR number