0Pricing
DevOps Bootcamp · Lesson

Managing Secrets and Environment Variables

Safely use GitHub Actions secrets, variables, and environments to keep credentials out of your code and control deployments.

Managing Secrets and Environment Variables is a free DevOps Bootcamp lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Secrets Need Care

Pipelines need tokens and passwords to reach registries and cloud targets. Hardcoding them leaks them to anyone with repo access — that’s what secrets prevent.

Where Secrets Live

You add secrets in repository, organization, or environment settings. They’re encrypted at rest and exposed to workflows only as masked values.

Using a Secret

Reference a secret through the secrets context, then pass it into a step as an env var or action input. Here it feeds a deploy script.

steps:
  - name: Deploy
    env:
      API_TOKEN: ${{ secrets.API_TOKEN }}
    run: ./deploy.sh

Secrets Are Masked

GitHub auto-masks secrets in logs as ***. Even so, never echo or persist one — transforms like base64 can slip past the mask and leak it.

Variables vs Secrets

For non-sensitive config like a region or build flag, use variables via the vars context. They’re visible in the UI, which is fine when nothing’s secret.

env:
  REGION: ${{ vars.AWS_REGION }}

The Default GITHUB_TOKEN

Every run gets an automatic GITHUB_TOKEN to authenticate to the repo. Scope it tightly with the permissions key — least privilege.

permissions:
  contents: read
  pull-requests: write

Environments

An environment like staging or production groups secrets and adds protection rules — required reviewers, wait timers, branch limits — before a deploy runs.

jobs:
  deploy:
    environment: production
    runs-on: ubuntu-latest

Required Reviewers

With a protected environment, a deploy job pauses until a designated reviewer approves — a deliberate human gate in front of production.

Forked PR Safety

Secrets are never passed to workflows from forked PRs, so an untrusted contributor can’t steal them. Design CI so fork PRs need no secrets.

Rotating Secrets

Treat every secret as rotatable. When one leaks or expires, just update it in settings — the next run picks up the new value, zero code changes.

Best Practices Summary

The playbook: secrets for sensitive values, variables for the rest, a tightly scoped GITHUB_TOKEN, environments guarding production, and never log a secret.

Quick Check

Secret or variable, masked or visible — which goes where?

Recap

You can manage secrets and variables safely now: store them encrypted, read via the secrets context, scope the token, and gate deploys behind environments.

Frequently asked questions

Is the “Managing Secrets and Environment Variables” lesson free?

Yes — the full text of “Managing Secrets and Environment Variables” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Managing Secrets and Environment Variables”?

Safely use GitHub Actions secrets, variables, and environments to keep credentials out of your code and control deployments. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Managing Secrets and Environment Variables” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What is CI/CD and DevOps?
  2. GitHub Actions Core Concepts
  3. Your First GitHub Workflow
  4. Managing Secrets and Environment Variables
← Back to DevOps Bootcamp