Skip to content
advanced Phase 16 · Cloud Security Foundations

Cloud Security Posture Management

Continuously benchmark configurations against security baselines.

55m
0 problems
Topic Progress 0%

What CSPM Solves and How It Works

What CSPM Solves

Cloud environments change constantly. Every day, engineers create resources, modify policies, adjust security groups, and toggle settings — often through the console, often under time pressure. Each change is a potential misconfiguration that weakens your security posture. The problem isn't that teams are careless; it's that cloud environments are too complex and too dynamic for manual oversight.

Cloud Security Posture Management (CSPM) is the practice of continuously evaluating your cloud resources against security baselines and compliance frameworks, detecting misconfigurations, and driving remediation. It's the difference between hoping your configurations are correct and knowing they are.

The three core capabilities

1. Continuous assessment against baselines

CSPM tools evaluate your resources against established security frameworks:

  • CIS Benchmarks — vendor-neutral best practices for cloud configuration (e.g., CIS AWS Foundations Benchmark)
  • Custom policies — organization-specific rules (e.g., "all S3 buckets must have encryption enabled")
  • Compliance frameworks — SOC 2, ISO 27001, PCI DSS, HIPAA mappings
# Example CIS benchmark check (pseudo-policy)
policy:
  id: cis-aws-2.1.1
  description: Ensure S3 buckets have default encryption enabled
  resource: aws_s3_bucket
  condition:
    server_side_encryption_configuration:
      rules:
        - apply_server_side_encryption_by_default:
            sse_algorithm: AES256
  severity: high

2. Drift detection

Infrastructure-as-code (IaC) tools like Terraform define your intended state. CSPM detects when the actual state diverges from the intended state:

# Terraform defines: encryption = true
resource "aws_s3_bucket" "data" {
  bucket = "my-app-data"
  server_side_encryption_configuration { ... }
}

# Someone disables encryption via the console
# CSPM detects: actual state != intended state → DRIFT ALERT

Drift is dangerous because it's invisible — the IaC code still says encryption is enabled, but the running resource has it disabled. Without drift detection, you won't discover the problem until a breach occurs.

3. Remediation routing

Finding a misconfiguration is only half the job. CSPM tools route findings to the right team with enough context to fix them:

  • Asset ownership — map each resource to the team that owns it
  • Remediation instructions — not just "this is wrong" but "here's how to fix it"
  • Priority scoring — not all findings are equal; a public production database is more critical than a public dev bucket

How CSPM tools operate

CSPM tools use one or more of these approaches:

  • API-based scanning — the tool calls cloud provider APIs to inventory resources and evaluate configurations. No agents required. This is the most common approach.
  • Agent-based monitoring — lightweight agents on compute instances monitor file integrity, configuration changes, and runtime behavior.
  • Event-driven evaluation — the tool subscribes to cloud provider event streams (e.g., AWS CloudTrail, Azure Activity Log) and evaluates configurations in real time as changes occur.
# Simplified CSPM evaluation logic
def evaluate_resource(resource, policies):
    findings = []
    for policy in policies:
        if not policy.check(resource):
            findings.append(Finding(
                policy=policy,
                resource=resource,
                severity=policy.severity,
                remediation=policy.remediation_steps
            ))
    return findings

# Example: evaluate all S3 buckets against encryption policy
s3_buckets = aws.list_s3_buckets()
for bucket in s3_buckets:
    findings = evaluate_resource(bucket, [encryption_policy, public_access_policy])
    for finding in findings:
        notify_asset_owner(finding)

The CSPM maturity model

Not all CSPM implementations are equal. The maturity progression:

  1. Manual audits — periodic manual checks (quarterly, annually). Slow, incomplete, and outdated immediately.
  2. Automated scanning — continuous API-based assessment against baselines. Catches misconfigurations but generates noise.
  3. Risk-prioritized findings — findings scored by business context (production vs. dev, data sensitivity, exposure). Reduces noise and focuses on what matters.
  4. Automated remediation — common misconfigurations auto-fixed (e.g., auto-enable encryption on new buckets). Human review for complex cases.
  5. Shift-left integration — posture checks integrated into CI/CD pipelines, catching misconfigurations before deployment.

The goal is to progress from reactive (finding misconfigurations after they exist) to proactive (preventing them from being deployed).

Drift Detection and Remediation Workflows

Drift Detection and Remediation Workflows

Drift is the silent killer of cloud security. Your Terraform code says one thing; your running infrastructure does something else. The gap between intended state and actual state is where breaches live.

How drift happens

Drift occurs whenever someone changes a resource outside of the IaC workflow:

  1. Console changes — an engineer logs into the AWS console to "quickly fix" something and forgets to update the Terraform code
  2. Emergency changes — during an incident, someone modifies a security group to unblock traffic and never reverts it
  3. Manual scaling — someone increases capacity manually instead of updating auto-scaling policies
  4. Third-party tools — monitoring or management tools that modify resources as a side effect
# Intended state (Terraform)
resource "aws_security_group" "web" {
  ingress {
    from_port   = 443
    to_port     = 443
    cidr_blocks = ["0.0.0.0/0"]
  }
}

# Actual state (someone added port 80 via console)
# Drift: ingress now has port 80 open in addition to 443
# Terraform plan shows no changes — the code matches the intended state
# But the running resource is different

Detecting drift

CSPM tools detect drift by comparing the actual resource configuration (via API) against the IaC-defined state:

# Drift detection logic
def detect_drift(terraform_state, actual_resources):
    drifts = []
    for resource in actual_resources:
        intended = terraform_state.get(resource.id)
        if intended and intended != resource.actual_config:
            drifts.append(Drift(
                resource=resource,
                intended=intended,
                actual=resource.actual_config,
                differences=compare(intended, resource.actual_config)
            ))
    return drifts

The key challenge is mapping actual resources to their IaC-defined counterparts. This requires consistent tagging and naming conventions.

Remediation workflows

Effective remediation is not just about fixing the misconfiguration — it's about fixing the process that allowed it to happen:

1. Auto-remediation for known patterns:

Some misconfigurations are safe to fix automatically:

# Auto-remediate: enable encryption on unencrypted S3 buckets
def auto_remediate(bucket):
    if not bucket.encryption_enabled:
        s3.put_bucket_encryption(
            Bucket=bucket.name,
            ServerSideEncryptionConfiguration={
                'Rules': [{'ApplyServerSideEncryptionByDefault': {'SSEAlgorithm': 'AES256'}}]
            }
        )
        notify_owner(bucket.owner, "Encryption auto-enabled on bucket")

2. Ticket-based remediation for complex cases:

For changes that might break applications, create a ticket with full context:

Ticket: Security group sg-12345 allows 0.0.0.0/0 on port 22
Resource: sg-12345 (production-web-tier)
Owner: platform-team@company.com
Risk: High — SSH open to the internet on production
Remediation: Restrict source to bastion host security group (sg-bastion)
Reference: CIS AWS Foundations 5.2

3. Process fixes for recurring drift:

If the same type of drift keeps happening, the process is broken:

  • Console access restrictions — use SCPs or IAM policies to prevent console modifications of critical resources
  • Break-glass procedures — define an approved process for emergency changes that includes automatic IaC update
  • Drift detection cadence — run drift detection frequently (hourly, not daily) to catch changes quickly

Measuring posture improvement

CSPM is not a set-and-forget tool. You need to measure whether your posture is improving:

# Posture metrics
def calculate_posture_score(findings, resources):
    total_checks = len(resources) * len(policies)
    passed_checks = total_checks - len(findings)
    return (passed_checks / total_checks) * 100

# Track over time
# Week 1: 72% posture score
# Week 4: 89% posture score
# Week 8: 94% posture score

Key metrics to track:

  • Posture score — percentage of checks passing
  • Mean time to remediate (MTTR) — how quickly findings are fixed
  • Recurring findings — same misconfiguration appearing repeatedly (indicates process failure)
  • Critical findings open — high-severity issues that remain unpatched

The goal is not a perfect score — it's a trend of improvement with critical findings addressed promptly.

Practice Problems

0 / 2 solved
Design a CSPM Policy for Encryption Compliance

Write a CSPM policy (in pseudo-code or Rego/OPA format) that checks whether all EBS volumes in an AWS account have encryption enabled. The policy should flag unencrypted volumes as high severity.

Solution
```rego
# OPA/Rego policy for EBS encryption
package aws.ebs.encryption

default allow = false

allow {
    input.encrypted == true
}

violation[msg] {
    not allow
    msg := sprintf("EBS volume %s is not encrypted", [input.volume_id])
}

# Severity: high
# Remediation: Enable encryption on the volume or replace with an encrypted volume
# AWS CLI: aws ec2 create-volume --availability-zone us-east-1a --size 100 --encrypted
```
The policy evaluates each EBS volume's `encrypted` attribute. If `encrypted` is not `true`, it generates a violation with the volume ID. This policy can be evaluated continuously against all volumes in the account.
Investigate a Drift Alert

A CSPM tool alerts that the security group for your production database has drifted from its Terraform-defined state. The Terraform code shows inbound traffic only from the app tier security group on port 5432. The actual state shows an additional rule allowing 0.0.0.0/0 on port 5432. Describe your investigation and remediation steps.

Solution
1. **Verify the drift**: Use `aws ec2 describe-security-groups --group-ids sg-xxx` to confirm the actual state matches the alert.
2. **Identify the change**: Check CloudTrail for `AuthorizeSecurityGroupIngress` events to find who added the rule and when.
3. **Assess risk**: The database is now accessible from the entire internet on port 5432 — this is a critical exposure.
4. **Immediate remediation**: Remove the 0.0.0.0/0 rule using `aws ec2 revoke-security-group-ingress`.
5. **Root cause**: Determine why the rule was added (emergency change, mistake, malicious).
6. **Process fix**: If it was an emergency change, ensure the break-glass procedure includes reverting changes and updating Terraform. If it was a mistake, implement SCPs that prevent direct console modification of database security groups.
7. **Verify**: Re-run drift detection to confirm the actual state matches the Terraform state.

Quiz

1. A company uses Terraform to manage all infrastructure. An engineer modifies a security group via the AWS console to open port 80 for testing. The Terraform code still shows only port 443. What is this an example of, and why is it dangerous?

Question 1 options

2. Which CSPM capability is most effective at preventing misconfigurations from reaching production?

Question 2 options

3. A CSPM tool reports 500 findings across your cloud environment. The team is overwhelmed and starts ignoring alerts. What is the most effective way to reduce noise while maintaining security?

Question 3 options

Flashcards

Question

What are the three core capabilities of CSPM?

Answer

1) Continuous assessment against baselines (CIS, custom policies, compliance frameworks), 2) Drift detection (actual state vs. IaC-defined state), 3) Remediation routing (findings to asset owners with actionable guidance).

Question

What is configuration drift and why is it dangerous?

Answer

Drift is when the actual resource configuration diverges from the IaC-defined state. It's dangerous because Terraform plan shows no changes — the misconfiguration is invisible to the IaC workflow and persists undetected.

Question

What is shift-left posture management?

Answer

Integrating posture checks into CI/CD pipelines to evaluate configurations before deployment. This prevents misconfigurations from reaching production, rather than detecting them after they exist.

Question

How do you reduce CSPM alert fatigue?

Answer

Prioritize findings by business context (production vs. dev, data sensitivity, exposure), route to asset owners with remediation instructions, and track metrics like posture score and mean time to remediate.

Revision Notes

Key Takeaways

  • 1. CSPM continuously evaluates cloud resources against security baselines and compliance frameworks
  • 2. Drift detection catches when running resources diverge from IaC-defined state — the invisible security gap
  • 3. Shift-left integration prevents misconfigurations from reaching production, rather than detecting them after
  • 4. Risk-prioritization and asset ownership routing are essential for making findings actionable

Interview Tips

  • • Use a concrete example: 'We integrated OPA policy checks into our CI/CD pipeline, which caught a public S3 bucket configuration before it was deployed.'
  • • Explain the drift problem: 'An engineer opened a security group via the console during an incident and never reverted it — drift detection caught it two weeks later.'
  • • Discuss the maturity progression: 'We started with quarterly manual audits, moved to continuous scanning, and now use shift-left to prevent misconfigurations before deployment.'

Cheat Sheet

Cloud Security Posture Management Cheat Sheet

Phase: Cloud Security Foundations | Level: advanced

Three core capabilities:

  1. Continuous assessment — evaluate resources against CIS benchmarks, custom policies, compliance frameworks
  2. Drift detection — compare actual state to IaC-defined state
  3. Remediation routing — findings to asset owners with actionable guidance

CSPM maturity model:

  1. Manual audits (slow, incomplete)
  2. Automated scanning (continuous, noisy)
  3. Risk-prioritized findings (focused on what matters)
  4. Automated remediation (auto-fix known patterns)
  5. Shift-left integration (prevent before deploy)

Drift detection:

  • Occurs when resources are modified outside IaC (console, emergency changes, manual scaling)
  • Dangerous because Terraform plan shows no changes — misconfiguration is invisible
  • Fix: frequent drift detection, console access restrictions, break-glass procedures

Reducing alert fatigue:

  • Prioritize by business context (prod vs. dev, data sensitivity, exposure)
  • Route to asset owners with remediation instructions
  • Track: posture score, MTTR, recurring findings, critical open findings

Key metrics:

  • Posture score (% checks passing)
  • Mean time to remediate (MTTR)
  • Recurring findings (process failure indicator)
  • Critical findings open

Continue Learning

Before You Start

  • No prerequisites listed.