TExcelTAD
Home › Cloud & Container Security › CSPM, CNAPP and a Tiny Posture Checker

CSPM, CNAPP and a Tiny Posture Checker

IaC scanning checks the code; detections watch events; neither tells you what the account looks like right now: every account, every region, every resource, however it was created. Cloud security posture management (CSPM) does that: it inventories resources through the providers' APIs and evaluates them against rules, usually organised by benchmark (the CIS Foundations Benchmarks for AWS, Azure and GCP, AWS Foundational Security Best Practices, Microsoft cloud security benchmark, regulatory frameworks). Over the last few years the market merged CSPM with workload protection, entitlement analysis and Kubernetes posture into CNAPP (cloud-native application protection platforms), whose most useful idea is the attack path: not "47 medium findings" but "this internet-facing instance with IMDSv1 has a role that can read the customer bucket". This lesson builds a tiny CSPM over a synthetic inventory, including one attack-path rule, and uses it to frame the course's mini project.

The vocabulary

Term Covers Examples
CSPM configuration of cloud resources against rules and benchmarks AWS Security Hub CSPM, Defender for Cloud (CSPM), SCC Security Health Analytics; open source: Prowler, ScoutSuite, Steampipe benchmarks, Cloud Custodian
CIEM identities and entitlements: unused, excessive, risky permissions Access Analyzer, Defender CSPM's permissions management (Microsoft retired the separate Entra Permissions Management on 1 October 2025), the analysis of Least Privilege
CWPP workloads: vulnerabilities, malware, runtime behaviour on VMs and containers Inspector, Defender for Servers/Containers, Falco (Runtime Detection)
KSPM Kubernetes cluster and workload configuration kube-bench, Kubescape, Trivy's cluster scanning
CNAPP all of the above plus IaC scanning, correlated into risk and attack paths commercial platforms; the providers' own suites
Benchmark a published, versioned list of recommended settings with audit steps CIS AWS / Azure / GCP Foundations, CIS Kubernetes, CIS EKS/AKS/GKE

Benchmarks change between versions (controls are added, renumbered, retired), so a posture report should always say which benchmark version it measured.

A tiny posture checker

The inventory below is the shape a collector would produce from describe/list calls across the lab account (trimmed to the fields the rules need). Each rule is a function returning findings with a section and severity; the last rule correlates three resources into an attack path.

python · try it yourself
import json

inventory = json.loads("""{
 "account": "123456789012",
 "root": {"mfa": false, "access_keys": 0, "last_used_days": 2},
 "password_policy": {"min_length": 8, "reuse_prevention": 0},
 "users": [{"name": "alice", "mfa": true, "keys": [{"id": "AKIA...1", "age_days": 40}]},
           {"name": "app-legacy", "mfa": false, "keys": [{"id": "AKIA...2", "age_days": 410}]},
           {"name": "bob", "mfa": false, "console": true, "keys": []}],
 "trails": [{"name": "org-trail", "multi_region": true, "logging": true, "log_validation": false}],
 "buckets": [{"name": "lab-public-site", "public": true, "bpa": false, "encryption": "AES256", "tags": {"data": "public"}},
             {"name": "lab-customer-exports", "public": false, "bpa": true, "encryption": "aws:kms", "tags": {"data": "confidential"}}],
 "security_groups": [{"id": "sg-bastion", "ingress": [{"port": 22, "cidr": "0.0.0.0/0"}]},
                     {"id": "sg-web", "ingress": [{"port": 443, "cidr": "0.0.0.0/0"}]}],
 "instances": [{"id": "i-0a1b2c3d4e5f60001", "public_ip": "203.0.113.20", "sgs": ["sg-web"], "imds_tokens": "optional",
                "role": "app-role"},
               {"id": "i-0a1b2c3d4e5f60009", "public_ip": null, "sgs": [], "imds_tokens": "required", "role": "batch-role"}],
 "roles": {"app-role": {"s3_read": ["lab-customer-exports", "lab-public-site"]}, "batch-role": {"s3_read": []}},
 "guardduty": {"eu-west-1": true, "us-east-1": false},
 "ebs_default_encryption": false
}""")
inv = inventory

def rules():
    if not inv["root"]["mfa"]:
        yield "Identity", "CRITICAL", "root user has no MFA"
    if inv["root"]["last_used_days"] < 30:
        yield "Identity", "HIGH", f"root user used {inv['root']['last_used_days']} days ago"
    for u in inv["users"]:
        if u.get("console") and not u["mfa"]:
            yield "Identity", "HIGH", f"console user {u['name']} without MFA"
        for k in u["keys"]:
            if k["age_days"] > 90:
                yield "Identity", "MEDIUM", f"access key of {u['name']} is {k['age_days']} days old"
    if inv["password_policy"]["min_length"] < 14:
        yield "Identity", "LOW", f"password minimum length {inv['password_policy']['min_length']} (< 14)"
    for t in inv["trails"]:
        if not t["log_validation"]:
            yield "Logging", "MEDIUM", f"trail {t['name']}: log file validation off"
    for region, on in inv["guardduty"].items():
        if not on:
            yield "Monitoring", "MEDIUM", f"GuardDuty disabled in {region}"
    for b in inv["buckets"]:
        if b["public"] and b["tags"].get("data") != "public":
            yield "Data", "CRITICAL", f"bucket {b['name']} public but classified {b['tags'].get('data')}"
        if not b["bpa"]:
            yield "Data", "MEDIUM", f"bucket {b['name']}: Block Public Access off"
    if not inv["ebs_default_encryption"]:
        yield "Data", "LOW", "EBS encryption by default is off"
    for sg in inv["security_groups"]:
        for r in sg["ingress"]:
            if r["cidr"] in ("0.0.0.0/0", "::/0") and r["port"] in (22, 3389):
                yield "Network", "HIGH", f"{sg['id']} allows port {r['port']} from {r['cidr']}"
    for i in inv["instances"]:
        if i["imds_tokens"] != "required":
            yield "Compute", "MEDIUM", f"{i['id']} allows IMDSv1"
    # attack path: internet-facing + IMDSv1 + role that reads confidential data
    confidential = {b["name"] for b in inv["buckets"] if b["tags"].get("data") == "confidential"}
    for i in inv["instances"]:
        reachable = i["public_ip"] and any(r["cidr"] == "0.0.0.0/0" for s in inv["security_groups"] if s["id"] in i["sgs"] for r in s["ingress"])
        reads = confidential & set(inv["roles"][i["role"]]["s3_read"])
        if reachable and i["imds_tokens"] == "optional" and reads:
            yield "Attack path", "CRITICAL", (f"Internet -> {i['id']} (public, IMDSv1) -> role {i['role']} -> "
                                              f"reads confidential {sorted(reads)}")

order = ["CRITICAL", "HIGH", "MEDIUM", "LOW"]
findings = sorted(rules(), key=lambda f: (order.index(f[1]), f[0]))
for section, sev, text in findings:
    print(f"{sev:8} {section:11} {text}")
counts = {s: sum(1 for f in findings if f[1] == s) for s in order}
print("\nsummary:", ", ".join(f"{n} {s}" for s, n in counts.items()))
CRITICAL Attack path Internet -> i-0a1b2c3d4e5f60001 (public, IMDSv1) -> role app-role -> reads confidential ['lab-customer-exports']
CRITICAL Identity    root user has no MFA
HIGH     Identity    root user used 2 days ago
HIGH     Identity    console user bob without MFA
HIGH     Network     sg-bastion allows port 22 from 0.0.0.0/0
MEDIUM   Compute     i-0a1b2c3d4e5f60001 allows IMDSv1
MEDIUM   Data        bucket lab-public-site: Block Public Access off
MEDIUM   Identity    access key of app-legacy is 410 days old
MEDIUM   Logging     trail org-trail: log file validation off
MEDIUM   Monitoring  GuardDuty disabled in us-east-1
LOW      Data        EBS encryption by default is off
LOW      Identity    password minimum length 8 (< 14)

summary: 2 CRITICAL, 3 HIGH, 5 MEDIUM, 2 LOW

Each ingredient on its own (an IMDSv1 MEDIUM, port 443 open to the world as a web server should be, a role that reads two buckets) would sit in a long list or not be a finding at all. The attack-path rule joins them: the instance is reachable from the Internet, its metadata service answers plain GETs, and its role reads the confidential exports bucket. That is the SSRF-to-data path of the IMDS lessons, found in configuration before anyone exploits it, and it is the finding to fix first, by any of its links: IMDSv2, narrowing the role, or moving the instance behind a load balancer.

Running posture management well

  • Organisation-wide: delegated administrator, all accounts and regions, new accounts enrolled automatically.
  • Owners and SLAs: every finding routed to the team owning the resource (tags, account mapping), with fix-by dates by severity.
  • Exceptions with expiry: accepted risks recorded with a reason and a review date, never as silent suppressions.
  • Prioritise by paths and data: rank by reachability and the sensitivity of what is reachable, not by count.
  • Remediate at the source: fix the IaC module or the guardrail that allowed the finding, so it doesn't come back; auto-remediation (Cloud Custodian, Config remediation) only for safe, well-tested cases.
  • Measure: findings by severity over time, mean time to remediate, percentage of resources covered by guardrails.

Pitfalls

  • A dashboard with thousands of findings and no owners: posture tools produce work, someone must be assigned to do it.
  • Treating benchmark compliance as the goal: a "passed" CIS control says nothing about your application's IAM design.
  • Ignoring the attack-path view because each individual finding is "only medium".

Practice

1. Set the first instance's imds_tokens to "required". Which findings disappear, and is the account now safe from that path?

The IMDSv1 MEDIUM finding and the CRITICAL attack path disappear. The path is closed for request forgery, but code execution on the instance would still reach the confidential bucket through the role; narrow app-role too.

2. Add a rule: "IAM user with an access key older than 90 days and no use in 30 days". What extra field would the inventory need?

last_used_days per key (from IAM's access-key-last-used data or the credential report). Unused old keys should be deactivated and deleted rather than rotated.

3. Which finding would you report as the top item to the account owner, in one sentence?

"The public web instance i-…0001 still accepts IMDSv1 requests and its role can read the confidential customer-exports bucket, so a single SSRF bug in the web application would expose customer data; require IMDSv2 and remove that bucket from app-role."

Test yourself

What does CSPM evaluate?

  1. Source code
  2. The live configuration of cloud resources against rules and benchmarks
  3. Network packets
  4. Container images only

What is the main idea CNAPP adds on top of individual findings?

  1. More severity levels
  2. Correlating findings into attack paths and risk to data
  3. Cheaper licences
  4. Replacing IAM

Why should a posture report name the benchmark version?

  1. For decoration
  2. Benchmarks add, renumber and retire controls between versions
  3. It is a legal requirement
  4. Scores are identical across versions

How many CRITICAL findings did the checker report?

  1. 1
  2. 2
  3. 3
  4. 4