0Pricing
DevOps Bootcamp · Lesson

Secret Management with GitHub

Deep dive into securely storing and accessing sensitive credentials using GitHub Secrets and OpenID Connect (OIDC).

Secret Management with GitHub is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 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 Secure Secret Management?

In any software project, you often need to use sensitive information like API keys, database credentials, or access tokens. Storing these directly in your code or repository is a major security risk.

Secret management is the practice of securely storing and managing these sensitive pieces of data. It ensures that only authorized systems and users can access them, preventing unauthorized exposure.

What are GitHub Secrets?

GitHub provides a secure way to store sensitive information called GitHub Secrets. These are encrypted environment variables that you can use in your GitHub Actions workflows.

  • They are not written to the logs by default.
  • They are not visible in the UI after creation.
  • They are accessible only by selected workflows.

This keeps your credentials safe from being accidentally exposed.

Setting Up Repository Secrets

You can define secrets at different levels: repository, environment, or organization. Most commonly, you'll start with repository secrets.

To create one:

  1. Go to your repository's Settings tab.
  2. Navigate to Secrets and variables > Actions.
  3. Click New repository secret.

Give it a unique name (e.g., API_KEY) and paste your secret value.

Accessing Secrets in Workflows

Once a secret is defined, you can use it in your workflow YAML files. GitHub Actions automatically injects secrets as environment variables into your jobs.

You access them using the ${{ secrets.SECRET_NAME }} context. This script simulates a step that would use such a secret. To run this, imagine MY_API_KEY is set as an environment variable by GitHub Actions.

#!/bin/bash
# This script simulates a workflow step
# where a secret is passed as an environment variable.

echo "Attempting to use an API key..."

# In a real GitHub Action, MY_API_KEY would be
# set by ${{ secrets.MY_API_KEY }} in the workflow YAML.

if [ -z "$MY_API_KEY" ]; then
  echo "Error: MY_API_KEY is not set!"
  echo "Please define it as a secret in your workflow."
else
  echo "Successfully accessed API key (partially shown): ${MY_API_KEY:0:5}..."
fi

Broader Secret Scopes

Beyond repository secrets, GitHub offers two more powerful scopes:

  • Organization Secrets: Available to multiple repositories within an organization. Useful for secrets shared across many projects (e.g., a company-wide deployment token).
  • Environment Secrets: Tied to specific deployment environments (e.g., staging, production). These can have protection rules, like requiring manual approval before deployment.

Always use the smallest scope necessary for maximum security.

What is OpenID Connect (OIDC)?

OpenID Connect (OIDC) is an authentication layer built on top of OAuth 2.0. It's a standard that allows clients to verify the identity of an end-user based on the authentication performed by an authorization server.

In CI/CD, OIDC allows your workflows to securely authenticate with cloud providers (like AWS, Azure, GCP) without needing to store long-lived credentials (like API keys) as GitHub Secrets.

How OIDC Works with Actions

GitHub Actions can act as an OIDC provider. When a workflow runs, GitHub generates a unique, short-lived OIDC token for that specific job.

This token contains verifiable claims about the workflow, such as the repository, branch, and job ID. Cloud providers can then be configured to trust tokens issued by GitHub and grant temporary access based on these claims.

Key Benefits of OIDC

Using OIDC with GitHub Actions offers significant security advantages:

  • No Long-Lived Credentials: You don't store static cloud API keys in GitHub Secrets.
  • Reduced Risk: Short-lived tokens minimize the impact if a token is ever compromised.
  • Fine-Grained Access: Cloud roles can be mapped to specific workflow conditions (e.g., only allow deployment from the main branch).
  • Auditing: Easier to track who did what, as identities are tied to the workflow run.

Integrating OIDC with Cloud

To use OIDC, you need to configure your cloud provider (e.g., AWS IAM, Azure AD, GCP IAM) to trust GitHub's OIDC issuer.

This typically involves:

  1. Setting up an Identity Provider (IdP) in your cloud account.
  2. Defining a Role/Policy that grants specific permissions.
  3. Adding a "Trust Policy" to the role, allowing GitHub's OIDC tokens to assume it, often with conditions based on token claims (e.g., only from a specific repo).

The workflow then requests a token and uses it to authenticate.

Quick Check: Secure Access

You've learned about GitHub Secrets for storing sensitive data and OpenID Connect for credential-less cloud authentication.

Which of the following statements about GitHub Actions secret management are TRUE?

Recap: Secure Your Credentials

Great job! You've learned how to securely manage sensitive data in your CI/CD pipelines.

  • GitHub Secrets provide encrypted storage for API keys and tokens within your repository, organization, or specific environments.
  • OpenID Connect (OIDC) offers an even more secure way to authenticate with cloud providers by using short-lived, verifiable tokens instead of static credentials.

These practices are crucial for building robust and secure DevOps pipelines.

Frequently asked questions

Is the “Secret Management with GitHub” lesson free?

Yes — the full text of “Secret Management with GitHub” 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 “Secret Management with GitHub”?

Deep dive into securely storing and accessing sensitive credentials using GitHub Secrets and OpenID Connect (OIDC). 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Secret Management with GitHub” 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. Security Best Practices in CI/CD
  2. Secret Management with GitHub
  3. Static Application Security Testing (SAST)
  4. Dependency and Supply Chain Security (SCA)
← Back to DevOps Bootcamp