DevSecOps

CI/CD Credential Theft Prevention

CI/CD pipelines are treasure troves of secrets -- cloud credentials, API keys, signing certificates. Preventing credential theft from build environments is critical to supply chain security.

Yukti Singhal
Security Researcher
6 min read

CI/CD pipelines are some of the most privileged environments in modern software organizations. They hold cloud provider credentials, package registry tokens, code signing keys, database passwords, and API keys for every service the application interacts with. When attackers target CI/CD credential theft, the payoff is massive.

Why CI/CD Environments Are Rich Targets

A typical CI/CD pipeline needs credentials to:

  • Pull source code from repositories.
  • Download dependencies from package registries.
  • Access cloud services for testing.
  • Push artifacts to container registries.
  • Deploy to staging and production environments.
  • Sign release artifacts.
  • Send notifications to chat systems.

Each of these requires credentials, and those credentials typically have broad permissions. A CI/CD environment might have production-level cloud access, the ability to publish to package registries, and access to signing keys -- all in one place.

Credential Theft Vectors

Malicious Dependencies

The Codecov breach (2021) demonstrated this perfectly. Attackers modified the Codecov bash uploader to exfiltrate environment variables from CI/CD pipelines. Since many organizations used Codecov in their pipelines, the attackers harvested credentials from thousands of build environments.

Any dependency that runs during the build process can access environment variables. This includes:

  • npm postinstall scripts
  • Python setup.py execution
  • Build plugins and extensions
  • Test frameworks and coverage tools
  • Linting tools and formatters

Pull Request Attacks

In many CI/CD configurations, pull requests from forks trigger pipeline execution. If the pipeline exposes secrets to PR builds, a malicious PR can exfiltrate them.

The attack is straightforward:

  1. Fork a target repository.
  2. Submit a PR that modifies the build script to print or exfiltrate secrets.
  3. The CI/CD system runs the modified build script with access to the repository's secrets.

Pipeline Configuration Injection

If an attacker can modify CI/CD configuration files (.github/workflows/*.yml, .gitlab-ci.yml, Jenkinsfile), they can:

  • Add steps that exfiltrate environment variables.
  • Modify build commands to include credential harvesting.
  • Change artifact destinations to attacker-controlled servers.
  • Add post-build steps that send secrets to external endpoints.

Compromised Build Images

CI/CD pipelines run in container images. If the build image is compromised, every build that uses it is compromised. The image might include:

  • Modified build tools that capture credentials.
  • Background processes that exfiltrate secrets.
  • Modified SSH clients that capture keys.

Cache Poisoning

CI/CD caches (dependency caches, build caches) can be poisoned to inject malicious code. If an attacker can write to the cache, subsequent builds will use the poisoned cache and execute malicious code that can access credentials.

Log Exposure

Build logs often contain secrets accidentally. A misconfigured step might print environment variables, and those logs are accessible to anyone with project access.

Real-World Incidents

Codecov (2021)

Attackers modified the Codecov bash uploader in their Docker image. The script was designed to collect environment variables and send them to an attacker-controlled server. The compromise went undetected for two months, during which credentials from thousands of CI/CD pipelines were exfiltrated. Affected organizations included Twitch, HashiCorp, and others.

Travis CI Secret Exposure (2021)

A Travis CI vulnerability exposed secrets from public repositories' build logs. Secrets that should have been masked were accessible in plaintext. The exposure affected thousands of repositories and required mass credential rotation.

GitHub Actions Secret Exfiltration Research (2022)

Researchers demonstrated multiple methods to exfiltrate secrets from GitHub Actions workflows, including through compromised actions, pull request triggers, and workflow injection via crafted issue titles or branch names.

Prevention Strategies

Principle of Least Privilege

Every credential in CI/CD should have the minimum permissions required:

  • Scoped tokens: Use tokens limited to specific operations (read-only for pulls, write-only for specific registries).
  • Time-limited credentials: Use short-lived tokens that expire quickly. AWS STS, GCP workload identity, and Azure managed identities provide temporary credentials.
  • Environment-specific credentials: Staging and production should use different credentials. Build environments should not have production access.

Secret Management

Stop storing secrets as environment variables when possible:

  • Use dedicated secret management tools (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault).
  • Inject secrets just-in-time rather than making them available for the entire pipeline.
  • Rotate secrets regularly and automatically.
  • Audit secret access to detect unusual patterns.

Pipeline Isolation

Isolate different pipeline stages:

  • Build isolation: Build steps shouldn't have access to deployment credentials.
  • PR isolation: Never expose secrets to pull request builds from forks.
  • Environment isolation: Dev, staging, and production pipelines should be completely separate with different credentials.

Prevent Secret Leakage in Logs

  • Use secret masking features provided by CI/CD platforms.
  • Scan build logs for accidental secret exposure.
  • Limit who can access build logs.
  • Retain logs for the minimum necessary period.

Dependency Execution Controls

Limit what dependencies can do during builds:

  • Disable install scripts where possible.
  • Use read-only file systems for dependency installation.
  • Network-restrict build environments so exfiltration is harder.
  • Monitor outbound connections from build environments.

OIDC and Keyless Authentication

Modern CI/CD platforms support OpenID Connect (OIDC) for authentication to cloud providers. Instead of storing long-lived credentials, the CI/CD platform presents an OIDC token that the cloud provider exchanges for short-lived credentials.

GitHub Actions, GitLab CI, and CircleCI all support OIDC. This eliminates stored secrets entirely for cloud provider authentication.

Pipeline-as-Code Review

Treat CI/CD configuration as security-critical code:

  • Require code review for all pipeline changes.
  • Use CODEOWNERS to restrict who can modify pipeline configurations.
  • Alert on pipeline configuration changes.
  • Pin action and plugin versions (don't use @latest or @main).

Runtime Monitoring

Monitor build environment behavior:

  • Alert on unexpected network connections.
  • Detect credential access patterns that deviate from normal.
  • Monitor for processes that shouldn't be running in build environments.

Credential Rotation

Assume credentials will eventually be compromised and plan accordingly:

  • Rotate all CI/CD credentials regularly (monthly at minimum).
  • Have a rapid rotation procedure for incident response.
  • Audit which credentials are in use and remove unused ones.

How Safeguard.sh Helps

Safeguard.sh strengthens CI/CD security by providing comprehensive visibility into your build pipeline's dependency chain. Through SBOM analysis, Safeguard.sh identifies every component that executes during your build process, flagging suspicious packages that might attempt credential exfiltration. The platform's policy gates can enforce security requirements before artifacts produced by your pipeline are accepted, ensuring that builds using compromised dependencies don't propagate downstream. Continuous monitoring alerts your team when dependencies with known credential-theft behavior appear in your supply chain, providing an early warning system that complements your pipeline hardening efforts.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.