Infra Stack Review

Managing Secrets Injection Across Multiple Deployment Environments

Unscoped credentials across environments turn leaked secrets into organization-wide breaches.

· 12 min read · Updated
Cover illustration for “Managing Secrets Injection Across Multiple Deployment Environments”
CI/CD Workflows · August 6, 2026 · 12 min read · 2,626 words

When an architecture gives every environment the same undifferentiated access to the same credentials, you get secrets sprawl, built without an environment model at all, so that dev, staging, production, feature branches, and CI runners all end up holding keys that open the same doors.

The pattern spreads through replication. As teams add environments, someone has to decide how each new one gets its credentials. Scoping each environment separately takes planning and policy work. But copying an existing secret into a new.env file takes thirty seconds. Without a deliberate model for how environments relate to each other, copying wins every time, and every copy is a new place a credential can leak from. The more environments a team spins up, the wider the blast radius when any single one of them is compromised. OWASP's Secrets Management Cheat Sheet points at a specific consequence of this pattern: when multiple services share the same secret, figuring out which one leaked it, or which one got compromised first, becomes genuinely hard to trace.

The numbers behind this are not small. GitGuardian's State of Secrets Sprawl 2026 found that hardcoded secrets showing up in public GitHub commits grew 34% year over year in 2025, the largest single-year jump the report has recorded. The same research found that more than half of the credentials confirmed exposed back in 2022 were still valid when retested four years later. That second number says more about the nature of the problem than the first. A growth rate shows the problem getting bigger. If a stale credential still works four years after it leaked, that shows rotation does not happen, not as teams actually practice it. That reflects a governance failure, not a missing tool.

Two newer forces are making the sprawl worse. AI-assisted coding tools are now part of how most teams ship software, and GitGuardian's 2026 research found that AI-assisted commits expose secrets at more than twice the rate of commits written without AI help. A second surface has opened up alongside this, because Model Context Protocol configuration files, which define how an AI agent connects to databases, APIs, and other services, need credentials to do that connecting. Thousands of these configuration files turned up on public GitHub in 2025 with exposed credentials sitting inside them, and a significant share of those credentials were confirmed still valid. On top of this, the Shai-Hulud 2 attack found that most of the secret occurrences recovered from compromised machines traced back to CI/CD runners, not developer laptops. The pipeline, not the person, is where the exposure concentrates.

Treating Each Environment as a First-Class Citizen

Giving an environment first-class status means three concrete things have to be true for it: it holds its own scoped credentials, it runs on its own rotation schedule, and it produces its own independent audit trail. If even one of the three is missing, a leaked credential, once contained, can still spread across every environment the organization runs.

Scoped credentials come first because they set the outer limit on damage. A credential that works in dev should never work in production. So if environments share credentials, a leak anywhere becomes a leak everywhere, and environment boundaries exist on paper only. OWASP frames this as the Least Privilege principle applied directly to secrets management: engineers should not have blanket access to every secret sitting in the secrets manager, and the access controls that govern who can read what need to be fine-grained down to the level of individual objects, not broad categories.

Rotation schedules come second, and you need to vary them by environment instead of following one company-wide calendar. A credential protecting a production database carries more risk than the same type of credential in a dev sandbox, so it should rotate more often. JumpServer's 2026 guide lays out recommended rotation cadences by secret type: cloud API keys, database passwords, and OAuth tokens each carry their own suggested frequency. The point that matters here is that those frequencies need to be set per environment on top of per secret type. Treating a production OAuth token and a dev OAuth token identically because they're "the same kind of secret" throws away the one variable that actually predicts risk: where the secret lives.

Audit trails come third, and you need them most after something has already gone wrong. The audit log for staging needs to be queryable on its own, separately from the log for production. When the two get mixed together, reconstructing how an attacker moved from one system to another after a breach becomes close to impossible, because the trail of who-accessed-what-when no longer maps cleanly onto which environment was actually touched. Credentials, rotation, and audit trails are not three separate best practices that happen to be convenient. They are the minimum structure that makes "environment" mean something at all, rather than just a label in a config file. The sections that follow walk through how to build each piece.

Centralized storage with environment-scoped paths as the structural foundation

Centralized storage is the prerequisite that makes the three-part model possible at all, and environment-scoped paths are what turn centralization into per-environment discipline rather than a single shared bucket of credentials. Without a central store, there is no single place to enforce scoping, rotation, or auditing. With one, but without path-level scoping inside it, the store just becomes one big pile of secrets that happens to live in one place instead of many.

Cloud-native secret managers handle the single-cloud case well, but they run into a real limit once an organization spans more than one cloud. Akeyless's 2026 guide describes tools like AWS Secrets Manager and Azure Key Vault as "islands of identity": they don't talk to each other. Credentials end up siloed inside separate clouds, or buried in CI/CD variables outside either system, and that fragmentation creates blind spots where an ungoverned credential can quietly provide a path into sensitive data. Running native tools across more than one cloud also means separate clusters, custom replication work, and cloud-specific policy configurations, so every environment you add widens the governance gap instead of closing it.

Path-based scoping fixes the fragmentation by making environment boundaries explicit and enforceable at the policy layer. If a single vault holds paths like dev/service-name/secret, staging/service-name/secret, and production/service-name/secret, a policy engine can check environment isolation automatically, instead of depending on an application developer remembering which variable goes where. OWASP's guidance backs this up directly: secrets management should be standardized across lifecycle management, authentication, authorization, and accounting, and it should be obvious to anyone in the organization what a given secret is used for and where to find it. A clean path structure delivers both of those at once.

One case from the research shows what this looks like once it's working. A SaaS startup pursuing SOC 2 compliance had been embedding database passwords directly in environment variables. It introduced a vault with role-based access scoped to each microservice, had its CI/CD pipeline pull secrets at deployment time using short-lived tokens, and fed access logs into its SIEM for monitoring. The vault's path structure made per-microservice, per-environment access grants possible to configure and enforce.

Choosing a tool means weighing real tradeoffs, not picking a winner. Cloud-native managers, AWS Secrets Manager, Azure Key Vault, and GCP Secret Manager among them, work well for a team running entirely inside one cloud, but start creating overhead and gaps the moment a second cloud enters the picture. HashiCorp Vault and similar traditional vaulting software secure secrets effectively, but they ask a team to deploy, manage, and scale its own clusters, and that is a real and ongoing operational cost for a small team. Infisical's 2025 guide adds a consideration that cuts across both categories: cloud-agnostic authentication, using OIDC, AWS IAM roles, GCP Workload Identity, or Azure Managed Identity, lets workloads authenticate without needing long-lived credentials at all, which avoids vendor lock-in while keeping policy enforcement consistent no matter which environment a workload runs in. For a team still running on one primary cloud, the honest recommendation is to start with that cloud's native tool and only bring in a platform-layer tool once a genuine multi-cloud footprint or a real need for dynamic credentials appears.

The CI/CD pipeline as the highest-risk injection point across environments

The CI/CD pipeline is where secrets stop being entries in a vault and become live values inside a running job, and that crossing point is exactly where most multi-environment contamination happens. A pipeline that isn't disciplined about this crossing is the single most common way a production secret ends up reachable from a feature-branch build it was never meant to touch.

A mature pipeline enforces a three-layer model to keep that from happening. The secret store holds the canonical value at the first layer. The CI platform maps entries from that store to masked, protected variables scoped to a specific pipeline and branch at the second layer. The deploy target receives only what that particular environment actually needs at the third layer, so production keys never touch a feature-branch job. Infisical's 2025 guide describes the goal of this structure as removing humans from the loop entirely: applications reference secret names or paths rather than actual values, and the CI/CD pipeline generates environment-specific secrets as part of the deployment process itself, rather than relying on someone manually copying a value into the right place.

Plain environment variable injection is common, but it is weak when it's the only control in place. Environment variables are visible to every process running in that context, and they often appear in logs or system dumps without anyone intending that to happen. OWASP says you should treat environment variable injection as a fallback option for getting secrets into a running application. Docker makes the same mistake easy to repeat: secrets passed in through docker ENV or docker ARG can leak as part of the container image definition itself, baked into a layer that anyone with access to the image can inspect. The safer pattern lets the orchestrator overwrite the environment variable with the real secret value at runtime, so nothing sensitive ever gets hardcoded into the image.

The pipeline's credentials need the same protection as the application secrets they inject. The CircleCI incident from 2023 shows how this happens in practice: malware on a developer's laptop captured a session cookie backed by two-factor authentication, and that cookie let attackers reach customer secrets stored inside the platform. Nothing about the application's own secrets was weak in that incident. The pipeline's own access credentials were the weak point; those credentials need rotation and monitoring just like any secret the pipeline hands out downstream.

Kubernetes workloads have a cleaner pattern available for handling this crossing point: the sidecar. OWASP describes a pod running a sidecar container, HashiCorp Vault Agent is one example, that authenticates to the secrets manager using a Kubernetes service account, retrieves the needed secret, and writes it to a volume shared with the application container. The application never has to know anything about the secrets manager's API or authentication scheme. It just reads a file.

None of this works without a gate that catches what slips through anyway. Pre-commit hooks and CI pipeline scanning, using tools like GitGuardian, Trufflehog, or Gitleaks, catch hardcoded secrets before they reach the repository. JumpServer's 2026 guidance treats any secret found in commit history as already compromised the moment it's found: revoke it, rotate it, then investigate how it got there. Investigation comes last, not first, because a credential sitting in commit history is a live risk for every minute it stays valid.

Dynamic secrets and short-lived credentials as the rotation strategy that scales

Diagram: The Credential That Never Dies: Four Years of Exposure. Visualizes: Show the scale of stale credential risk using two concrete figures from GitGuardian's State of Secrets Sprawl 2026: hardcoded secrets in public GitHub commits grew 34%…

Scheduled rotation shrinks the window during which a leaked credential stays useful, but it never closes that window. Dynamic secrets close it by design: every credential becomes single-use or tied to a session, so dynamic issuance is the only rotation strategy that scales across many environments without demanding proportionally more operational effort as each new environment gets added.

The research shows why scheduled rotation keeps falling short in practice. GitGuardian's 2026 findings show that 64% of credentials confirmed exposed back in 2022 were still valid when retested in January 2026, four years after the original exposure. That figure confirms something specific: scheduled rotation fails because teams don't execute it consistently, not because the schedules themselves are wrong. Rotating credentials by hand across several environments takes more coordination than most teams can sustain month after month, so the rotations quietly stop happening, and the credentials just sit there, valid, for years.

Dynamic secrets remove the schedule from the equation, so no human has to execute a rotation for them to stay safe. When an application asks for a secret, the system creates a unique, temporary credential on the spot, with a defined time-to-live attached to it. Once that TTL runs out, or the session that used it ends, the credential simply stops working. There's no long-lived value sitting around for anyone to steal later, because nothing issued this way is meant to last. OWASP gives a database example: if an application's database credentials get stolen under this model, they expire automatically the next time the system reboots, without anyone needing to revoke them manually. Infisical's 2025 guide extends the same idea to SSH access: certificate authorities issue signed certificates scoped to a specific server and a specific time window, which removes the need to distribute and manage permanent SSH keys across a fleet of machines.

How aggressively a team applies this depends on the environment. Production is where it matters most, so you should build toward dynamic database credentials paired with short-lived cloud access tokens there. Staging benefits almost as directly: dynamic credentials there cut the risk that a staging credential gets reused against production by mistake or by an attacker who assumes the two environments share access. Dev and CI environments benefit from the same approach scaled down: short-lived tokens scoped tightly to a specific branch or job mean a build can't reach production data it was never supposed to touch in the first place, even if that build gets compromised.

Dynamic issuance isn't available everywhere. Some legacy systems simply don't support issuing credentials on demand, and for those, automated rotation on a fixed schedule, paired with the ability to revoke a credential immediately when needed, is the realistic fallback. OWASP lists gradual rotation as one of several strategies for this kind of constrained system, where you introduce new keys for write operations while leaving old keys valid for read operations only, so you avoid an outage during the rotation itself.

The stakes climb further once AI and machine learning infrastructure enter the picture. If a credential inside a Kubernetes cluster running ML workloads is exposed, it can compromise an entire training dataset, enable theft of a trained model, or hand over GPU access that costs real money to run. A typical web application scopes a secret exposure to one user's data. ML infrastructure secrets control resources shared across every user and every model the infrastructure serves, so if one leaks, it reaches much further than it would in a conventional application. Platforms like Porter, a bring-your-own-cloud PaaS that deploys and scales AI workloads inside a team's own AWS, GCP, or Azure account, surface this distinction directly by keeping each environment's compute and access boundaries inside infrastructure the team actually owns and controls. GitGuardian's 2026 research found that detections of exposed AI service secrets grew sharply year over year, with LLM infrastructure credentials among the exposures recorded. The pattern traced through this piece, replication without scoping, rotation that depends on people remembering to do it, pipelines that let the wrong environment reach the wrong secret, appears here too, just with higher stakes attached to every instance of it.

Sources

  1. Best Practices For Managing Secrets Across Multiple Environments
  2. Secrets Management - OWASP Cheat Sheet Series
  3. Secrets Management Best Practices for Enterprise Security (2026 Guide)
  4. Secrets Management: Definition + 10 Best Practices (2026) - EnvManager
Filed underCI/CD Workflows

More in CI/CD Workflows