Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Cloud, Container and Supply Chain Security  ›  Lesson

IaC Scanning and CSPM

CSPM 12 minScan infrastructure-as-code in the pipeline before it is applied, and use cloud security posture management to keep checking the live account for misconfiguration and drift.

IaC Scanning and CSPM

Tiffin's invoices live in a cloud storage bucket. One Friday a developer changes a Terraform file to make a bucket "easier to share", and on Monday a stranger is downloading invoices. Most cloud breaches are not clever hacks; they are misconfigurations. Two checks, one before and one after, catch almost all of them.

The rule

Scan the plan before it's applied; watch the account after.

Infrastructure as code (IaC) describes cloud resources in files, such as Terraform, CloudFormation or Kubernetes manifests, that are reviewed and applied by the pipeline. Because it is code, it can be scanned like code.

IaC scanning reads those files in the pipeline and flags risky settings before anything is created:

resource "aws_s3_bucket_public_access_block" "invoices" {
  bucket                  = aws_s3_bucket.invoices.id
  block_public_acls       = false   # scanner: public access not blocked
  block_public_policy     = false
}

resource "aws_security_group_rule" "ssh" {
  type        = "ingress"
  from_port   = 22
  to_port     = 22
  protocol    = "tcp"
  cidr_blocks = ["0.0.0.0/0"]      # scanner: SSH open to the whole internet
}

The same scanners usually read Kubernetes manifests and Dockerfiles too, so one step in the scan stage covers every kind of infrastructure file in the repository. Like SAST, they point to the exact file and line, which makes the fix obvious to the developer who wrote it.

Typical findings: public storage, databases without encryption, admin ports open to the world, logging switched off, over-broad IAM policies.

Cloud security posture management (CSPM) looks at the live cloud account instead. It continuously compares every real resource with a baseline of secure settings and alerts on anything that breaks it. It catches what the pipeline never sees:

  • drift: a setting changed by hand in the console
  • shadow resources: things created outside IaC altogether
  • new rules in the baseline that old resources now fail

The shortcut

Ask of any cloud risk: "Could it arrive through code, around code, or both?" Through code → IaC scanning in the pipeline. Around code → CSPM. Usually both.

The public invoices bucketStep 1 of 4
  1. Through code

    The Terraform change sets block_public_policy = false. The IaC scanner in the scan stage fails the build. It never reaches the cloud.

Drills

Answer fast — trust the rule.

quick drill

When does IaC scanning catch a misconfiguration?

quick drill

Someone opens a database port to the internet by hand in the console. What catches it?

quick drill

Which Terraform line should an IaC scanner flag?

quick drill

CSPM reports drift on a bucket. What is the best fix?

Remember

  • Scan the plan before it's applied; watch the account after.
  • Through code → IaC scanning; around code → CSPM; usually both.
  • Fix drift in code, not only in the console.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainBefore and after apply

Tiffin defines its cloud setup in Terraform. Explain how IaC scanning and CSPM work together to protect it, using a publicly readable invoices bucket as the example. Say where each check runs, what it catches that the other misses, and what should happen when each one fires.