Toutes les vulnérabilités
HIGHInfra

CLOUD-IAC-TFSTATE-EXPOSURE

Cloud · IaC · Terraform state file (terraform.tfstate)

Résumé

Exposed Terraform state is an Infrastructure-as-Code hygiene failure class in which the terraform.tfstate file leaks credentials because Terraform records every managed resource attribute, including secrets, in cleartext JSON by default. HashiCorp documents that Terraform stores state in a plaintext file that includes any secret values defined in the configuration, so database passwords, IAM access keys, TLS private keys, and API tokens are written verbatim into state. The exposure paths are concrete and repeatedly observed: state committed to a public or private git repository without a .gitignore rule, state left in a world-readable or misconfigured S3 bucket, state captured in CI/CD logs, or state held in a remote backend that lacks encryption at rest and access controls. Numerous terraform.tfstate files have been found in public GitHub repositories and open S3 buckets, and because the file is effectively a master key to the infrastructure, an attacker who reads it obtains working credentials and bypasses the perimeter entirely without exploiting any vulnerability.

Comment l’éviter dans votre code

  • Add *.tfstate and *.tfstate.backup to .gitignore and never commit state to any repo.
  • Store state in an encrypted remote backend (S3 with SSE-KMS, or HCP Terraform) with state locking.
  • Apply Block Public Access and least-privilege IAM policies to the state backend bucket.
  • Keep secrets out of state by sourcing them from a vault and marking variables sensitive.
  • Scan repos and IaC with secret scanners and tfsec/Checkov in CI to catch committed state.

Références

Vulnérabilités liées

Tout Infra →