For IT professionals and developers
Free for every learner
About 7 minutes

Lesson 03 of 7 · DevSecOps for IT professionals and developers

Secure CI Secrets Management

Protect pipeline credentials with scoped access, keep them out of source and logs, and respond promptly when a secret is exposed.

Anyone can read this lesson. Completion is saved to a learner account.

Lesson objective

By the end, you can

Given a fictional CI workflow, keep credentials out of source code and logs, restrict protected or scoped pipeline secrets to authorized jobs, and respond to exposure by promptly revoking or rotating the credential, notifying the appropriate security contact, and reviewing every place it may have appeared.

Practical instruction

Keep credentials out of code and logs

Keep credentials out of source code, artifacts, and logs

Never paste a credential into a workflow file, source file, command argument, test fixture, build artifact, or commit. Put approved pipeline secrets in the CI platform’s protected secret store, and refer to a secret by its configured name only in the job that needs it. Example names such as DEMO_DEPLOY_TOKEN below are labels, not credentials.

Do not print secrets or entire environments to debug a job. Avoid shell tracing and commands such as printenv when a secret may be present. Log masking can hide some matching output, but it cannot prevent code from using a credential or guarantee every transformed value is masked. Keep credentials out of logs in the first place.

Scope secrets to protected, authorized jobs

A secret should be available only to the job that needs it, for a protected branch or release environment, after the required review or approval. Keep secrets away from untrusted pull-request code and fork builds. Use read-only permissions for verification jobs and grant narrowly scoped access only to an authorized release job.

Prefer short-lived, narrowly scoped credentials or workload identity when your platform supports them. Restrict the credential to the required environment and actions, and review which branches, events, maintainers, and reusable workflows can cause that job to run. A secret store does not make broad job access safe.

Respond as though an exposed credential is compromised

Revoke or rotate the exposed credential promptly through its issuing system, then update authorized secret storage and verify the old value no longer works. Notify your security or incident-response contact and follow your organization’s incident process. Do not wait to prove that someone used the value before invalidating it.

Review where the value may have appeared: commits and repository history, pull-request diffs, job logs, artifacts, caches, copied messages, and downstream systems or accounts the credential could access. Remove visible copies where appropriate, preserve evidence according to incident guidance, and assess whether further credentials or actions are affected. Masking a log or deleting one visible copy alone does not restore a compromised secret; only revoking or rotating it does.

Safe hands-on exercise

Review a fictional CI secrets workflow

A fictional team reviews the sample workflow below before adopting it. Every value is a teaching placeholder; do not run the sample, connect it to a repository, enter a real credential, or send any information. The review and self-check run only in this browser.

# FICTIONAL SAMPLE ONLY — inspect, never execute
name: fictional-release-review
on: pull_request
jobs:
  verify:
    env:
      DEMO_CI_TOKEN: "FICTIONAL_PLACEHOLDER_NOT_A_CREDENTIAL"
    steps:
      - run: echo "$DEMO_CI_TOKEN"
      - run: printenv
  deploy:
    if: github.event_name == "pull_request"
    env:
      DEMO_DEPLOY_TOKEN: ${{ secrets.DEMO_DEPLOY_TOKEN }}
    steps:
      - run: ./fictional-deploy.sh

Apply the lesson

Identify unsafe secret handling in the sample, then select the safer controls and exposure response that should replace it.

Select the unsafe handling and safer controls

A complete review identifies all four safeguards and rejects each unsafe shortcut. You can change selections and check again; this does not contact or execute a pipeline. Use only the fictional placeholders shown. This browser-side self-check neither accepts credentials nor saves or transmits your selections.

Knowledge check

Check your understanding

A developer notices a credential in a CI log. Which response best protects the affected systems?

Choose the best answer