Cloud Security

Your Build Server Knows Every Secret

Jonas LindqvistJonas LindqvistCloud Security Architect27 Apr 20215 min read2031 views
Editorial cover for “Your Build Server Knows Every Secret”

On April 15, Codecov, a code-coverage service used by a great many software teams, disclosed that a third party had altered its Bash Uploader script. Starting January 31, the script was periodically modified so that it quietly sent the environment variables of the CI jobs running it to a server outside Codecov's control. Nobody noticed for two months. Then, on April 1, a customer compared the script's checksum against the one published on GitHub, found a mismatch and reported it.

A CI job's environment variables are where teams keep the keys to everything: cloud credentials, deploy tokens, package registry tokens, database passwords and signing keys. On April 22, HashiCorp confirmed that the GPG private key it uses to sign the checksums for its product downloads was among the exposed secrets. It has rotated the key and says it found no evidence of misuse. Most affected organizations will never publish a bulletin, so here is the advice we are giving our own clients.

How a coverage report became a credential leak

Codecov says the attacker got in through an error in its Docker image creation process, which let them extract a credential that allowed changes to the script. The change itself was small: collect the environment and the git remote information, send it elsewhere, and suppress any error that might draw attention.

How the leak worked matters more than the line of code:

  • A script fetched live from a vendor URL on every build, without pinning.
  • Executed inside the job that holds the secrets, because that is where the coverage files are.
  • With unrestricted outbound network access, because build runners are usually allowed to talk to anything.

The Bash Uploader also sat underneath Codecov's GitHub Action, CircleCI Orb and Bitrise Step, so teams that never ran it by hand were in scope as well.

None of those choices was careless. They are what most quick-start guides recommend. The result was that the most trivial step in the pipeline, uploading a coverage report, ran with the most sensitive secrets the organization owned.

If you used it between January 31 and April 1

Codecov's guidance is to treat the CI environment as exposed and re-roll every credential in it. We agree, and we would add an order of work:

  1. List what was there. Codecov suggests running env in the pipeline to see exactly which variables a job could read. Include variables inherited from organization-level or group-level settings, because those are the ones people forget.
  2. Rotate by blast radius. Rotate cloud provider keys and deploy credentials first. Package publishing tokens and signing keys come next, then database and third-party API tokens. An administrator-level cloud key sitting in a CI variable is the case that turns into a breach.
  3. Audit how each key was used. For every credential, pull its usage history since January 31 from cloud audit logs, registry publish events and git push logs. Look for use from addresses that are not your runners. Rotation stops future misuse, but only the logs can show you past misuse.
  4. Check what you shipped. If a publishing token or signing key was exposed, confirm that every artifact released since January 31 matches what you built. HashiCorp says it validated its existing releases and re-signed them with a new key, which is a reasonable template.

The structural fixes

Rotating keys closes this incident. These five changes deal with the whole category.

Short-lived credentials instead of stored ones. A long-lived access key in a pipeline variable keeps working wherever it is copied to, until somebody notices. A secrets manager can instead issue each job credentials that are scoped to that job and expire within the hour. That turns a leak like this one into a nuisance.

Secrets per step, not per pipeline. The coverage upload needs a coverage token. It does not need your production deploy key. Split jobs so that third-party tooling runs where the sensitive secrets are absent.

Pin and verify what you execute. Vendor the script into your repository, or pin a specific version and check its hash against a value you stored yourself. The customer who caught this compromise did exactly that: the hash they trusted came from a different place than the file they downloaded.

Egress control on runners. A build job should talk to your source host, your registries, your cloud and a short list of named services. If you run self-hosted runners, you can have an outbound allow-list in place this quarter. A build runner connecting to an unfamiliar destination is one of the most reliable alerts you can write.

Signing keys out of CI memory. If a signing key is readable as an environment variable, every tool in the job can read it. Keep signing keys in a key management service or hardware module that signs on request, so the key itself never enters the build.

Why this is a mid-market problem

It is tempting to file this under "software companies". But most of the organizations we work with now have a pipeline somewhere: the web team's deploys, the data team's scheduled jobs, an integration someone built for the ERP. Security rarely reviews those pipelines because they belong to engineering.

We have reviewed client pipelines over the past ten days, and the most common finding was ordinary. One set of secrets was available to every step, including steps that pull code from the internet at runtime. Several pipelines held cloud credentials with full administrative rights, created once by whoever set the pipeline up and never looked at again.

Your build server is the most trusted machine you own and the one you look at least. Give it fewer secrets, and make it ask for the rest.

Sources

#CI/CD#secrets management#software supply chain#Codecov#egress#cloud credentials
Jonas Lindqvist

About the author

Jonas LindqvistCloud Security Architect

Jonas spent six years as a platform engineer before crossing over to security, which is why his hardening guidance actually survives contact with a real DevOps team. He is a CISSP with the AWS and Azure security specialty certs, and he wrote the landing-zone baseline we now deploy for every cloud-native client. His rule of thumb: if a control is not in code, it does not exist.

Cloud architecture reviewIAM & identity securityInfrastructure as codeKubernetes security

Discussion(0)

No comments yet — the floor is yours.

Join the discussion

Your email stays private; we only use it to distinguish real readers from bots.

open a channel

The best time to harden your defenses was yesterday.

The second-best time is right now. Tell us what keeps you up at night — we answer within one business day.