Skip to content

CI/CD Secrets Management Basics

Cloud & DevOps6 min read

Keep API keys and passwords out of code and logs. Learn where pipeline secrets leak, how to store them, and how to rotate after a leak.

In this article
  1. What counts as a secret in a pipeline
  2. Where secrets leak
  3. Choose where to store secrets
  4. Prefer short-lived credentials over stored keys
  5. Apply least privilege and separate environments
  6. Detect leaks and respond fast
  7. A practical checklist
  8. What to do next

Manage CI/CD secrets by keeping them out of source code, storing them in a dedicated secrets store or your pipeline's encrypted secret feature, giving each pipeline the minimum access it needs, using short-lived credentials where you can, and rotating anything that might have leaked. The most common failure is also the simplest: a password or API key committed to a repository. Once a secret is in version control history, treat it as compromised, no matter how quickly you delete the file.

This guide is for developers and team leads who build and deploy software. It explains what counts as a secret, where they leak, the options for storing them, and a practical checklist you can apply to a pipeline this week.

What counts as a secret in a pipeline

A secret is any value that grants access or proves identity. In a typical pipeline that includes:

  • Cloud access keys and service account credentials.
  • Database passwords and connection strings.
  • API keys for payment, email, mapping or other third-party services.
  • Signing keys and certificates for apps and packages.
  • Registry and package manager tokens.
  • SSH private keys and deployment tokens.
  • Webhook signing secrets and encryption keys.

Configuration such as a region name or a feature flag is not secret. Separating the two keeps your secret list short and manageable. A short list is easier to protect, rotate and audit.

Where secrets leak

Knowing the usual leak points tells you where to look first:

  1. Source code and history. Hard-coded keys, committed .env files and test credentials. Deleting the line does not remove it from earlier commits.
  2. Build logs. A script that prints environment variables, or a failing command that echoes a connection string, can expose secrets to everyone who can read logs.
  3. Container images. Secrets copied into an image layer stay there, even if a later step deletes them, and anyone who pulls the image can extract them.
  4. Artifacts and caches. Build outputs, test reports and caches that include config files.
  5. Forks and pull requests. A workflow that runs untrusted code from a pull request with access to secrets lets a contributor steal them.
  6. Shared accounts and chat. Keys pasted into messages, tickets or documents.
  7. Over-broad tokens. A single admin key used by every pipeline means one leak exposes everything.

Many organisations also discover leaks through third parties, such as a public repository scan, rather than their own checks. Assume that anything which reaches a public place will be found by automated scanners quickly.

Choose where to store secrets

You have several options, and the right one depends on scale and platform.

ApproachGood forWatch out for
CI/CD platform secret store (for example the encrypted secrets in your pipeline tool)Small teams, simple pipelinesScope and access rules differ per platform, and values are often long-lived
Cloud secrets manager (AWS, Azure or Google Cloud offerings)Teams already on one cloud, shared secrets across servicesNeeds IAM design and some cost, plus a way for the pipeline to authenticate
Dedicated secrets platformLarger or multi-cloud estates, dynamic credentialsAnother system to run and secure
Encrypted secrets in the repositoryTeams who want config as codeKey management for the encryption key becomes the new problem

Whatever you pick, never fall back to plain text in the repository, the image or the wiki. For smaller teams, starting with the pipeline's built-in secret store is entirely reasonable. Move to a cloud secrets manager when you need central rotation, audit trails or sharing across several applications. Check each product's current documentation for exact features.

Prefer short-lived credentials over stored keys

The safest secret is one that does not exist for long, or does not exist at all. Many platforms now support identity federation between your pipeline and your cloud provider. The pipeline proves who it is with a short-lived signed token, and the cloud issues temporary credentials that expire within minutes or hours. No long-lived cloud key sits in your CI settings waiting to be stolen.

The benefits are significant:

  • There is nothing permanent to leak or rotate on a schedule.
  • Access can be limited to a specific repository, branch or environment.
  • Audit logs show which pipeline run obtained which credentials.

The feature is often called OpenID Connect federation or workload identity, though names vary between providers. Read your provider's documentation for the current setup steps. Pair it with the infrastructure habits in our guide to Terraform and infrastructure as code, so the trust relationships themselves are reviewed and versioned.

Apply least privilege and separate environments

Even a well-stored secret does harm if it is too powerful. Practical rules:

  • One credential per purpose. A deploy token should not also read the production database.
  • Separate dev, test and production. Production secrets should be reachable only from production deployment jobs, ideally behind a manual approval.
  • Restrict by branch or tag. Only protected branches should be able to use deployment secrets.
  • Limit who can edit pipelines. Anyone who can change a workflow file can often extract secrets that workflow can read. Require review for pipeline changes.
  • Use read-only access where possible. A job that only pulls packages does not need write permission.

This is the same thinking behind zero trust: give each identity only what it needs, and verify it each time. It also reduces the damage from the situation described in our GitHub Actions pipeline guide, where one compromised workflow could otherwise reach everything.

Detect leaks and respond fast

Prevention will fail occasionally, so build detection in:

  1. Scan before commit. Use a secret scanning tool as a pre-commit hook, so mistakes are caught on the developer's machine.
  2. Scan in the pipeline. Fail the build if a secret pattern appears in new code. Many repository hosts offer built-in secret scanning and push protection.
  3. Scan history and images. Run a one-off scan of existing repositories and container images, since old leaks are still live.
  4. Mask logs. Use the platform's masking feature and avoid printing environment variables. Do not enable verbose debugging on jobs that handle secrets without thinking.
  5. Monitor usage. Alert on unusual use of cloud keys, such as calls from unexpected locations or services.

When a secret leaks, act in this order:

  1. Revoke or rotate the secret immediately. Do not wait to clean up the repository first.
  2. Check logs for any use of the credential during the exposure window.
  3. Remove the secret from the code and, where practical, rewrite history, understanding that copies may already exist elsewhere.
  4. Find out how it got there and fix the cause.
  5. If personal data may have been accessed, follow your incident response plan and consider your GDPR obligations. This is not legal advice, so confirm the current position with your data protection contact and the Data Protection Commission guidance.

A practical checklist

  • List every secret your pipelines use, who owns it and where it is stored.
  • Remove all secrets from code, images and shared documents.
  • Move each secret into a proper store with restricted access.
  • Replace long-lived cloud keys with federated, short-lived credentials where supported.
  • Give each pipeline and environment its own narrowly scoped credential.
  • Protect the branches and workflows that can touch production secrets.
  • Turn on secret scanning locally and in the repository host.
  • Write down how to rotate each secret, and practise it once.
  • Review access and unused secrets every quarter.

Rotation deserves one more note: a rotation that has never been tested often fails when it matters. Practise it in a calm moment, in the same way you would test a backup, as described in why untested backups fail. Reviewing the code for related issues with a secure code review checklist also catches many of these mistakes before they ship.

What to do next

Pick one pipeline, perhaps your most important one, and walk through the checklist. Most teams find a handful of quick wins: a forgotten key in an old repository, a token with far more access than it needs, a build log that prints too much. Fix those first, then extend the approach across your other projects.

If you would like help with this, the CloudWiss team in Dublin can talk it through, including how to set up federated credentials and secret scanning. Read more about our cloud and DevOps services.

Share this article

General educational information, not legal or professional advice for your specific situation.

Frequently asked questions

Is it enough to delete a committed secret?

No. It remains in git history and may already be copied or scanned. Revoke and rotate it straight away, then clean up the repository.

What are short-lived credentials?

They are temporary tokens issued for a single job or session that expire automatically. Federation between your pipeline and cloud provider can issue them without storing long-lived keys.

Do I need a dedicated secrets manager?

Not always. Small teams can start with the pipeline's encrypted secrets. A secrets manager helps when you need central rotation, audit trails or sharing across many apps.

How often should secrets be rotated?

It depends on sensitivity and what your provider supports. Rotate immediately after any suspected leak, and on a regular schedule for long-lived keys. Prefer short-lived credentials so rotation is automatic.

Keep reading

Let’s build it

Ready to build with CloudWiss?

Tell us what you want to build, move to the cloud or keep running. We reply with a clear next step.