Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 38 ยท Projects and Practice

Project: A Cloud Configuration Auditor

Build a small cloud configuration auditor step by step: a rule registry, a JSON inventory, severity scoring, suppressions with expiry, a report and a CI exit code.

In this project you will build a small cloud configuration auditor: a program that reads a description of cloud resources, applies security rules, handles approved exceptions and produces a report that a pipeline can act on. It combines ideas from the whole chapter: posture management, policy as code, IaC scanning and quality gates.

Everything runs in your browser on invented data. The inventory format is deliberately simple JSON, so you can reuse the auditor later on exports from your own accounts, for example the output of read-only listing commands. Only audit environments you own or are authorised to assess.

What we are building

flowchart LR
    A["inventory.json"] --> B["Rule registry"]
    B --> C["Findings"]
    S["suppressions with expiry"] --> D["Filter"]
    C --> D
    D --> E["Report: text and JSON"]
    E --> F["Exit code for CI"]

Five small parts: inventory, rules, suppressions, report, exit code.

Requirements:

  1. Rules are small functions registered with an ID, a title and a severity.
  2. Each finding names the resource, the rule and a fix suggestion.
  3. Suppressions need a reason and an expiry date; expired ones stop working.
  4. The report is sorted by severity and available as text and as JSON.
  5. The program fails (non-zero exit) if any unsuppressed finding is HIGH or CRITICAL.

Step 1: the inventory and the rule registry

A decorator registers each rule in a list, so adding a rule means adding one function. The inventory below is invented.

Python Step 1: rules that yield findings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The auditor already finds eight problems across seven resources. Notice that adding a new check does not touch the audit loop: this is the same extension pattern real policy engines use.

Step 2: suppressions with an expiry date

Some findings are accepted risks. A suppression must say who accepted it, why and until when. Expired suppressions are ignored, so exceptions cannot live forever by accident.

Python Step 2: apply suppressions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Only the first suppression is honoured. The second expired in February, and the third has no owner and no reason, so it is rejected, which keeps the critical finding on alice visible.

Step 3: report and exit code

Humans want a readable summary; machines want JSON; pipelines want an exit code. One function can produce all three.

Python Step 3: report and CI decision

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The exit code of 1 is what makes a CI job fail. In a real pipeline step you would call sys.exit(exit_code(findings)) after printing.

Step 4: extend it

You now have the skeleton of a real tool. Try these extensions, ordered from easy to hard:

  1. Add three rules of your own: an access key older than 90 days, a database with no encryption at rest and a security group that opens port 3389 to the world.
  2. Group the report by owner, using a tags field in each resource, so each team sees its own findings.
  3. Add a baseline file. Store today's findings; on the next run report only new findings, so a legacy estate can adopt the tool without drowning.
  4. Add compliance mapping: give each rule a list of framework controls (for example a CIS item), and print a coverage table like the one in compliance frameworks.
  5. Add drift detection by comparing the live inventory with a desired-state file, as in the posture lesson.
  6. Read real data (authorised accounts only). Export configuration with the provider's read-only CLI into JSON, write an adapter function that maps it to your inventory shape and run the rules.

Design notes worth remembering

  • Rules fail safe. A missing field should count as a violation or a "cannot determine", not a pass.
  • Findings carry fixes. A tool that explains how to repair a problem gets used.
  • Exceptions expire. Time limits turn permanent blind spots into scheduled reviews.
  • Separate data, rules and output. That separation is what lets the same engine run in a laptop, a pull request or a nightly job.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why register rules with a decorator and a list?

    A registry separates rule definitions from the engine. The same pattern is used by real policy and lint tools.
  2. 2. Which suppression should the auditor reject?

    Accountability needs an owner and a reason, and an expiry date makes sure that the exception is reviewed.
  3. 3. What is the purpose of the non-zero exit code?

    Pipelines treat a non-zero exit status as a failed step, which stops the merge or deployment.
  4. 4. Why should a missing field in the inventory not count as a pass?

    If the data is incomplete, the auditor cannot prove the resource is safe, so it should flag it.

Summary

  • You built an auditor from four parts: a rule registry, an inventory, suppressions with expiry and a report with an exit code.
  • Findings should include severity and a fix suggestion; the output should serve humans, machines and pipelines.
  • Exceptions need an owner, a reason and an expiry date, and rules should fail safe.
  • The skeleton extends naturally to baselines, owners, compliance mapping and drift detection.

Next: Project: A Log Threat Hunter