TL;DR: Hardcoded secrets, secrets sprawl, weak access controls, and infrequent rotation make Infrastructure as Code a recurring source of exposure, according to Entro Security. Vaults reduce blast radius, but they do not solve lifecycle, logging, or post-retrieval leakage, so secrets governance must extend across the toolchain.
At a glance
What this is: This is an analysis of why Infrastructure as Code creates persistent secrets-security risk, with the key finding that hardcoding, sprawl, and weak lifecycle controls remain the main failure points.
Why it matters: It matters because IAM teams have to govern secrets, workload identity, and access review as one lifecycle problem across human and non-human actors, not as isolated tooling decisions.
By the numbers:
- Only 44% of organisations are currently using a dedicated secrets management system.
👉 Read Entro Security's blog on best practices for IaC and secrets security
Context
Infrastructure as Code secrets security is the discipline of keeping credentials, tokens, and keys out of code and out of uncontrolled runtime artifacts. The core problem is that IaC optimises speed and reproducibility, while secrets demand tight lifecycle control, traceability, and immediate revocation when exposure occurs.
The governance gap is not just hardcoding. Secrets also leak through logs, environment variables, repositories, and loosely managed pipelines, which means the control surface spans development, deployment, and runtime. That is why the problem sits across NHI governance, IAM, and CI/CD controls rather than inside a vault alone.
Key questions
Q: How should security teams prevent secrets from being hardcoded in Infrastructure as Code?
A: Security teams should remove credentials from source files entirely and replace them with runtime references from a secrets system or identity-aware delivery process. They should also add repository scanning, commit blocking, and build-time checks so secrets never enter version control. The goal is to make the codebase incapable of storing reusable credentials.
Q: Why do vaults not solve secrets security on their own?
A: Vaults centralise storage, but they do not control where a secret goes after it is retrieved. Secrets can still appear in logs, environment variables, command lines, caches, and deployment artefacts. That is why vault adoption must be paired with discovery, rotation, audit logging, and downstream leakage controls.
Q: What breaks when secrets are spread across multiple repositories and tools?
A: When secrets sprawl across repositories and toolchains, organisations lose the ability to find, classify, and revoke them quickly. Response slows, ownership becomes unclear, and different copies may survive even after one credential is rotated. That creates avoidable exposure and makes incident response far harder than it should be.
Q: How do security teams govern secrets in CI/CD pipelines without slowing delivery?
A: They should treat the pipeline as part of the identity plane and give it only the secrets it needs for a specific build or deployment. Access should be logged, time-bounded, and reviewable, with approval boundaries for changes that affect secret distribution. This preserves delivery speed while reducing uncontrolled credential reuse.
Technical breakdown
Why hardcoded secrets turn IaC into an exposure path
Hardcoding secrets in Ansible, Terraform, or other IaC tools turns source code into a credential store. Once a repository, build log, or shared script contains a password or API key, the secret stops being tied to a controlled identity lifecycle and becomes a reusable artefact. Version control then amplifies the exposure because copies persist across branches, forks, caches, and backups. The real technical issue is not just visibility, but permanence: a secret embedded in code is hard to find, hard to revoke, and often reused in multiple systems.
Practical implication: eliminate embedded secrets from code paths and treat IaC repositories as high-risk disclosure surfaces.
Secrets sprawl and why vaults do not remove lifecycle risk
Secrets sprawl happens when credentials are distributed across repositories, key management systems, configuration files, and cloud services without a consistent governance layer. A vault centralises storage, but it does not automatically govern every place the secret is copied after retrieval. That is why unsealed secrets still appear in memory, logs, command lines, and environment variables. In practice, the challenge is lifecycle continuity: creation, use, discovery, rotation, and revocation all need to be visible if the organisation wants to reduce exposure rather than merely relocate it.
Practical implication: map where secrets exist after issuance, not just where they are stored before issuance.
How CI/CD and zero trust controls need to intersect with secrets management
The article points to a broader control failure: secrets handling cannot sit apart from pipeline governance. If CI/CD systems can read, inject, or distribute secrets without strong logging and approval boundaries, then the pipeline becomes part of the identity plane. Zero Trust principles apply here because access should be continuously validated, not assumed from past trust. The technical model therefore combines least privilege, audit logging, and policy enforcement across the toolchain, especially where multiple teams, ephemeral workloads, and automated deployments share credentials.
Practical implication: bind secrets access to pipeline identity, logging, and approval controls instead of treating the vault as a standalone control.
Threat narrative
Attacker objective: The objective is to turn a leaked or embedded secret into durable access to cloud and application infrastructure.
- Entry occurs when secrets are hardcoded into IaC files, copied into repositories, or exposed through misconfigured cloud storage and pipeline artefacts.
- Credential access follows when an attacker, insider, or unintended recipient retrieves the secret from code, logs, environment variables, or shared configuration.
- Impact occurs when the exposed secret is reused to access infrastructure, manipulate cloud resources, or expand access across connected systems.
Breaches seen in the wild
- Shai Hulud npm malware campaign — Shai Hulud campaign: npm malware exposed secrets on GitHub.
- Salesloft OAuth token breach — hackers stole OAuth tokens to access Salesforce data via Salesloft.
Read our 52 NHI Breaches Analysis report for a comprehensive view of breaches impacting Non-Human Identities including AI Agents.
NHI Mgmt Group analysis
Hardcoded IaC secrets are not a storage problem, they are a lifecycle failure. Once credentials are embedded in source files, the organisation has already lost control of where they copy, how long they persist, and who can reuse them. That breaks the normal identity assumption that access is issued into a known system and can be revoked from a known system. Practitioners should treat code-embedded secrets as a governance defect, not a convenience issue.
Secrets sprawl creates identity blast radius. When credentials exist in multiple repositories, services, and toolchains, the organisation no longer has a single authoritative control point. That means discovery, revocation, and audit all become slower than the exposure itself. The practical implication is that any programme that cannot enumerate secrets across the delivery chain cannot claim meaningful non-human identity governance.
Vaults reduce exposure, but they do not finish the control job. A vault centralises storage, yet the article correctly notes that secrets still reappear after retrieval in logs, command lines, and memory. That means the security model must extend beyond vault placement to retrieval governance and downstream artefact control. Teams that stop at vault adoption will keep the same risk, only with a better named repository.
Infrastructure as Code forces IAM teams to govern machines the way they govern people, but with tighter timing. The same lifecycle discipline used for joiner, mover, and leaver processes has to apply to service accounts, pipeline identities, and secret issuance. The difference is that machine identities change faster and fail more silently, so review cadences that work for humans are too slow for automated delivery paths. Practitioners should align lifecycle governance to the pace of deployment, not the cadence of employee review.
From our research:
- Only 44% of organisations are currently using a dedicated secrets management system, according to The 2024 State of Secrets Management Survey.
- 54% of organisations are dissatisfied with their current secrets management solution because not all secrets are secured, and 43% cite lack of central management.
- For a broader view of the control gap, read the Guide to the Secret Sprawl Challenge for the lifecycle and discovery problems that usually sit behind secrets exposure.
What this signals
Secrets governance is becoming a delivery-chain problem, not a vault problem. As more teams ship infrastructure through code, the control question shifts to where secrets can appear after retrieval and who can still see them. Organisations that cannot trace secret usage across code, build, and runtime will keep discovering that their controls exist only at the point of storage.
Secret sprawl is now a measurable governance debt. Our research shows that 88% of security professionals are concerned about secrets sprawl, and that concern should be read as a signal that discovery and ownership are outpacing remediation. The next maturity step is not more storage, but a reliable inventory of secrets across pipelines and runtime.
Identity programmes should treat machine credentials as lifecycle objects. When a pipeline identity or service credential changes, the full chain of issuance, use, rotation, and revocation has to remain auditable. That is where lifecycle governance and NIST Cybersecurity Framework 2.0 controls intersect most directly for practitioners.
For practitioners
- Remove secrets from source-controlled IaC Replace hardcoded credentials with runtime secret references, and block commits that contain keys, tokens, or passwords in Ansible, Terraform, or related repositories. Treat every repository as a potential disclosure point and scan both primary code and supporting configuration for embedded secrets.
- Trace every secret through its post-vault path Document where secrets are injected after retrieval, including logs, command lines, environment variables, and build artefacts. If you cannot see the full path, you cannot prove that revocation or rotation will actually remove exposure.
- Bind secrets governance to pipeline identity Apply least privilege, logging, and approval controls to CI/CD systems that read or distribute secrets. Pipeline identities should be treated as governance subjects, with explicit access scopes and reviewable change paths.
- Rotate secrets using dependency context Rotate credentials only after mapping the systems, services, and permissions that depend on them. Context-aware rotation reduces outage risk and makes it possible to revoke the correct secret without breaking unrelated workloads.
Key takeaways
- Hardcoded secrets in IaC convert source code into a credential distribution channel, which is why exposure keeps recurring.
- Vaults help reduce blast radius, but unmanaged retrieval paths and secrets sprawl still leave organisations with poor control over secret lifecycle.
- Practitioners need to govern secrets across repositories, pipelines, and runtime artefacts if they want revocation and rotation to work in practice.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-03 | The article focuses on secret hardcoding, rotation, and exposure across IaC workflows. |
| NIST CSF 2.0 | PR.AC-4 | Least-privilege access and controlled secret use map directly to access management. |
| NIST Zero Trust (SP 800-207) | PR.AC-1 | Continuous verification is needed when secrets move through pipelines and runtime systems. |
Remove embedded secrets, rotate exposed credentials, and tie secret handling to lifecycle governance.
Key terms
- Secrets Sprawl: Secrets sprawl is the uncontrolled spread of credentials, tokens, and keys across repositories, pipelines, cloud services, and configuration files. It weakens ownership and makes discovery, rotation, and revocation slower than the exposure itself, which turns routine operations into recurring security risk.
- Infrastructure As Code Secrets Security: Infrastructure as Code secrets security is the practice of keeping credentials out of code while controlling how they are issued, used, and revoked in automated delivery. It combines repository hygiene, pipeline governance, logging, and lifecycle management so secrets do not become durable artefacts.
- Context-Based Secret Rotation: Context-based secret rotation is the process of changing a credential with awareness of the services, permissions, and dependencies that rely on it. It reduces disruption by matching rotation to actual usage, rather than treating every secret as interchangeable or every environment as identical.
- Pipeline Identity: Pipeline identity is the non-human identity used by CI/CD systems to fetch, inject, or distribute credentials during build and deployment. Because it can move secrets at machine speed, it needs tight scope, logging, and review just like any other privileged identity.
What's in the full article
Entro Security's full blog covers the operational detail this post intentionally leaves for the source:
- Step-by-step guidance on organizing secrets across IaC directory structures and variable naming conventions
- A deeper walkthrough of access control patterns for secrets vaults, including least-privilege decisions
- Practical logging and audit guidance for secret creation, retrieval, updates, and deletions
- Context-based rotation considerations for dependencies, privileges, and service relationships
Deepen your knowledge
NHI governance, agentic AI identity, and machine identity security are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are responsible for identity security strategy or NHI governance in your organisation, it is worth exploring.
Published by the NHIMG editorial team on 2024-05-20.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org