Terraform variables holding secrets are marked sensitive
terraform/no-plaintext-secrets@v1
Every Terraform variable named like a credential declares sensitive = true.
| Id | terraform/no-plaintext-secrets |
| Version | v1 |
| Category | terraform |
| Default severity | error |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | terraform |
Collectors
This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.
| Collector | Gathers | Inputs it is given |
|---|---|---|
terraform | The Terraform configuration in the checkout: every root directory holding .tf files, the backend it stores state in, the providers and modules it takes on and how tightly they are pinned, the resources it declares, the variables it takes, the lock file that resolves it, and any state file left in the tree. Everything is read from the files themselves, so it works on a runner with no Terraform installed. When the terraform CLI is there, the versions an initialised root has already resolved are added. | none |
The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.
Configuration
{
"guardrails": {
"failOn": "error",
"checks": [
{
"use": "terraform/no-plaintext-secrets@v1",
"severity": "error",
"with": {
"patterns": "*SECRET*,*TOKEN*,*PASSWORD*,*KEY*,*CREDENTIAL*"
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
patterns | Comma separated glob patterns, matched case-insensitively against the name of every variable block. Only names are checked: the collector never collects defaults, because a default can be the credential itself. | *SECRET*,*TOKEN*,*PASSWORD*,*KEY*,*CREDENTIAL* | GUARDRAIL_INPUT_PATTERNS |
How to fix
Mark the variable as sensitive, and don't give it a default:
variable "db_password" {
type = string
sensitive = true
}Pass the value in from the secret store your pipeline already uses, as an environment variable, instead of from a .tfvars file anyone can commit:
TF_VAR_db_password="$(aws ssm get-parameter --name /company/db/password --with-decryption --query Parameter.Value --output text)" terraform applysensitive = true redacts the value in plans and CLI output. It doesn't encrypt it in state, so the backend still needs to encrypt. Plans are the exposure people miss: a pull request comment that quotes a plan publishes whatever the plan printed.
More in terraform
terraform/modules-pinned. Every module a Terraform root pulls from a registry or a git URL names a version, so the same commit always resolves to the same module code.terraform/providers-pinned. Every provider a live Terraform root requires is pinned to one exact version, and the lock file that resolves them is committed.terraform/remote-state. Every live Terraform root stores its state in a remote backend, and no state file is left in the checkout.terraform/state-encrypted. Every live Terraform root declares an encrypted backend, so its state isn't stored in the clear in its bucket.terraform/state-locking. Every live Terraform root declares state locking, so two applies cannot write the same state at once.