teluzia.Cloud Engineer · Day 108
CHAPTER 16 · CI/CD AND AUTOMATED DEPLOYMENTS

Secrets and environment management

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Environment controls are a deployment gate, while secrets are keys behind the gate; ordinary variables are labels, not protected keys. GitHub Actions secrets hold sensitive values with access rules and masking behavior; configuration variables are nonsecret settings. Masking is not a guarantee against transformed leakage. Do not echo secrets, place them in artifacts, or pass untrusted input into shell commands unsafely. Environments can scope secrets and require configured protection rules before deployment jobs proceed. Branch restrictions and reviewers should match the release policy. An environment name alone does not create a complete governance process; configure and verify the actual protections and entitlement limits for your repository.

Think of it this way

Environment controls are a deployment gate, while secrets are keys behind the gate; ordinary variables are labels, not protected keys.

TOPIC 01 / 03Step by step

Secrets and ordinary variables

GitHub Actions secrets hold sensitive values with access rules and masking behavior; configuration variables are nonsecret settings. Masking is not a guarantee against transformed leakage. Do not echo secrets, place them in artifacts, or pass untrusted input into shell commands unsafely. For example, a nonsecret region is a variable; a credential, if unavoidable, belongs in a protected secret rather than YAML text.

WORKED EXAMPLE
A nonsecret region is a variable; a credential, if unavoidable, belongs in a protected secret rather than YAML text.

A workflow needs a region name and a credential. The region is nonsecret configuration and can appear in ordinary variables. The credential requires a controlled secret reference or, preferably where supported, a temporary identity flow. The job should receive it only when needed and never echo it or copy it into an artifact.

A variable stores ordinary configuration. A secret is a sensitive value with access and masking behavior. Masking hides some recognized log occurrences, not every transformed representation. Encoding, slicing, or sending the value to another endpoint can still leak it. Treat diagnostics as a potential exposure path. A fake credential in a teaching draft is not proof that repository secret configuration exists. Avoid passing secrets to untrusted code or broadly scoped third-party actions. Moving a value into a secret store improves source hygiene but does not remove the need for limited authority, rotation, and careful runtime handling.

Why this matters

A nonsecret region is a variable; a credential, if unavoidable, belongs in a protected secret rather than YAML text.

A common trap

Do not overlook this operational distinction: Do not echo secrets, place them in artifacts, or pass untrusted input into shell commands unsafely.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Secrets and ordinary variables

GitHub Actions secrets hold sensitive values with access rules and masking behavior; configuration variables are nonsecret settings. Masking is not a guarantee against transformed leakage. Do not echo secrets, place them in artifacts, or pass untrusted input into shell commands unsafely. For example, a nonsecret region is a variable; a credential, if unavoidable, belongs in a protected secret rather than YAML text.

WORKED EXAMPLE
A nonsecret region is a variable; a credential, if unavoidable, belongs in a protected secret rather than YAML text.

A workflow needs a region name and a credential. The region is nonsecret configuration and can appear in ordinary variables. The credential requires a controlled secret reference or, preferably where supported, a temporary identity flow. The job should receive it only when needed and never echo it or copy it into an artifact.

A variable stores ordinary configuration. A secret is a sensitive value with access and masking behavior. Masking hides some recognized log occurrences, not every transformed representation. Encoding, slicing, or sending the value to another endpoint can still leak it. Treat diagnostics as a potential exposure path. A fake credential in a teaching draft is not proof that repository secret configuration exists. Avoid passing secrets to untrusted code or broadly scoped third-party actions. Moving a value into a secret store improves source hygiene but does not remove the need for limited authority, rotation, and careful runtime handling.

Why this matters

A nonsecret region is a variable; a credential, if unavoidable, belongs in a protected secret rather than YAML text.

A common trap

Do not overlook this operational distinction: Do not echo secrets, place them in artifacts, or pass untrusted input into shell commands unsafely.

Environment protection

Environments can scope secrets and require configured protection rules before deployment jobs proceed. Branch restrictions and reviewers should match the release policy. An environment name alone does not create a complete governance process; configure and verify the actual protections and entitlement limits for your repository. For example, the production job references an environment configured to accept only selected branches and require an appropriate reviewer.

WORKED EXAMPLE
The production job references an environment configured to accept only selected branches and require an appropriate reviewer.

A deployment job references the production environment. GitHub applies that environment's configured protections, which may include reviewers, branch rules, or supported custom checks. Only after relevant conditions are satisfied should the job proceed with its allowed deployment context. Simply naming an environment production does not automatically create all these controls.

An environment represents a deployment destination and associated settings. A protection rule defines a gate. A deployment branch policy narrows eligible source refs. Feature availability depends on repository and account capabilities, so verify the actual settings rather than assume them. Environment secrets and ordinary repository secrets have different intended scopes. Keep approval focused on a concrete release identity and meaningful evidence, not a vague future action. A gate is only useful if the underlying trigger and workflow cannot bypass it through another privileged job. Inventory alternative release paths and restrict their credentials too.

Why this matters

The production job references an environment configured to accept only selected branches and require an appropriate reviewer.

A common trap

Do not overlook this operational distinction: An environment name alone does not create a complete governance process; configure and verify the actual protections and entitlement limits for your repository.

Untrusted input and permissions

Restrict token permissions and avoid exposing sensitive context to untrusted code. Pull-request behavior depends on event and origin. Treat issue text, branch names, and event fields as data, not direct shell program fragments. Prefer safe argument or environment handling and reviewed action implementations. For example, pass a branch-name input through an environment variable and quote it rather than interpolate it as executable shell text.

WORKED EXAMPLE
Pass a branch-name input through an environment variable and quote it rather than interpolate it as executable shell text.

An issue title contains characters interpreted by a shell. A workflow directly interpolates that text into a run command, so what appeared to be display data can become executable syntax. Use supported safe data handling, quoted environment variables, or structured action inputs, while still considering the receiving program's argument behavior.

Untrusted input is data controlled outside the trusted workflow author. Injection changes intended code or command interpretation. Token permissions define the authority available to the job's GitHub token. Minimize those permissions and avoid exposing cloud credentials to event-controlled scripts. The risk is not limited to passwords: repository write access or internal network reach can also be valuable authority. Review pull_request versus pull_request_target behavior carefully before running contributor code. A trusted workflow file can still execute untrusted checked-out content, so examine the complete data and code path rather than only the workflow's author.

Why this matters

Pass a branch-name input through an environment variable and quote it rather than interpolate it as executable shell text.

A common trap

Do not overlook this operational distinction: Prefer safe argument or environment handling and reviewed action implementations.

KEEP THESE WITH YOU

Today’s takeaways

Secrets and ordinary variables: GitHub Actions secrets hold sensitive values with access rules and masking behavior; configuration variables are nonsecret settings. Masking is not a guarantee against transformed leakage. Do not echo secrets, place them in artifacts, or pass untrusted input into shell commands unsafely.

Environment protection: Environments can scope secrets and require configured protection rules before deployment jobs proceed. Branch restrictions and reviewers should match the release policy. An environment name alone does not create a complete governance process; configure and verify the actual protections and entitlement limits for your repository.

Untrusted input and permissions: Restrict token permissions and avoid exposing sensitive context to untrusted code. Pull-request behavior depends on event and origin. Treat issue text, branch names, and event fields as data, not direct shell program fragments. Prefer safe argument or environment handling and reviewed action implementations.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed