SSOGEN / Learn / Infrastructure as Code Scanning: Three Terraform Findings and Their Fixes
Learn
Infrastructure as Code Scanning: Three Terraform Findings and Their Fixes
Before Terraform, CloudFormation or Kubernetes files are applied, infrastructure as code scanning reads them and fails the build when a resource breaks a named rule, such as an IAM policy that allows every action.

An IaC scanner works on text, or on the JSON that terraform plan writes, so it runs in a pre-commit hook or a pull request before anything reaches AWS. Each finding names a check ID, a resource and a line range. The file below carries three access mistakes. Infrastructure as code scanning flags all three, and the fixes follow.
What Checkov reports for a hard-coded key, a wildcard policy and open SSH
provider "aws" { region = "eu-west-1" access_key = "EXAMPLEKEYID00000000" secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"}
resource "aws_iam_policy" "deploy" { name = "deploy" policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = "*" Resource = "*" }] })}
resource "aws_security_group" "admin" { name = "admin" vpc_id = var.vpc_id
ingress { description = "SSH" from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] }}Check: CKV_AWS_41: "Ensure no hard coded AWS access key and secret key exists in provider" FAILED for resource: aws.default File: /main.tf:1-5
Check: CKV_AWS_62: "Ensure IAM policies that allow full "*-*" administrative privileges are not created" FAILED for resource: aws_iam_policy.deploy File: /main.tf:7-17
Check: CKV_AWS_63: "Ensure no IAM policies documents allow "*" as a statement's actions" FAILED for resource: aws_iam_policy.deploy File: /main.tf:7-17
Check: CKV_AWS_24: "Ensure no security groups allow ingress from 0.0.0.0:0 to port 22" FAILED for resource: aws_security_group.admin File: /main.tf:19-30Built from Checkov’s public rule documentation (Terraform policy index and check source, read November 18, 2026); not captured tool output. A real run reports more checks, passes included.
Both key values are placeholders. CKV_AWS_41 matches shape, not validity: 20 capital letters and digits in access_key, 40 base64 characters in secret_key. Checkov’s own unit test for the check uses the example key pair that AWS publishes and expects FAILED. The Gitleaks default rule lets that same pair through, because it ends in EXAMPLE.
The fixes, and why each one is an access problem
Every fix narrows who or what can reach something.
| Check | Before | After | If it ships |
|---|---|---|---|
| CKV_AWS_41 | access_key and secret_key written into provider "aws" |
Delete both lines. Locally the provider reads your AWS profile. In CI the job assumes a role through OIDC workload identity federation, so no long-lived key exists. | Anyone who can read the repository, a fork or a laptop clone holds the IAM user’s keys until they are revoked. A key already in history needs revoke, rotate and clean-up, not a new commit. |
| CKV_AWS_62, CKV_AWS_63 | Action = "*" and Resource = "*" in one Allow statement |
Action = ["s3:PutObject"] on arn:aws:s3:::acme-releases/builds/* |
Every principal with the policy attached can call every AWS API on every resource, including iam:CreateAccessKey. |
| CKV_AWS_24 | cidr_blocks = ["0.0.0.0/0"] on port 22 |
cidr_blocks = [var.internal_cidr], or delete the rule: SSOGEN Remote Access opens SSH in the browser through the Gateway, and with an Outbound Connector the private network opens no inbound port. |
Every address on the internet can reach sshd and start guessing passwords. |
CKV_AWS_62 fails only when one Allow statement has * in both Action and Resource. CKV_AWS_63 fails on * in Action alone. HashiCorp’s AWS provider page warns that hard-coded credentials are not recommended in any Terraform configuration.
provider "aws" { region = "eu-west-1" # No keys: the profile or the CI role supplies credentials}
resource "aws_iam_policy" "deploy" { name = "deploy" policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["s3:PutObject"] Resource = "arn:aws:s3:::acme-releases/builds/*" }] })}
resource "aws_security_group" "admin" { name = "admin" vpc_id = var.vpc_id
ingress { description = "SSH from the internal network" from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = [var.internal_cidr] }}What the scanner reads, and what it cannot see
Static rules see the file, not the account it lands in.
- Values set at apply time. A value passed with
-varor aTF_VAR_environment variable is in no file. Scan the plan instead:terraform show -json tfplan.binary > tfplan.json, thencheckov -f tfplan.json. - Remote modules. Checkov reads a registry or git module only when it downloads it (
--download-external-modules). The plan JSON contains the module’s resources already. - Console changes. Someone opens port 22 in the AWS console after apply. The repository still passes; the next
terraform planshows the drift. - Access granted elsewhere. A policy attached by hand or from another state file is not in this repository, so no rule here can judge it.
Identity checks to turn on first
Checkov’s Terraform policy index lists 1,144 check IDs, 456 of them for AWS (counted November 18, 2026). These six catch the common IAM mistakes; the last row is the S3 public-access pair.
| Check ID | What it catches |
|---|---|
CKV_AWS_62 |
A statement that allows * actions on * resources (full administrator) |
CKV_AWS_63 |
* as a statement’s actions |
CKV_AWS_355 |
* as the resource for actions that can be limited to an ARN |
CKV_AWS_286 |
A policy that allows privilege escalation |
CKV_AWS_40 |
Policies attached to users instead of groups or roles |
CKV_AWS_273 |
aws_iam_user resources: “Ensure access is controlled through SSO and not AWS IAM defined users” |
CKV_AWS_20, CKV2_AWS_6 |
An S3 bucket ACL that allows public read, and a bucket with no public access block |
Run it at commit and in the pull request
Pre-commit hook on the laptop
Checkov ships a hook with the ID
checkovthat runscheckov -d .when a.tffile changes. Add it to.pre-commit-config.yamlwithrev: 3.4.5, the release of November 12, 2026. It gives the author the finding before a reviewer sees it.Required check on the pull request
Run the same scan in CI on the plan JSON. Checkov exits non-zero when a check fails, so mark the job as a required status check and the merge stays blocked. Its author can skip a local hook; a required check runs on every pull request.
Accept a risk in the diff, with a reason
Put
#checkov:skip=CKV_AWS_24:Vendor support range, review by 2027-03-31inside the resource block. The output then lists the check as SKIPPED with your comment, and reviewers see the reason in the pull request.
Shift-left security maps the other stages where a check can run, from the IDE to production.
Common questions about IaC scanning
What is infrastructure as code (IaC)?
IaC defines servers, networks and permissions in versioned text files that a tool applies to a cloud account. Terraform uses HCL, AWS CloudFormation uses JSON or YAML templates, and Kubernetes uses YAML manifests. Changes go through review like application code, and an IaC scanner reads the same files before anything is applied.
What is scanning in cyber security?
Security scanning is an automated check of an asset against known-bad patterns. Vulnerability scanners compare software versions with CVE lists. Secret scanners look for credentials. Container image scanning inspects the packages inside image layers. IaC scanning matches infrastructure files against configuration rules, either on a schedule or as a pipeline gate.
Which tools scan infrastructure as code?
Checkov, Trivy and KICS are open-source IaC scanners, all under the Apache 2.0 license. Checkov reads Terraform, plan JSON, CloudFormation, Kubernetes, Helm, ARM and Bicep. Trivy’s misconfiguration scanner carries the former tfsec engine, and Aqua asks tfsec users to move to Trivy. KICS comes from Checkmarx. Format coverage decides the choice: start with the scanner that reads every file type in your repositories.
Is IaC part of CI/CD?
Yes, once infrastructure changes go through pull requests. The pipeline runs terraform plan, then the checks, then terraform apply after approval. The IaC scan is one part of that pipeline: it reads the changed files or the plan JSON, and a failed check blocks the merge the same way a failed unit test does.
Where these rules come from
Every check ID and title above was read at its source on the date below.
Sources, all read 2026-11-18:
- Checkov: Terraform policy index, Quick Start, Suppressing and Skipping Policies, Terraform Plan Scanning, CLI Command Reference
- Checkov source on GitHub: the CKV_AWS_41 check and its unit test, CKV_AWS_62, the pre-commit hooks file
- HashiCorp AWS provider documentation, provider configuration
- The tfsec README (migration to Trivy), the Trivy README and the KICS README
- The Gitleaks default config
- AWS IAM User Guide, access keys
Updated