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.
Why This Matters for Security Teams
Hardcoded secrets in Infrastructure as Code turn deployment logic into a credential distribution channel. Once a token, API key, or certificate lands in Terraform, CloudFormation, Helm, or pipeline YAML, it can be copied into logs, forks, artifacts, and chat systems faster than a team can rotate it. The risk is not only accidental exposure; it is also reuse across environments, which defeats least privilege and makes compromise durable.
This is why NHI Management Group treats secrets sprawl as an operational control failure, not just a developer mistake. The pattern is visible in The State of Secrets Sprawl 2025, which shows that hardcoded secrets continue to appear in both public and private workflows. For IaC specifically, the right question is whether the codebase can ever store a reusable credential at all. Guidance from the OWASP Non-Human Identity Top 10 reinforces that machine credentials need lifecycle controls, not just detection.
In practice, many security teams find the problem only after a repository scan or incident response exercise has already shown that the same secret was used in multiple pipelines.
How It Works in Practice
The strongest pattern is to remove static credentials from source entirely and replace them with runtime resolution. IaC should reference a secrets system, workload identity, or ephemeral credential broker at deploy time, not embed the secret value itself. That means the template can describe what access is needed, while an external control plane decides which secret, token, or certificate is issued and for how long.
Practically, this usually requires three layers:
- Developer controls that block cleartext secrets before commit, including pre-commit hooks and local validation.
- Repository and CI controls that reject secret-like patterns during pull request checks and build steps.
- Runtime delivery that uses short-lived credentials, managed rotation, and automatic revocation after use.
That approach aligns with the principle behind Ultimate Guide to NHIs - Static vs Dynamic Secrets, where reusable credentials are replaced with dynamic issuance. It also fits current implementation guidance in the OWASP Non-Human Identity Top 10, because the identity used by automation should be traceable, bounded, and revocable.
For delivery pipelines, teams increasingly pair secrets scanning with identity-aware access to the vault so the build runner proves who it is before receiving anything sensitive. That is more durable than storing a secret in a variable group or Terraform state file, both of which expand the blast radius when a repo or runner is compromised. These controls tend to break down when legacy modules require inline credentials to satisfy provider bootstrap steps because the automation has not been redesigned around ephemeral identity.
Common Variations and Edge Cases
Tighter secrets control often increases delivery friction, requiring organisations to balance developer speed against stronger release hygiene. That tradeoff is real when teams rely on third-party providers, bootstrap scripts, or legacy modules that were written before dynamic credentials were available.
Current guidance suggests treating those cases as migration targets, not exceptions to policy. For example, a Terraform module that still expects a long-lived cloud key should be refactored to assume workload identity or a short-lived token exchange. If that is not possible immediately, the next best step is to confine the secret to a narrower trust boundary, shorten its TTL, and monitor usage aggressively.
Two edge cases matter most. First, private repositories are not safe by default, as hidden leakage often occurs in internal repos, CI logs, and copied state files. Second, scanning alone is not enough if a discovered secret remains valid. The practical lesson from CI/CD pipeline exploitation case study and 52 NHI Breaches Analysis is that detection must be paired with revocation and source cleanup. Best practice is evolving, but there is no universal standard for every IaC stack yet.
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 AI RMF set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-03 | Covers secret exposure and lifecycle control for non-human identities. |
| NIST CSF 2.0 | PR.AC-1 | Addresses identity and access control for automation and CI/CD identities. |
| NIST AI RMF | GOVERN | Supports governance for automation that can leak or misuse secrets during deployment. |
Replace static IaC secrets with short-lived credentials and revoke exposed values immediately.
Related resources from NHI Mgmt Group
- How should security teams prevent hardcoded secrets from becoming a breach path?
- When should security and infrastructure teams lower TTL before a change?
- How should security and infrastructure teams roll out IPv6 in dual-stack environments?
- How do security teams reduce identity blind spots across code and cloud?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on June 23, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org