Backend audit checks
tfcensus audit backend runs 25 checks on the state buckets, lock tables and states its units use. Every finding carries the check ID as its rule, a severity and a reason. --fail-on takes the lowest severity that fails the run. Keys under audit.policy set the thresholds, and audit.suppress hides findings with a reason and an optional expires date (configuration).
State buckets
Run once per state bucket.
| Check | Severity | Passes when | Fix | Set by |
|---|---|---|---|---|
S3-VER | high | State bucket versioning is enabled | Enable versioning, so an overwritten or deleted state can be restored. | |
S3-MFA | low | State bucket has MFA delete | Informational: MFA delete needs the root user's MFA device and is rarely practical. | |
S3-ENC | medium | State bucket encrypts with a customer-managed KMS key | Set default encryption to SSE-KMS with a customer-managed key, so key policy controls who can decrypt state. | |
S3-KMSPOL | high | State key policy doesn't let every principal decrypt | Remove kms:Decrypt for Principal "*", or restrict it with aws:PrincipalAccount or aws:PrincipalOrgID. | |
S3-PAB | high | Bucket and account public access block are all on | Turn on all four public access block settings on the bucket and the account. | |
S3-TLS | high | State bucket policy denies requests without TLS | Add a Deny for Principal "*", Action s3:*, the bucket and bucket/* resources, with Bool aws:SecureTransport false as the only condition. | |
S3-OWN | medium | Object ownership is BucketOwnerEnforced | Set object ownership to BucketOwnerEnforced, which turns ACLs off. | |
S3-REPL | medium | State is replicated to another region | Configure cross-region replication to a versioned, KMS-encrypted bucket. | |
S3-LC | medium | Noncurrent state versions expire after a bounded time | Add a lifecycle rule with NoncurrentVersionExpiration of at least the policy's noncurrent_days. | audit.policy.noncurrent_days |
S3-LOG | low | State access is logged | Turn on server access logging or CloudTrail S3 data events for the bucket. | |
S3-LEGACY | low | No legacy RootAccess statement | Remove the RootAccess statement that terragrunt before 1.2 added; the account root has access through IAM. |
Locks
Run once per unit backend and lock table.
| Check | Severity | Passes when | Fix | Set by |
|---|---|---|---|---|
LK-MODE | low | Unit locks with S3 lock files | Set use_lockfile = true: dynamodb_table is deprecated since Terraform 1.11. Keep both during the migration. | |
LK-BOTH | info | Unit uses one lock mechanism | Both lock files and DynamoDB are configured, which is fine while migrating. Remove dynamodb_table afterwards. | |
LK-PITR | medium | Lock table has point-in-time recovery and KMS encryption | Turn on point-in-time recovery and encrypt the table with a KMS key. | |
LK-STALE | high | No stale locks | Check that no run holds the lock, then release it with terraform force-unlock. | audit.policy.stale_lock_hours |
LK-MD5 | low | No orphaned digest items | Delete the -md5 item: its state object no longer exists. |
Fleet and states
Run over the states and the units that point at them.
| Check | Severity | Passes when | Fix | Set by |
|---|---|---|---|---|
FL-ORPHAN | medium | Every state key belongs to a unit | Delete or archive the state, or add the unit that owns it to the scanned repos. | |
FL-ABSENT | low | Every unit's state exists | Apply the unit, or fix its backend key. | |
FL-EMPTY | low | State manages resources | Destroy the unit's code and state, or check that the key is right. | |
FL-LINEAGE | high | Each lineage lives under one key | One of the states is a copy. Keep the one the unit applies to and archive the other. | |
FL-DOUBLE | high | Each resource is managed by one state | Remove the resource from all but one state with terraform state rm, or a removed block. | |
FL-TFVER | medium | State was written by a supported version | Upgrade the unit's terraform or tofu to at least the policy's min_terraform_version. | audit.policy.min_terraform_version |
FL-PROV | low | Provider versions meet the policy | Upgrade the provider in .terraform.lock.hcl with terraform init -upgrade. | audit.policy.min_provider_versions |
FL-SIZE | low | State is small enough for fast plans | Split the unit. | audit.policy.max_state_mb |
FL-SECRET | info | No secrets stored in plain state | Use write-only arguments or ephemeral resources, or keep the secret in a secrets manager. |
Suppress a finding
yaml
audit:
suppress:
- check: S3-MFA
reason: MFA delete needs the root user's device
- check: LK-*
bucket: acme-legacy-tfstate
reason: the legacy fleet moves to lock files in Q1
expires: "2027-03-31"