Terraform variables holding secrets are marked sensitive
iac/terraform-no-plaintext-secrets@v1
Every Terraform variable named like a credential declares sensitive = true.
| Id | iac/terraform-no-plaintext-secrets |
| Version | v1 |
| Category | iac |
| Default severity | error |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | terraform |
Collectors
This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.
| 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. Read out of the files themselves, so it works on a runner with no Terraform installed, and enriched with the versions an initialised root has already resolved when the terraform CLI is there. | none |
The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.
Configuration
{
"guardrails": {
"failOn": "error",
"comment": true,
"checks": [
{
"use": "iac/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 without regard to case. Each one is matched against the name of every variable block. Names only: the collector never carries a default, because a default can be the credential itself. | *SECRET*,*TOKEN*,*PASSWORD*,*KEY*,*CREDENTIAL* | GUARDRAIL_INPUT_PATTERNS |
How to fix
Mark the variable sensitive, and give it no default:
variable "db_password" {
type = string
sensitive = true
}Pass the value in from the secret store the pipeline already uses, as an environment variable, rather than from a .tfvars anyone can commit:
TF_VAR_db_password="$(aws ssm get-parameter --name /acme/db/password --with-decryption --query Parameter.Value --output text)" terraform applysensitive = true redacts the value in plans and in CLI output. It does not encrypt it in state, so the backend still has to be one that encrypts. The plan is the exposure that gets missed: a pull request comment quoting a plan publishes whatever the plan printed.
More in iac
iac/dockerfile-base-pinned. Every image a Dockerfile builds from is pinned to a digest, so a rebuild of the same commit starts from the same bytes.iac/dockerfile-healthcheck. Every Dockerfile declares aHEALTHCHECK, so the orchestrator can tell a container that is running from one that is working.iac/dockerfile-lint-clean. Every finding the Dockerfile linter reported sits below the severity the team gates on.iac/dockerfile-no-build-secrets. NoARGorENVa Dockerfile declares is named like a credential.iac/dockerfile-nonroot-user. Every Dockerfile ends on aUSERthat is not root, so the container runs its process unprivileged.iac/terraform-modules-pinned. Every module a Terraform root takes from a registry or a git URL names the version it takes, so the same commit resolves to the same module twice.iac/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.iac/terraform-remote-state. Every live Terraform root stores its state in a remote backend, and no state file is left in the checkout.