Skip to main content
All articles

Your state file is a plaintext credential store: Terraform secrets and CVE-2024-47083

Terraform stores secrets in state in plaintext by design, and the tooling around it leaks the same secrets into logs and CI. CVE-2024-47083 is one named instance; the sensitive flag protects your terminal, not your state.

By Published

8 min read23 views

Two different failures get filed under "Terraform leaked our secrets," and conflating them is how teams end up fixing the wrong one.

  • State stores secrets in plaintext. This is documented behaviour, not a bug. Every terraform apply writes the full attributes of every managed resource into the state file, and that includes database passwords, private keys and access tokens, in clear text.
  • The tooling around IaC spills those same secrets. Providers write them to logs, CI systems archive plan output, and pull-request bots post them into comments. This is where the CVEs live, because "a secret ended up somewhere it should not" is a defect even when plaintext state is not.

The first is a property you design around. The second is a stream of named vulnerabilities that keep arriving. The mistake people make is trusting the sensitive flag to solve either, when it solves neither.

Why sensitive = true does not do what its name implies

Marking a variable or output sensitive = true changes one thing: Terraform stops printing the value in CLI output and plan diffs. HashiCorp's own documentation is explicit that this is a display control, not an encryption control. The value is still written to the state file and to plan files in plaintext, and anyone who can read those files can read the value.

So the sensitive flag is a defence against shoulder-surfing and log scraping of the terminal, and nothing more. It is genuinely useful for that. It is actively misleading if a team reads the word "sensitive" and concludes the secret is protected at rest. It is not. The state file is a credential store, and the flag does not lock it.

That leaves two real exposure surfaces: the state file itself, and every artifact the IaC toolchain produces on the way to writing it.

The real one: CVE-2024-47083

The Power Platform Terraform Provider authenticates to Power Platform using a service principal, whose client_secret is exactly the kind of value the sensitive treatment is supposed to guard. The advisory describes the failure:

sensitive information, specifically the client_secret used in the service principal authentication, may be exposed in logs ... due to an error in the logging code that causes the client_secret to not be properly masked when logs are persisted or viewed.

That is CVE-2024-47083, affecting versions prior to 3.0.0, scored 8.8 (CVSS 4.0) and classed as insertion of sensitive information into a log file (CWE-532) with improper output neutralization for logs (CWE-117). The fix in 3.0.0 removes the logging of sensitive content. Anyone who ran an affected version has the client secret sitting in whatever captured that provider's logs: a CI run, a developer's terminal scrollback, a shipped log aggregator.

It is not a lone incident, it is a pattern. CVE-2024-52009 is Atlantis, the Terraform pull-request automation tool, writing rotated GitHub tokens (ghs_...) into its logs; anyone who could read those logs could impersonate the Atlantis app and, where it administered a GitHub organization, gain admin over the org (CWE-532, fixed in v0.30.0). CVE-2023-30618 is kitchen-terraform printing sensitive Terraform output values at the info logging level after a regression (CWE-532, fixed in 7.0.1). Three tools, one shape: a secret Terraform was handling ended up in a log, because output redaction is easy to get wrong and the secrets were plaintext to begin with.

A lab you can build without Docker

You can see both surfaces on a single Linux VM with nothing but the Terraform CLI and two providers that run entirely offline. No cloud account, no credentials, no container runtime.

# On a disposable Linux VM. Install Terraform from HashiCorp's release page,
# then create a config that uses only the random and local providers.
mkdir tf-state-lab && cd tf-state-lab
cat > main.tf <<'EOF'
terraform {
  required_providers {
    random = { source = "hashicorp/random" }
    local  = { source = "hashicorp/local" }
  }
}

resource "random_password" "db" {
  length = 24
}

output "db_password" {
  value     = random_password.db.result
  sensitive = true          # this hides it from the CLI, nothing more
}
EOF

terraform init
terraform apply -auto-approve

Now confirm what the flag did and did not do:

# The CLI honoured sensitive: the value is redacted in the output above.
terraform output db_password           # prints: (sensitive value)

# The state file did not: the same secret is sitting in plaintext.
grep -o '"result": *"[^"]*"' terraform.tfstate | head

The grep returns the generated password in clear text, next to "sensitive": true, in the state file. That single contrast is the whole point: the value marked sensitive is fully readable at rest. Then reproduce the second surface, the tooling spill, with trace logging:

TF_LOG=trace terraform apply -auto-approve 2>trace.log
grep -i result trace.log | head        # sensitive material in the trace stream

The random and local providers are patched and well-behaved, so this lab does not reproduce CVE-2024-47083. It reproduces the conditions that made CVE-2024-47083 possible: secrets are plaintext in state, and verbose logging paths see them, so any redaction slip in a provider or a wrapper turns into a disclosure.

Finding it in code and history

The exposures are findable both in the working tree and, more importantly, in version-control history, because a state file committed once is exposed forever in the history even after it is deleted.

# Has a state file ever been committed? History, not just HEAD.
git log --all --oneline -- '*.tfstate' '*.tfstate.backup'

# Local backend means state lands on disk wherever the run happens.
grep -rniE 'backend\s+"local"|path\s*=\s*".*\.tfstate"' .

# Verbose logging wired into CI, which archives the output.
grep -rniE 'TF_LOG|TF_LOG_PROVIDER' .

# Plan files written to disk and uploaded as build artifacts.
grep -rniE 'terraform plan .*-out|\.tfplan' .

The highest-value check is the git log --all for *.tfstate. A state file in history is a live credential dump that no amount of current .gitignore fixes. If it is there, the secrets it held are compromised and the remediation is rotation, not deletion.

Fixing it

Move state to an encrypted, access-controlled remote backend. Local state on a laptop or in a repo is the worst case. Use a backend that encrypts at rest and supports locking (for example S3 with server-side encryption and a lock table, or Terraform Cloud), and restrict read access to the state as tightly as you would restrict the secrets inside it, because they are the same thing.

Keep secrets out of state where you can. Prefer short-lived, dynamically generated credentials (for instance from a secrets manager) so that what lands in state is a lease or a reference rather than a durable secret. Where the provider supports ephemeral or write-only handling of sensitive values, use it, so the secret is never persisted.

Never commit state, and enforce it. A .gitignore entry for *.tfstate is necessary but not sufficient; add a pre-commit hook or a CI check that rejects the commit, because the flag protecting you is the one that fires before the file lands.

Upgrade the leaking tools and scrub logs. Move the Power Platform provider to 3.0.0 or later, Atlantis to v0.30.0 or later, kitchen-terraform to 7.0.1 or later, and treat any provider or wrapper that writes secrets to logs as a vulnerability to patch. Configure CI to mask secrets and avoid archiving raw plan output.

Rotate what has already been in plaintext. Any secret that lived in a committed state file, an archived plan, or a captured provider log is burned. Patching stops future writes; it does not recall the ones already made. Rotate the credential.

Detecting it

  • Secret scanning on repositories and CI artifacts. Run a scanner such as gitleaks or trufflehog across the full history, not just the tip, and across build-artifact storage. A *.tfstate in history or a ghs_ token in a log is exactly what these find.
  • Access monitoring on the state backend. If state lives in an object store, enable access logging on that bucket and treat reads by unexpected principals the way you would treat reads of a password vault, because the sensitivity is identical.
  • Pipeline guards. Alert when TF_LOG is set to trace or debug in a CI job, and when a job uploads a .tfplan or raw plan output as an artifact. Both are the conditions that turn a routine run into a disclosure.
  • Pre-merge checks. Fail the build on any attempt to commit a state or plan file. This is detection early enough to be prevention.

Take this away

The Terraform state file is not a place secrets might accidentally appear, it is where they are kept, in plaintext, by design, and sensitive = true guards your terminal rather than that file. CVE-2024-47083 is one named instance of the broader truth that IaC tooling leaks the secrets it handles: into logs, into plan output, into pull-request comments. Give the state file, and every artifact around it, the same protection as the credentials it contains, and rotate anything that has already lived there in the clear.

Further reading

Was this useful?

Share

Tags

  • cloud security
  • cve analysis
  • secure code review
  • detection engineering

Get the next write-up by email

New technical write-ups by email when we publish. No sales sequence, and every email has an unsubscribe link.

Prefer a feed? RSS. How we handle your address: privacy notice.

Comments

Loading comments…

Leave a comment

Comments are read and approved by hand before they appear, so yours will not show up straight away. Your email address is optional, is never published, and is only used if we need to reply to you directly.

0/5000

Related service

Cloud Penetration Testing (AWS)

Identity, storage and workload misconfiguration testing across your AWS accounts.

If you want to know whether what you have just read applies to your own systems, that is the engagement that answers it.