Skip to main content
Secret management can look straightforward: add a secret and reference it in your workflow YAML. In practice, deployments need human and technical guardrails to prevent accidental or malicious exposure. GitHub Actions environments provide three integrated layers of protection: branch mapping, manual approvals, and environment-scoped secrets. Together they create an auditable, restricted path for sensitive credentials to reach deployment targets. Here’s a minimal example showing how a workflow step references a secret (this may be an environment-scoped secret):
  1. Branch mapping Branch mapping restricts which branches are allowed to deploy to a given environment. For instance, configure your production environment to accept deployments only from main or branches matching a release pattern. If someone triggers a production deployment from a personal feature branch, GitHub prevents the job from progressing to the environment approval step.
  2. Manual approvals Add a human approval gate by requiring reviewers for an environment. When a job targets the production environment, GitHub pauses the workflow and notifies the configured reviewers. The deployment cannot continue until a reviewer clicks Approve, creating an auditable change-control record tied to that deployment.
A presentation slide titled "Manual Approvals" showing a small boxed UI for the production environment with protection rules. It lists two approved groups, "platform-leads" and "release-managers," each marked with a check.
When a job is waiting for approval the UI displays a paused state like this:
  1. Environment secrets Store production credentials (for example, database passwords or API keys) as secrets scoped specifically to an environment. Environment-scoped secrets are only accessible when the workflow run reaches that environment — and because access requires both the branch to be allowed and any required approvals to be granted, those secrets are protected by both technical and human controls. This prevents a developer from exposing production secrets from a feature branch.
A slide titled "Environment Secrets" showing a UI panel that lists PROD_DB_PASSWORD and PROD_API_KEY. Below it is a simple process flow: a developer → branch mapping → manual approval → environment secrets (marked "Never handed out").
OpenID Connect (OIDC) and short-lived credentials For cloud deployments, you can avoid storing static cloud keys in GitHub by using OpenID Connect (OIDC). Instead of embedding a long-lived cloud key, the workflow requests a one-time signed JSON Web Token (JWT) from GitHub. That token carries claims such as the repository, ref/branch, workflow name, and targeted environment. Example OIDC token claims:
Your cloud provider (for example, AWS) verifies the token signature against GitHub’s public OpenID Connect endpoint. If the claims match the provider’s trust policy, the provider issues temporary, short-lived credentials (commonly expiring after about one hour). This eliminates the need to store static, long-lived cloud keys in GitHub.
When using OIDC, ensure your cloud trust policy restricts accepted claims (repository, ref, environment, etc.) to follow the principle of least privilege. Misconfigured trust policies can accidentally widen access.
An infographic titled "Using OpenID Connect (OIDC)" that diagrams a four-step flow: a GitHub workflow requests access, GitHub issues a one-time signed JSON web token, AWS verifies it, and returns short-lived temporary credentials. It also notes no AWS keys are stored in GitHub and that claims must match a trust policy.
Quick reference table Exam-focused summary
  • Environments map deployments to specific branches and prevent unapproved branches from reaching sensitive gates.
  • Environment-scoped secrets are only accessible after branch restrictions and manual approvals are satisfied.
  • OIDC replaces static cloud keys by exchanging a signed JWT for temporary credentials when claims match the cloud provider’s trust policy.
A slide titled "Exam Facts" showing two numbered info cards. The first card reads "Environments map deployments to specific branches" and the second reads "Environment secrets sit behind both gates," each with brief subtext.
Links and references
Remember: combine branch restrictions, required reviewers, and environment-scoped secrets to build an auditable, secure deployment workflow. For cloud providers, prefer OIDC-based short-lived credentials over static keys.

Watch Video