GitHub Actions can automate testing, releases, and infrastructure changes, but a workflow is also executable code with access to repositories, tokens, secrets, and deployment systems. This checklist provides a practical way to reduce that risk without making ordinary builds difficult to maintain. Use it when adding a workflow, reviewing external contributions, upgrading actions, or performing a scheduled CI security audit.
Overview
A secure GitHub Actions workflow follows four principles: grant the smallest useful token permissions, keep untrusted pull-request code away from secrets, treat third-party actions as dependencies, and isolate jobs that can change production or repository settings.
The most important control is the GITHUB_TOKEN permission model. Set permissions explicitly at the workflow level, then grant additional access only to the job that needs it. A test job usually needs no write access. A release job may need permission to publish a package or create a release, but that access should not automatically apply to every step.
| Permission | Typical use | Review question |
|---|---|---|
contents: read | Checkout source and read repository files | Does this job need to write source, tags, or releases? |
contents: write | Create releases, tags, or repository changes | Can this be limited to a protected release job? |
pull-requests: read | Read pull-request metadata or files | Is write access actually required? |
pull-requests: write | Post comments, labels, or reviews | Could a compromised step alter the review process? |
actions: read | Read workflow or run information | Does the action need workflow-management data? |
packages: write | Publish packages or container images | Is publishing separated from tests and pull requests? |
These are examples rather than a universal permission map. Check the documentation for each action and confirm the exact capability required by the job. An explicit baseline makes future permission changes visible in code.
Checklist by scenario
For ordinary pull requests
- Use
pull_requestfor validation of proposed changes wherever possible. - Set a restrictive workflow-level permission baseline, such as
contents: read, or disable permissions and add only what is needed. - Do not expose deployment credentials, cloud credentials, signing keys, or production tokens to untrusted build steps.
- Keep checkout, dependency installation, tests, and reporting steps limited to the job’s purpose.
- Review scripts invoked by the workflow. A pull request can modify shell scripts, package configuration, build files, and test code that the runner executes.
For forked pull requests and external contributions
- Assume code from a fork is untrusted, even when the change appears small.
- Expect repository secrets to be unavailable to fork-triggered workflows. Do not design a security boundary around a secret being absent; design the workflow so the job is safe without it.
- Use a separate, trusted maintainer workflow for privileged tasks such as publishing artifacts, deploying, or approving a change.
- Inspect any workflow change before enabling it on a branch with sensitive credentials.
- Require appropriate review and environment approval for production operations.
For pull_request_target
Treat pull_request_target as a privileged event, not as a drop-in replacement for pull_request. It runs in the context of the base repository and may have access to its permissions and secrets. Never check out and execute untrusted pull-request code in that privileged context unless the design has been carefully isolated and reviewed.
A safer pattern is to use it only for narrowly scoped trusted operations, such as handling metadata, and to avoid commands that evaluate files supplied by the pull request. If a workflow must process an artifact from an untrusted job, define the artifact boundary explicitly and validate its contents before use.
For releases and deployments
- Separate build and test jobs from release or deployment jobs.
- Trigger privileged jobs only from trusted branches, tags, or manual approvals appropriate to your release process.
- Use environment protection and short-lived credentials where supported by the deployment platform.
- Give the deployment job only the permissions and secrets it needs.
- Record what was built, tested, and deployed so a rollback is understandable.
For the surrounding release process, see the Docker image tagging and promotion checklist and the deployment smoke-test guide.
For third-party actions
- Prefer maintained actions with a clear purpose and a narrow permission requirement.
- Pin actions to a full commit SHA for stronger supply-chain control instead of relying only on a movable tag such as
v4. - Keep a human-readable comment beside the SHA identifying the intended version, then update both deliberately.
- Review changes before updating a pinned SHA, especially for actions that handle secrets or modify releases.
- Consider reusable workflows or centrally managed approved actions for common organization-wide tasks.
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@FULL_COMMIT_SHA # intended version: vX.Y.Z
- name: Run tests
run: ./scripts/test.sh
Replace the placeholder with the verified full commit SHA for the action version you intend to use. A tag comment improves readability, but the SHA is the value that pins execution.
What to double-check
- Permissions: Is there a workflow-level baseline? Does every job override it only when necessary? Search for write permissions and explain each one.
- Events: Does the trigger match the trust level of the code being run? Review
push,pull_request,pull_request_target, tag, schedule, and manual triggers separately. - Secrets: Where can each secret be reached? Check job-level environment variables, called workflows, deployment environments, and command output. Avoid printing values or passing them to tools that do not need them.
- Checkout behavior: What ref is checked out, and can it contain an attacker-controlled workflow or script? This question is especially important for privileged events.
- Runner choice: Use isolated or ephemeral runners for sensitive work when practical. Do not place unrelated trust domains on a persistent self-hosted runner without a cleanup and access-control plan.
- Dependencies: Review action versions, package installation sources, lockfiles, container images, and scripts downloaded during the job.
- Artifacts and logs: Ensure artifacts do not contain credentials, configuration files, tokens, or private source that later jobs or users should not receive.
- Failure paths: Check cleanup steps, cancellation behavior, retries, and notifications. A failed deployment should not leave credentials or partially changed infrastructure exposed.
For workflows that call external systems, apply the same thinking to webhook authentication, retries, and idempotency described in this webhook integration guide.
Common mistakes
- Using broad write access as a convenience: A build does not need repository write access simply because a release job does. Scope permissions by job.
- Checking out a fork in a privileged workflow: This can turn a harmless-looking pull request into code execution with access to trusted context. Keep untrusted code and privileged credentials separate.
- Assuming a hidden secret makes a job safe: Pull-request behavior can vary by event, repository setting, actor, and credential type. Remove the need for the secret rather than relying on it being withheld.
- Pinning only the major version: A version tag is convenient but movable. Use a verified full SHA when stronger action integrity is required.
- Trusting a pinned action forever: Pinning improves reproducibility, but it does not replace review. Track action advisories, update deliberately, and remove unused actions.
- Putting deployment and tests in one job: Combining them makes it harder to restrict credentials and harder to identify which step changed production.
- Ignoring workflow files in code review: A change under
.github/workflowscan alter triggers, permissions, commands, and secret exposure. Review it as security-sensitive code.
When to revisit
Run this checklist before adding or changing a workflow, when enabling contributions from outside the core team, before connecting a new deployment target, and after changing repository visibility or runner infrastructure. Revisit it during quarterly or seasonal planning cycles, after an action or dependency update, and whenever GitHub Actions behavior or supported action versions change.
For a quick audit, open every workflow and record five items: trigger, token permissions, secrets, third-party actions, and privileged destinations. Mark each item as required, restricted, or removable. Then make the smallest safe change, run a pull-request test, and confirm that release and deployment paths still work.
Keep the resulting decisions near the workflow in comments or repository documentation. A useful audit is not merely a one-time fix; it is a repeatable habit that makes future CI/CD changes easier to review. Pair this checklist with your database migration and release procedures, such as the zero-downtime migration checklist, so application changes, infrastructure changes, and GitHub Actions permissions are reviewed together.