IaC files have no hardcoded secrets
Why it matters
Infrastructure-as-Code files are source code: they are version-controlled, shared with teams, reviewed in pull requests, and often mirrored on GitHub. A Terraform file containing a hardcoded database password or a CloudFormation template with an embedded API key exposes those credentials to everyone with repository access and permanently records them in git history. CWE-798 applies directly to IaC secrets. OWASP A05 covers misconfigured infrastructure. SSDF PW.6 requires protecting code from unauthorized disclosure, which IaC with embedded secrets violates by definition.
Severity rationale
Low because IaC files are versioned and broadly accessible, meaning a hardcoded secret in a Terraform file exposes credentials to the entire development team and any future repository clone.
Remediation
Replace every hardcoded credential in IaC files with a variable marked sensitive = true or a direct secrets manager reference. Never pass secrets through Terraform output values unless they are also marked sensitive.
# BEFORE (wrong)
resource "aws_db_instance" "main" {
password = "my-real-db-password"
}
# AFTER (correct) — variable with sensitive flag
variable "db_password" {
type = string
sensitive = true
}
resource "aws_db_instance" "main" {
password = var.db_password
}
# AFTER (correct) — secrets manager reference
data "aws_secretsmanager_secret_version" "db" {
secret_id = "prod/db-password"
}
resource "aws_db_instance" "main" {
password = jsondecode(data.aws_secretsmanager_secret_version.db.secret_string)["password"]
}
Pass variable values via TF_VAR_db_password environment variables in CI, never via -var flags that appear in shell history.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Environment Security Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-798 — Use of Hard-coded Credentials
- owasp:2021 · A05 — Security Misconfiguration
- ssdf:800-218 · PW.6 — Implement and verify defense-in-depth mitigations
- soc2:2017 · CC6.1 — Logical access security software, infrastructure, and architectures
- soc2:2017 · C1.1 — Identification and protection of confidential information
Taxons
History
- 2026-04-18·v1.0.0·Initial import from environment-security·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.1, C1.1) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2