· Sourceplane engineering · Security · 4 min read

CI/CD without long-lived secrets

A cloud key pasted into CI settings years ago is one of the most common, and most dangerous, things in a small company's infrastructure. Short-lived, federated credentials remove it entirely.

Look in the settings of almost any CI system at a growing company and you will find them: cloud access keys, API tokens and deploy credentials, pasted in when the pipeline was first set up. They never expire. Nobody remembers exactly what they can do. They are copied into new repositories when new pipelines are created. Rotating them would mean finding every place they are used, so nobody does.

These credentials are some of the most valuable things an attacker can find, and CI systems are a common place to find them: a compromised dependency, a malicious pull request that prints environment variables, a leaked log. Removing them is one of the highest-value security changes a team can make, and it is usually less work than people expect.

Federated identity instead of stored keys

Modern CI systems can prove who they are without a stored secret. Each pipeline run is issued a short-lived identity token, signed by the CI provider, that states which repository, branch and workflow the run belongs to. Cloud providers and many other services can be configured to trust those tokens and exchange them for temporary credentials.

The result:

  • Nothing to store. There is no long-lived key in CI settings to leak.
  • Short-lived credentials. The temporary credentials expire in minutes or hours, so a leaked one is worth very little.
  • Narrow trust. The cloud side decides exactly which repositories, branches and environments may assume which roles.
  • Clear audit. Every credential issued is tied to a specific pipeline run.

This is supported by the major CI systems and cloud providers, and it is usually called OIDC federation or workload identity.

Scope trust tightly

The value of federation depends on how tightly the trust is scoped. Good defaults:

  • Per repository. A role trusts one repository, not the whole organisation.
  • Per branch or environment. Only the main branch, or a protected deployment environment, can assume the role that deploys to production. Pull request runs get a role that can only read or plan.
  • Per purpose. Separate roles for planning infrastructure, applying it and deploying applications, each with only the permissions it needs.

A pull request from a fork should not be able to obtain production credentials at all. With branch-scoped trust it simply cannot.

Brokered credentials for everything else

Not every service supports federation directly. For those, a credential broker can hold the long-lived secret centrally and mint short-lived, narrowly scoped tokens for each run. The pipeline asks the broker at run time, receives a token valid for the job, and nothing permanent ever lives in CI settings. The broker’s own access is protected by the same federated identity.

Secrets that must exist

Some secrets will remain, such as third-party API keys your application needs at runtime. For those:

  • Keep them in a secrets manager, not in CI settings or environment files.
  • Scope them per environment and per service.
  • Inject them at deploy time, and never print them to logs.
  • Rotate them on a schedule, which is easy when there is only one place they live.
  • Scan every change for accidentally committed secrets, and block the merge if one is found.

A migration plan

For a team starting from stored keys, a realistic order is:

  1. Inventory. List every secret in CI settings and what uses it.
  2. Federate the cloud first. Replace cloud access keys with federated roles, starting with production deploys.
  3. Split roles. Separate read and plan roles for pull requests from apply and deploy roles for the main branch.
  4. Broker the rest. Move remaining third-party tokens behind a broker or a secrets manager.
  5. Delete the old keys. Revoke them at the provider, not just in CI settings.
  6. Prevent regressions. Add secret scanning to every repository and a policy that rejects new long-lived keys.

Most teams can complete the first three steps in a few weeks. The risk reduction is immediate.


How we help. We move pipelines to federated, short-lived credentials and set up secrets management and scanning with your team. See security and guardrails, or talk to an engineer.

Share:
All articles