code.iac.no-static-cloud-credentials

Infrastructure code carries no static cloud credentials

Terraform providers resolve credentials from named profiles or the ambient credential chain; no provider block, variable default, or tracked tfvars file holds a key, secret, or token.

High Attested Preventive

Assertion

count(provider attributes in {access_key, secret_key, token, client_secret, credentials}) == 0 and every tracked *.tfvars matches *.example.tfvars

Evaluated against tflint --config .linter/.tflint.hcl over every Terraform root; git ls-files '*.tfvars', collected on-push.

Rationale

Infrastructure code is the one kind of code that is guaranteed to need cloud credentials, which makes it the place they most often get written down. A provider block with an access_key works on the first run and is committed with everything else. The fix is structural: providers get their identity from the environment they run in, so the same code is valid on a laptop with a named profile and on a runner with an assumed role, and there is nothing in the repository to leak.

Observation

The collector runs the Terraform linter over every root declared in the repository’s build configuration, with a rule set that flags credential attributes on provider blocks and credential-shaped defaults on variables. It also lists tracked *.tfvars files, since a tfvars file is where a credential goes when it is not in the provider block. The assertion holds when no credential attribute is present and every tracked tfvars file is an example file.

Provider blocks that name a profile are compliant: the name refers to a credential that lives in the operator’s own configuration, not in the repository.

Remediation

Delete the attribute and let the provider use its default chain. For AWS, set profile for local use and give the runner a role. For Azure and Google Cloud, use the CLI login or workload identity on the runner. If the credential was ever committed, rotate it; see code.repo.no-committed-secrets for why deletion alone is not enough.