Join our Newsletter — 33% off our NHI Course
Home› Guides› Deployment Environments: Using Protection Rules, Approvals and Scoped…
Guide Software & AI Supply Chain

Deployment Environments: Using Protection Rules, Approvals and Scoped Secrets to Gate Releases

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 14 min read
On this page

A release pipeline that keeps production credentials in repository secrets lets any workflow, on any branch, deploy to production. GitHub Actions deployment environments close that gap: a job that names an environment must pass that environment's protection rules before it starts, and only then can it read the environment's secrets. This guide explains how to design environments as release gates on GitHub: required reviewers, wait timers, branch and tag rules, custom protection rules, environment-scoped secrets and OIDC subject claims that name the environment. It is written for DevSecOps and platform engineers who own GitHub organisations and cloud deployment roles. For the wider platform picture, see the GitHub and GitHub Actions Security Guide.

This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.

Key takeaways

  • An environment is a gate, not a label. A job that references an environment waits until every protection rule passes, and environment secrets are only read when that job starts, so the secret is never exposed to an unapproved job.
  • Move production secrets out of repository scope. Repository and organisation secrets reach every workflow in the repository; environment secrets reach only jobs that reference the environment and have passed its rules.
  • Branch rules matter as much as approvals. Without a "Selected branches and tags" rule, an approver may be asked to wave through a deployment from a feature branch they have never reviewed.
  • Bind cloud trust to the environment. When a job references an environment, the OIDC subject becomes repo:ORG/REPO:environment:NAME, so a cloud role can trust production deployments and nothing else.
  • Turn off the administrator bypass for production. By default administrators can force deployments past the rules; clearing that setting makes the gate apply to everyone.

What deployment environments are

GitHub describes an environment as a general deployment target such as production, staging or development. A job opts in with the environment key, for example environment: production, or the long form with name and url. Three things then happen: the job is held until the environment's deployment protection rules pass, the job gains access to that environment's secrets and variables, and GitHub records a deployment object that appears in the environment's deployment history.

  • Who can configure them: the repository owner for personal repositories, or users with admin access for organisation repositories. Environments can also be managed through the REST API (environments, secrets, variables and deployment branch policies endpoints), which suits policy as code.
  • Naming: names are not case sensitive, may not exceed 255 characters and must be unique in the repository.
  • Implicit creation: running a workflow that references an environment that does not exist creates it, with no protection rules or secrets. A typo such as prodution therefore produces an ungated environment rather than an error.
  • Deletion: deleting an environment deletes its secrets and protection rules, and jobs waiting on it fail.
  • Environments without deployments: setting deployment: false in the job's environment block skips the deployment record. Wait timers and required reviewers still apply, but a job targeting an environment with a custom protection rule fails, because those rules need a deployment object.

Availability: GitHub's documentation states that environments, environment secrets and deployment protection rules are available in public repositories on all current plans. For private or internal repositories, environments, environment secrets and deployment branches need GitHub Pro, Team or Enterprise; on Free, Pro and Team plans, required reviewers, wait timers, the administrator bypass setting and custom protection rules apply to public repositories only, so private repositories need GitHub Enterprise for those. On Free plans, converting a public repository to private causes configured protection rules and environment secrets to be ignored. Check the current plan pages before relying on a rule in a private repository.

Protection rules and required reviewers

Protection rules are the conditions a job must meet before it runs. The settings below are those listed in GitHub's environment reference.

SettingWhat it enforcesLimits and behaviourRecommended for production
Required reviewersA named person or team must approve the jobUp to six users or teams; reviewers need at least read access; one approval is enoughA small release team, not individuals who may be absent
Prevent self-reviewThe user who started the deployment cannot approve it, even if listedOff unless selectedOn, so every production release has two people
Wait timerDelays the job after it is triggered1 to 43,200 minutes (30 days); wait time is not billedShort delay for staged rollouts or a cancel window
Deployment branches and tagsLimits which refs can deployNo restriction, Protected branches only, or Selected branches and tags (patterns matched against GITHUB_REF)Selected branches and tags, naming main or a release tag pattern
Allow administrators to bypass configured protection rulesLets admins force pending jobs to proceedOn by default; bypass is only possible while a job is Pending and needs a commentClear the setting; use a documented break-glass process instead
Custom deployment protection rulesA GitHub App approves or rejects based on an external systemPublic preview; up to six rules enabled per environmentChange ticket or monitoring health gate where one exists

How approval works

When a run reaches a gated job, reviewers see a Review deployments prompt, choose the environment and select Approve and deploy or Reject, optionally with a comment. A rejection fails the workflow. Approval is recorded per run, and the review history is available from the REST API (GET /repos/OWNER/REPO/actions/runs/RUN_ID/approvals), which is the evidence auditors usually ask for.

  • Reviewer design: because one approval suffices, list a team rather than six individuals, and keep that team small and reviewed. A reviewer only needs read access, so release approval can sit with people who cannot push code, which strengthens separation of duties.
  • What reviewers should check: the commit SHA and branch being deployed, whether the change passed review on that branch, and the run's trigger. An approval prompt from a workflow_dispatch on an unfamiliar branch deserves a reject.
  • Custom rules: a custom rule is a GitHub App with Actions read and Deployments read and write permissions, subscribed to the Deployment protection rule event. GitHub posts a deployment_protection_rule payload to the app, which validates the delivery, authenticates as the app and calls POST /repos/OWNER/REPO/actions/runs/RUN_ID/deployment_protection_rule with state set to approved or rejected. The app's private key becomes a release credential, so protect it like one. See the GitHub App Private Key Security Guide.

Scoped environment secrets

Secrets can live at organisation, repository or environment level. Environment scope is the one that is tied to a gate.

PropertyOrganisation and repository secretsEnvironment secrets
Which jobs can read themAny workflow in the repository (organisation secrets: repositories granted access)Only jobs that reference the environment
When they are readWhen the workflow run is queuedWhen the job referencing the environment starts, after protection rules pass
Approval controlNoneRequired reviewers and other rules must pass first
Name collisionRepository overrides organisationEnvironment overrides both
Count limits1,000 organisation, 100 repository100 per environment
Size48 KB per secret48 KB per secret
  • Precedence is a risk as well as a feature: because the environment secret wins on a name collision, a job without an environment silently falls back to a repository secret of the same name. Delete the repository copy when you move a secret into an environment, or a gated secret has an ungated twin.
  • Self-hosted runners: GitHub notes that workflows on self-hosted runners are not run in an isolated container even when they use environments, so environment secrets on those runners deserve the same care as repository secrets. Use dedicated, ephemeral runners for production jobs.
  • Prefer no secret at all: the best environment secret is the one replaced by OIDC federation, covered next. Keep environment secrets for targets that cannot accept federated tokens, and rotate them. See the Secrets Management Guide and How to Audit CI/CD Secrets Scope.

OIDC and environment claims

GitHub's OIDC token carries the environment in two places. The environment claim holds the environment name, and the default sub claim switches format when the job references an environment:

Job contextDefault sub format
Job references an environmentrepo:ORG/REPO:environment:NAME
Pull request event, no environmentrepo:ORG/REPO:pull_request
Branch, no environment, not a pull requestrepo:ORG/REPO:ref:refs/heads/BRANCH
Tag, no environment, not a pull requestrepo:ORG/REPO:ref:refs/tags/TAG
  • Trust the environment, then gate the environment: a cloud role whose trust condition is repo:octo-org/octo-repo:environment:production can only be assumed by a job that passed the production environment's rules. That turns the GitHub approval into a cloud access control.
  • The branch drops out of the subject: once an environment is referenced, the default subject no longer contains the ref. Enforce the branch with the environment's deployment branch rule, or add claims through a subject customisation template (for example repo, context and job_workflow_ref).
  • Special characters: colons in names are encoded, so an environment called Production:V1 appears as Production%3AV1. Simple lower-case names avoid matching surprises.
  • Implicit creation again: a subject that trusts environment:production is only as strong as the rules on that environment. If someone deletes it, the next run recreates it with no rules, so monitor environment configuration (see Rollout, detection and measurement).

Cloud-side setup is covered in the GitHub Actions OIDC Federation Hardening Guide, How to set up workload identity federation for GitHub Actions to AWS and How to federate GitHub Actions to Azure. Other CI platforms are covered in How to Scope CI OIDC Trust to Branch and Environment.

Branch and tag restrictions

The deployment branches and tags setting decides which refs can use the environment at all, before any reviewer is asked.

  • No restriction: any branch or tag can deploy. Acceptable for a development environment with no sensitive secrets.
  • Protected branches only: only branches with branch protection rules can deploy. GitHub documents two traps: if no branch protection rules exist in the repository, all branches can deploy, and tags with the same name as a protected branch, or fork branches matching the name, cannot deploy.
  • Selected branches and tags: name patterns, configured separately for branches and tags, matched against GITHUB_REF. A pattern of releases/* allows refs beginning releases/; wildcards do not match /, so release/*/* is needed for one extra level. Adding refs/pull/*/merge would let pull_request runs deploy, which is rarely wanted for production.

Pair with branch protection or rulesets. A rule that allows main is only as strong as the controls on main: require pull request review, status checks and restrictions on who can push. For tag-based releases, protect the tag pattern too, otherwise anyone with write access can push a matching tag and trigger a production deployment request.

Choosing a pattern

Release modelProduction ruleTrade-off
Trunk-based, deploy from mainBranch main only, plus required reviewersSimple; relies on strong protection of main
Tagged releasesTag pattern such as v*, with protected tagsClear provenance; tag protection must be in place
Release branchesBranch pattern release/*Supports hotfix lines; every matching branch needs protection
Small team, one repositoryProtected branches onlyLow effort; fails open if all protection rules are removed

Rollout, detection and measurement

  1. Inventory: list workflows that deploy or use cloud credentials, the secrets each uses and the scope of each secret. Use the REST API to list environments and their protection rules per repository.
  2. Create environments with rules before referencing them: define production through the API or Terraform with reviewers, prevent self-review, a branch or tag rule and the bypass setting cleared, so the first run never meets an ungated, implicitly created environment.
  3. Pilot on one service: move its production secrets into the environment, delete the repository copies, and switch the cloud role trust to the environment subject. Run a release and a rejected release to confirm both paths.
  4. Expand by risk: production first, then staging environments that hold real data or shared credentials.
  5. Rollback: if a gate blocks an urgent release, a listed reviewer approves it; avoid re-enabling the administrator bypass. Rolling back the change itself is a normal deployment that passes the same gate.

Detection draws on deployment history, the run approvals endpoint, deployment and deployment_status webhooks, and the organisation audit log stream. Watch for production deployments with no recorded approval, bypassed rules, new or deleted environments, changes to reviewers or branch policies, and new repository secrets whose names match environment secrets. See the GitHub Audit Log Detection Guide.

  • Coverage: percentage of production deploy jobs that reference a gated environment (target 100%).
  • Secret scope: count of production credentials still held as repository or organisation secrets (target zero).
  • Federation: percentage of cloud deployment roles that trust an environment subject rather than a branch or a repository wildcard.
  • Bypass rate: production environments with the administrator bypass enabled, and bypass events per quarter.
  • Approval quality: share of production approvals given by someone other than the initiator (should be 100% with prevent self-review on).

Framework mapping

ControlNIST SP 800-53 Rev. 5NIST CSF 2.0Other
Required reviewers, prevent self-reviewCM-3 Configuration Change Control, AC-5 Separation of DutiesPR.PS-01OWASP CI/CD Top 10 CICD-SEC-1
Branch and tag rules, bypass disabledCM-5 Access Restrictions for Change, SA-10 Developer Configuration ManagementPR.PS-01OWASP CI/CD Top 10 CICD-SEC-1
Environment-scoped secretsIA-5 Authenticator Management, AC-6 Least PrivilegePR.AA-01, PR.AA-05OWASP CI/CD Top 10 CICD-SEC-6
OIDC subject bound to environmentAC-6 Least Privilege, AC-3 Access EnforcementPR.AA-05Counters ATT&CK T1195.002 Compromise Software Supply Chain

See the OWASP CI/CD Top 10 CICD-SEC-1 Insufficient Flow Control Mechanisms Guide and the Change Management Security guide.

Common failure patterns

  • Gated environment, ungated twin secret: the production key is added to the environment but left in repository secrets, so any workflow can still read it.
  • Approvals without branch rules: reviewers approve a deployment request without noticing it came from a feature branch or a manual dispatch with modified workflow code.
  • Cloud trust on a repository wildcard: a role trusting repo:ORG/REPO:* lets pull request and branch jobs assume it, bypassing the environment entirely. Trust the environment subject instead.
  • Protected branches only, with no protected branches: the setting reads as safe, but GitHub's documented behaviour is that all branches can deploy when no branch protection rules exist.
  • Administrator bypass left on: the default allows admins to force deployments, so the gate does not apply to the people most often targeted by account takeover.
  • Self-hosted runners shared with untrusted jobs: environment secrets land on a persistent runner that pull request jobs also use. Keep production on dedicated ephemeral runners. See the CI/CD Pipeline Identity Security Guide.

Practitioner checklist

  • Every production deploy job references a production environment created with rules in place before first use.
  • Required reviewers is a small team, with Prevent self-review selected.
  • Deployment branches and tags is set to Selected branches and tags (or protected branches, with protection actually configured), and matching branches and tags are protected.
  • Allow administrators to bypass configured protection rules is cleared for production.
  • Production credentials exist only as environment secrets, with no same-named repository or organisation secret.
  • Cloud roles trust repo:ORG/REPO:environment:production, never a repository wildcard.
  • Custom protection rule apps hold minimal permissions and their private keys are stored and rotated as release credentials.
  • Environment configuration is managed as code and changes alert the platform team.
  • Approval history is exported for change and audit evidence.

Standards and references

Related NHI Mgmt Group resources: GitHub and GitHub Actions Security Guide, GitHub Actions OIDC Federation Hardening Guide, How to Restrict GITHUB_TOKEN Permissions in Workflows, How to Audit CI/CD Secrets Scope.

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.