Safeguard
Security Guides•

How do environment approvals protect secrets from outside contributors?

Environment secrets stay locked until a required reviewer approves the job. Set it up, restrict branches and block self-approval for outside pull requests.

Safeguard Security Team
4 min read

Put the secret in an environment with required reviewers. A job that references the environment cannot read its secrets until a reviewer approves, so a pull request cannot reach credentials without a human decision. Add a branch rule and prevent self-review to close the common gaps.

What an environment is

On GitHub, an environment is a named target such as staging or production. It can hold its own secrets and variables, and deployment protection rules decide when a job that references it may proceed. Secrets stored in an environment are just available to jobs that reference it. If it requires approval, the job cannot read them until a required reviewer approves.

Why it helps with forks

Fork pull requests already get no repository secrets by default. Environments help in the cases where you do need a secret for an outside change, such as running an integration test against a sandbox after you have read the diff. The approval is a deliberate point where a maintainer says yes.

Steps

  1. Create an environment, for example integration-sandbox.
  2. Add required reviewers, up to six people or teams. One approver is enough.
  3. Turn on prevent self-review so the person who triggered the run cannot approve it.
  4. Under deployment branches and tags, restrict which refs can deploy to this environment.
  5. Move the credential from repository secrets to environment secrets.
  6. Reference the environment from the one job that needs the credential.
  7. Give that credential the minimum scope, ideally scoped to a sandbox.

Plan limits

GitHub documents that environments and environment secrets are available in public repositories on all current plans. For private or internal repositories you need GitHub Pro, Team or Enterprise. Check the plan page before you design around required reviewers.

What approval does not cover

  • It does not make untrusted code safe. If the approved job runs the contributor's code with the secret, the reviewer has approved running that code. Review the diff first.
  • It does not isolate self-hosted runners. GitHub notes those are not run in an isolated container even with environments.
  • It does not protect a secret that is stored at repository level in addition.
  • A reviewer who approves without reading adds little. Give reviewers a short checklist and keep approval requests rare.

A reviewer checklist

CheckQuestion
DiffDoes it touch workflows, scripts the job runs, or dependency manifests?
ScopeIs the credential limited to a sandbox?
SourceIs the contributor known, or is this a first time contributor?
AlternativesCould this test run without the secret?

Try it yourself

Click through it at your own pace, or open it full screen.

Look at the decision point on a pull request, which is where a human approval fits into an automated flow.

Where Safeguard fits

Safeguard policies and guardrails put clear decision points in a pull request flow, and its compliance and evidence automation helps organize review evidence. The free scan is a quick start.

Quick check

Can the pull request author approve their own environment run?

Not if you select prevent self-review in the environment's protection rules.

Do environments replace code review?

No. They add an approval step before secrets are exposed. The diff still needs to be read.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.