Audit state backends and suppress findings
tfcensus audit backend checks where your state lives. It finds the S3 buckets and lock tables that your units' backends name, checks their settings, and checks the states themselves: orphans, copies, old versions and attribute names that look like secrets. Every call is a read, and it takes no lock. This guide runs an audit, tunes its thresholds, and handles the findings you accept.
Run the audit
audit backend discovers units the way units does and reads their state the way inventory does, so it takes the same paths and account flags:
tfcensus audit backend ~/src/infra/acme-live --profile 'acme-*'This is the output for the tf-audit fixture fleet, which has a good, a bad and a legacy bucket:
SEVERITY CHECK TARGET REASON
high S3-VER s3://acme-audit-bad versioning is suspended: an overwritten or deleted state can't be restored
high S3-KMSPOL s3://acme-audit-legacy key arn:aws:kms:eu-west-1:111111111111:key/0b1c2d3e-open-4000-8000-000000000003 allows kms:Decrypt to principals in any account (statement AllowDecryptAnywhere)
high S3-PAB s3://acme-audit-bad bucket: BlockPublicAcls, IgnorePublicAcls, BlockPublicPolicy, RestrictPublicBuckets off
high S3-TLS s3://acme-audit-bad the bucket has no policy, so plain HTTP requests aren't denied
high S3-TLS s3://acme-audit-legacy plain HTTP isn't denied for s3:GetObject by anonymous, another account, the bucket's account, arn:aws:iam::111111111111:root
high LK-STALE dynamodb://eu-west-1/acme-audit-locks-bad acme-audit-bad/legacy/terraform.tfstate lock held for 3d3h, over 24h
high LK-STALE s3://acme-audit-bad/legacy/terraform.tfstate.tflock lock file is 3d0h old, over 24h
high FL-LINEAGE tf-audit/app lineage 1a2b3c4d-0000-4000-8000-000000000002 is shared by tf-audit/app (s3://acme-audit-good/app/terraform.tfstate) and tf-audit/copy (s3://acme-audit-good/copy/terraform.tfstate)
high FL-LINEAGE tf-audit/copy lineage 1a2b3c4d-0000-4000-8000-000000000002 is shared by tf-audit/app (s3://acme-audit-good/app/terraform.tfstate) and tf-audit/copy (s3://acme-audit-good/copy/terraform.tfstate)
high FL-DOUBLE tf-audit/app aws_iam_role arn:aws:iam::111111111111:role/acme-audit-app is managed by tf-audit/app (aws_iam_role.app) and tf-audit/copy (aws_iam_role.app) (matched on arn)
medium S3-ENC s3://acme-audit-bad default encryption is SSE-S3: anyone with s3:GetObject can read state, no key policy applies
medium S3-OWN s3://acme-audit-bad object ownership is ObjectWriter: ACLs are on
medium S3-REPL s3://acme-audit-bad no replication: losing the region loses every state
medium S3-REPL s3://acme-audit-legacy replica acme-audit-legacy-replica is in the same region; replica acme-audit-legacy-replica versioning is suspended; replica acme-audit-legacy-replica: default encryption is SSE-S3: anyone with s3:GetObject can read state, no key policy applies
medium S3-LC s3://acme-audit-bad no lifecycle rule expires noncurrent versions of every state: they are kept forever
medium S3-LC s3://acme-audit-legacy noncurrent versions expire after 3 days, under 7: a bad apply found late can't be rolled back
medium LK-PITR dynamodb://eu-west-1/acme-audit-locks-bad encrypted with an AWS owned key, not KMS; point-in-time recovery is off
medium FL-ORPHAN s3://acme-audit-bad/retired/terraform.tfstate no discovered unit resolves to this key
medium FL-ORPHAN s3://acme-tfstate-orphans/lost/terraform.tfstate state in a discovered bucket that no unit uses
medium FL-TFVER tf-audit/legacy written by 1.5.7, older than the policy's 1.10
low S3-LOG s3://acme-audit-bad no server access logging and no CloudTrail trail records S3 data events for the bucket
low S3-LEGACY s3://acme-audit-legacy the policy has the RootAccess statement that terragrunt before 1.2 added
low LK-MODE tf-audit/legacy legacy/terraform.tfstate locks with dynamodb_table acme-audit-locks-bad only
low LK-MD5 dynamodb://eu-west-1/acme-audit-locks-bad acme-audit-bad/gone/terraform.tfstate-md5 digest for s3://acme-audit-bad/gone/terraform.tfstate, which doesn't exist
low FL-ABSENT tf-audit/planned s3://acme-audit-good/planned/terraform.tfstate doesn't exist: never applied, or a wrong key
low FL-EMPTY tf-audit/empty the state manages no resources
low FL-PROV tf-audit/legacy hashicorp/aws 4.67.0 in .terraform.lock.hcl is older than the policy's 5.0
low FL-SIZE tf-audit/legacy state is 4.8 KiB, over the policy's 0.004 MiB
info LK-BOTH tf-audit/app app/terraform.tfstate locks with both use_lockfile and dynamodb_table acme-audit-locks-good
info FL-SECRET tf-audit/secrets sensitive-looking attributes stored in plain state: aws_db_instance.main (password); aws_iam_access_key.ci (secret, ses_smtp_password_v4); random_password.db (bcrypt_hash, result)
BUCKET ACCOUNT REGION SOURCE UNITS STATES VERSIONING ENCRYPTION REPLICATION
acme-audit-bad 111111111111 eu-west-1 unit 1 2 Suspended AES256 none
acme-audit-good 111111111111 eu-west-1 unit 5 4 Enabled aws:kms (customer-managed key) acme-tfstate-good-replica (eu-central-1, enabled)
acme-audit-legacy 111111111111 eu-west-1 unit 1 1 Enabled aws:kms (customer-managed key) acme-audit-legacy-replica (eu-west-1, enabled)
acme-tfstate-good-replica 111111111111 eu-central-1 discover 0 4 Enabled aws:kms (customer-managed key) replica of acme-tfstate-orphans
acme-tfstate-orphans 111111111111 eu-west-1 discover 0 1 Enabled aws:kms (customer-managed key) acme-tfstate-good-replica (eu-central-1, enabled)
LOCK TABLE ACCOUNT REGION UNITS PITR ENCRYPTION LOCKS
acme-audit-locks-bad 111111111111 eu-west-1 1 off AWS owned key 1
acme-audit-locks-good 111111111111 eu-west-1 1 on KMS 1
suppressed S3-MFA s3://acme-audit-bad (MFA delete needs the root user's device, until 2027-06-30)
suppressed S3-MFA s3://acme-audit-legacy (MFA delete needs the root user's device, until 2027-06-30)
warning: audit.suppress[1] (check S3-LOG) expired on 2026-10-31 and no longer applies: 1 finding(s) reported again
30 findings (10 high, 10 medium, 8 low, 2 info), 2 suppressed; 5 buckets, 2 lock tables; 0 checks could not runThe first table has one row per finding, with the check, the severity, the target and the reason. The bucket and lock table tables summarize what the audit read. The lines at the end list the suppressed findings and a suppression that expired. The audit checks page explains each check, what passes and how to fix a finding.
Output never holds a state attribute value. FL-SECRET lists attribute names, such as password, and the resource address they are in.
Find buckets no unit names
A state bucket that no unit uses anymore still holds state, and often secrets. --discover lists every bucket of each account (s3:ListAllMyBuckets) and audits those that match a pattern and that no unit names. Their state keys show up as FL-ORPHAN:
tfcensus audit backend --profile 'acme-*' --discover
tfcensus audit backend --profile 'acme-*' --discover --discover-pattern 'acme-tfstate-*'The patterns come from --discover-pattern or audit.discover_patterns, and default to *tfstate*, *terraform-state* and *tf-state*.
Set the policy
Five checks compare against thresholds under audit.policy:
audit:
policy:
min_terraform_version: "1.10"
min_provider_versions:
hashicorp/aws: "5.0"
noncurrent_days: 30
stale_lock_hours: 24
max_state_mb: 20| Key | Check | Default |
|---|---|---|
audit.policy.min_terraform_version | FL-TFVER flags states written by an older terraform or OpenTofu. | 1.10 |
audit.policy.min_provider_versions | FL-PROV flags a provider in .terraform.lock.hcl older than its entry. | none |
audit.policy.noncurrent_days | S3-LC wants noncurrent state versions kept at least this many days. | 30 |
audit.policy.stale_lock_hours | LK-STALE flags locks older than this. | 24 |
audit.policy.max_state_mb | FL-SIZE flags states larger than this many MiB. | 20 |
min_provider_versions maps a provider source to a version. It is a map, so it has no environment variable; the other four have one each, such as TFCENSUS_AUDIT_POLICY_STALE_LOCK_HOURS (configuration).
Suppress accepted findings
Some findings are known and accepted. S3-MFA is a common one, because MFA delete needs the root user's device. List them under audit.suppress:
audit:
suppress:
- check: S3-MFA
bucket: acme-audit-*
reason: MFA delete needs the root user's device
expires: "2027-06-30"
- check: "LK-*"
unit: acme-live/sandbox/*
reason: sandbox units share a lock table on purposeA finding is suppressed when it matches every field an entry sets:
| Field | Matches |
|---|---|
check | The check ID, or a glob such as LK-*. |
bucket | The bucket name, as a glob. |
unit | The unit, as a repo/path glob. |
key | The state key or the lock table, as a glob. |
reason | Required. Why the finding is accepted. |
expires | Optional. The last day the entry applies, as a quoted "YYYY-MM-DD" date in UTC. |
A suppressed finding is not dropped. Text and Markdown list it after the tables with the suppression's reason, JSON puts it in a suppressed list, and SARIF marks the result with a suppression, so a reviewer can see what was accepted. After expires, the entry stops matching, the finding comes back, and a warning names the entry:
warning: audit.suppress[1] (check S3-LOG) expired on 2026-10-31 and no longer applies: 1 finding(s) reported againSuppressed findings don't count for --fail-on.
Gate CI on severity
--fail-on takes one severity, info, low, medium or high. The command exits 3 when an unsuppressed finding is at or above it. SARIF output goes to GitHub code scanning:
tfcensus audit backend --profile 'acme-*' --fail-on high --out sarif=reports/audit.sarif --out json=reports/audit.jsonThe exit code is 1 when a check couldn't run, such as a call that was denied, and 4 when every failure was a credential problem. The summary line says how many checks couldn't run. A denied call names the action, and the read-only IAM policy grants every one the audit makes.
tfcensus notify posts the JSON report to Slack, an issue or a pull request (Publish reports), and tfcensus report html adds it to the HTML report.