CI/CDGitHub Actions
GitHub environments: approvals, secrets and deployment rules
An environment describes a deployment target such as production, with its own protection rules and secrets. A job that references it does not start until every rule passes, and only then can it read the environment's secrets.

How a job uses an environment
Create the environment under Settings, then Environments, in the repository. A job points at it with the environment key.
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: production
url: https://my-app.example.com
steps:
- uses: actions/checkout@v7
- run: ./deploy.sh
env:
API_KEY: ${{ secrets.API_KEY }}
REGION: ${{ vars.REGION }}All protection rules must pass before the job is sent to a runner. Until then the job cannot read the environment's secrets. By default GitHub also creates a deployment object for the job. Add deployment: false under environment to use the secrets and variables with no deployment object. The name, the address and ./deploy.sh in the example stand for your own.
Required reviewers
List up to six users or teams. Each needs at least read access to the repository, and one approval is enough. A job that is not approved within 30 days fails.
Two settings belong with it:
- Prevent self-review. Users who initiate a deployment cannot approve it, even if they are a required reviewer.
- Allow administrators to bypass configured protection rules. By default administrators can bypass the rules and force all pending jobs for the environment to proceed. Deselect the setting to disallow that.
Check your plan first. GitHub's reference states that on GitHub Free, GitHub Pro and GitHub Team, required reviewers are available only for public repositories.
Wait timers
A wait timer delays the job for a set time after it is triggered. The time is a whole number of minutes from 1 to 43,200 (30 days), and it does not count towards billable time. On GitHub Free, Pro and Team, wait timers are available only for public repositories.
Deployment branch and tag rules
This rule decides which refs may deploy to the environment. It has three settings:
- No restriction. Any branch or tag can deploy.
- Protected branches only. Only branches with branch protection rules can deploy. If the repository has no protected branch, every branch can.
- Selected branches and tags. Only refs that match your name patterns can deploy.
A rule is matched against the GITHUB_REF of the run. With the rule releases/*, only a ref whose name begins with releases/ can deploy. Wildcards do not match /: for names that begin with release/ and contain one more slash, GitHub's example is release/*/*. Name patterns are configured for branches and for tags individually.
Branch and tag rules are available on all public repositories, and on private repositories with GitHub Pro or GitHub Team.
Environment secrets and variables
A secret stored in an environment is available only to jobs that reference the environment. When an environment requires approval, its secrets stay out of a job's reach until one of the required reviewers approves. Environment variables are also limited to jobs that reference the environment, and are read through the vars context.
Move production credentials off the repository level. GitHub's security reference states that any user with write access to a repository has read access to all secrets configured in it. GitHub documents environment branch rules as a way to restrict which branches can use certain secrets.
On GitHub Free, environments can be configured only for public repositories. A self-hosted runner does not run workflows in an isolated container. GitHub says environment secrets on such a runner deserve the same level of security as repository secrets and organization secrets.
Custom deployment protection rules
A custom rule gates the deployment with a third-party system through a GitHub App. When a job reaches the environment, GitHub sends a deployment_protection_rule webhook to the app. The app approves or rejects through the REST API, on conditions from its own system, such as an approved ticket or the health metrics of a cloud resource.
GitHub lists the feature as a public preview. At most six deployment protection rules can be enabled on an environment at the same time. Custom rules require a deployment object, so a job with deployment: false fails on an environment that has one. On Free, Pro and Team plans they are available only for public repositories.
Environments in OIDC subject claims
When a job references an environment, the subject claim of its OIDC token includes the environment name:
repo:my-org/my-repo:environment:productionA trust condition on this subject requires that the token comes from a job that references that environment. The subject includes the branch name only if the job does not reference an environment, so check any condition on ref:refs/heads/... when you add environment to a job.
Repositories created after July 15, 2026 use a subject format that includes the owner ID and the repository ID. GitHub's reference names the github/actions-oidc-debugger action for printing the claims before you write a trust policy.
What to check on production
- The branch rule allows only the branch or tags you release from.
- Required reviewers are set, with self-review prevented and the admin bypass off.
- Production secrets are stored on the environment.
- The cloud trust policy matches the environment subject.
- The name in the workflow is spelled as in the settings. A job that names an environment that does not exist creates it, with no rules and no secrets.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Concurrency groups: stop two deploys from running at once
CI/CD · 4 min read
One run per group at a time: cancel outdated pull request runs and never cancel a deploy.

Rolling, blue-green or canary: choosing a deployment strategy
CI/CD · 2 min read
What each strategy does, what it needs, and how to pick one.

Jenkins shared libraries: one pipeline for many jobs
CI/CD · 4 min read
Lay out a shared library, write one custom step, name its version and know what trusted means.