Secrets in pipelines: where they leak and how to stop it

ExplainedCI/CDDevOps, Hands OnBy Cloud Hands On

The common ways pipeline credentials escape, and the order of fixes: no secret, a short-lived one, a scoped one.

Pipelines hold the keys to production, which makes them a favourite target. Secrets leak through logs (printed, encoded, or in error messages), artifacts and caches, pull requests from forks on badly set-up triggers, compromised actions that read the environment, and plain commits of a key into the repository.

Fix in order of strength. Best: no secret, using OIDC federation so the job gets a short-lived cloud token. Next: a short-lived, narrowly scoped secret in a vault (Azure Key Vault) fetched at run time. Then: an environment secret only production jobs receive, behind required reviewers. Around all of it: least-privilege permissions:, actions pinned by SHA, push protection, and rotation when anyone leaves or a leak is suspected.

Cost. Free: GitHub secrets, environments, push protection and OIDC cost nothing.

Use it when

How it works

Avoid
OIDC federation instead of stored cloud keys.
Scope
Environment secrets for production only.
Hide
Masking and add-mask for derived values.
Block
Push protection stops keys entering Git.
Rotate
Change keys on a schedule and after any leak.

Options

OIDC
No stored secret; best for Azure, AWS and Google Cloud.
Key Vault at run time
For secrets OIDC can't replace, such as third-party API keys.
GitHub environment secrets
Simple, scoped to approved jobs.

Example. A contractor's laptop with a cloned repository was stolen from Tollmere Logistics. Because deployments used OIDC and the repository held no keys, the only action needed was removing the contractor's GitHub access.

Don't confuse it with

Masking
Hides known values in logs after the fact.
Not having the secret
Nothing to hide or leak.

Words to know

OIDC federation
Trusting a pipeline's identity token instead of a stored password.
Rotation
Replacing a secret with a new one.
Push protection
GitHub blocking pushes that contain known secret formats.

Where to look

  1. Settings
  2. Secrets and variables
  3. Actions

Practise it

Read it in the guide, next to the tasks and labs.

Open in DevOps, Hands On

Keep going