Skip to content

Chapter 5 of 7

Permissions, Tokens, and Security

Every workflow run is automatically provisioned with a GITHUB_TOKEN, which is used to authenticate with the GitHub API. The default scope of this token is read-only on most permissions, so any workflow that needs to write back to the repository or otherwise perform privileged actions must explicitly elevate its permissions. The permissions: key, usable at both workflow and job level, controls this; permissions: contents: read grants read-only repository content access, permissions: read-all grants read-only access across all available scopes, and job-level settings override workflow-level settings.

When a workflow needs to commit and push code as part of its automation, a common pattern is to set permissions: contents: write on the job, configure git with the recommended bot identity github-actions[bot] and the email 41898282+github-actions[bot]@users.noreply.github.com, and then use the GITHUB_TOKEN for authentication. The peter-evans/create-pull-request action is a popular tool for automating the creation of pull requests from a branch after commits are pushed.

Security considerations are especially important around pull_request events. The pull_request_target trigger runs in the base repository context with write permissions and is a frequent source of script injection attacks, so it should be used with extreme caution. Self-hosted runners on public repositories carry a similar risk: malicious pull requests from forks can run untrusted code on your own infrastructure. The standard mitigations are to require approval for first-time contributors, use fork-PR approval settings, and prefer ephemeral runners. GitHub-hosted runners, by contrast, start fresh for each job and have open egress to the public internet, so private networking requires a self-hosted runner.

All chapters
  1. 1GitHub Actions Foundations
  2. 2Triggering Workflows
  3. 3Jobs, Matrices, Concurrency, and Conditions
  4. 4Environment Variables, Outputs, and Context References
  5. 5Permissions, Tokens, and Security
  6. 6Artifacts, Caching, and Service Containers
  7. 7Reusable Workflows, Environments, and Deployments

Drill it

Reading is not remembering. These come from the Github Actions Ci Cd Recipes deck:

Q

What is GitHub Actions?

A CI/CD and workflow automation platform built into GitHub that runs jobs in response to repository events using YAML-defined workflows stored in .github/workfl...

Q

What file extension do GitHub Actions workflow files use?

.yaml or .yml, stored under .github/workflows/ in the repository.

Q

What is a workflow in GitHub Actions?

An automated, configurable process defined by a YAML file that runs one or more jobs and is triggered by events.

Q

What is a job in GitHub Actions?

A set of steps in a workflow that execute on the same runner; jobs run in parallel by default unless dependencies are declared with needs:.