✳ Field lesson CL4 / 13 min

Check the template before the cloud changes

A template change can be checked before it reaches the cloud. A policy check in the pipeline is preventive, and a posture tool on the live account is detective. Drift detection joins them by finding changes the code never saw.

cloudinfrastructure-as-codepolicy-as-codedriftCISSP D8Security+ (SY0-701) D1Security+ (SY0-701) D3

Helpful first: What a container boundary does not stop · Who can write and who can ship

Thirty days to Halcyon · Case 12: The long list · Episode 5 of 5

Thursday. Kael Cho, Staff Infrastructure Engineer, fixed the node role on Monday and uplink-status on Wednesday, both by hand. "Hand fixes come undone," he says. "Templates don't forget."

Sloane Sterling, Head of Compliance, chairs the board at 10:00 tomorrow. She will sign on evidence, not on promises.

At 16:10 a message arrives from Dax Mercer, Software Engineer: "Quick fix in the console. The uplink alarms were flapping." Is the account still what the templates say?

By the end you can

  • Tell a preventive policy check on a template from a detective posture check on a live account
  • Explain how drift happens and how it is caught
  • Place a policy check in the pipeline so a risky change fails before it is applied

A template is a change you can read first

Infrastructure as code (IaC) means describing cloud resources in files that a tool applies. Kael writes templates for the ground-telemetry cluster, the node role, the halcyon-downlink bucket, and the uplink-status deployment and its load balancer. They live in Git, so every change has an author, a reviewer, and a time. That history is the provenance of the account's settings.

Before it changes anything, the tool writes a plan. A plan lists every resource it would create, change, or delete, and how. So a risky setting can be read, and refused, before it exists.

A check on the plan is a preventive control. It stops a change from happening. A posture tool is a detective control. It reads the live account and reports what already exists.

Meridian needs both. The plan check sees only changes that go through the pipeline. The posture tool sees everything in the account, but only after a change is live.

SORT IT OUT

Kael lists five checks for the ground-telemetry account. Which act before a change exists, and which find it afterwards?

  1. A rule in the pipeline that fails any plan giving a role a wildcard action.

  2. A posture rule that flags a bucket someone made public by hand.

  3. Admission control in the cluster that refuses a privileged pod.

  4. A scheduled comparison that reports a setting changed outside the code.

  5. A second engineer reading the plan before anyone applies it.

Show the answers
  1. Preventive, before the change exists. It reads the plan, so the role is never created.
  2. Detective, after it exists. The bucket is already public when the tool sees it.
  3. Preventive, before the change exists. The pod is refused before it starts, even though the check sits outside the pipeline.
  4. Detective, after it exists. It finds a change that has already happened.
  5. Preventive, before the change exists. A review of the plan happens before the account changes.

Policy as code fails the plan

A policy check is a rule written as code and run on every plan. It has three parts: the rule, the input, and the result.

Meridian's rules are short. No pod may set privileged or hostNetwork. No role may allow a wildcard action. The input is the plan, exported as JSON with terraform show -json. A policy engine reads that JSON. Open Policy Agent (OPA), with rules written in a language called Rego, is one such engine. Others do the same job, and none of them is a standard.

The result is pass or fail, with a reason a person can read. A failure stops the pipeline before apply. A pass goes to a reviewer, and only then to apply.

After apply, one more check keeps running. A scheduled job plans against the live account to catch changes made around the pipeline. The next section is about those.

WORKED EXAMPLE

One pull request, two failures

  1. 09:40, the commit. Kael builds his first templates from the files already in Git, with import blocks for the live resources. Nobody had copied Monday's or Wednesday's hand fixes into those files.
  2. 09:42, the plan. The plan would change the live account back. ingest-readonly would allow s3:* on every bucket again, and uplink-status would run privileged on the host network.
  3. 09:43, the check. Two failures: a wildcard action in ingest-readonly, and a pod rule broken by uplink-status. The pipeline stops, and nothing is applied.
  4. The fix. Kael copies the hand fixes into the templates: the narrowed policy, the pod without either setting, and the pod's own identity.
  5. 11:05 and 11:12. The new plan passes. Dax reviews it and approves the merge at 11:05. The pipeline applies it at 11:12.

Result: Both hand fixes are now in code. A later deploy cannot quietly undo them, because the check would fail it first.

PUT IT IN ORDER

Put one template change in order, from the commit to the check that keeps watching afterwards.

  1. The pipeline writes a plan.
  2. An engineer commits the template change.
  3. The pipeline applies the change.
  4. A scheduled drift check compares the account with the code.
  5. A second engineer reviews the plan.
  6. The policy check reads the plan.

Show the answer
  1. An engineer commits the template change.
  2. The pipeline writes a plan.
  3. The policy check reads the plan.
  4. A second engineer reviews the plan.
  5. The pipeline applies the change.
  6. A scheduled drift check compares the account with the code.

The plan has to exist before anything can check it. The machine check runs before the human review, so the reviewer reads a plan that already passes. Apply comes last in the pipeline, and the drift check watches what happens after.

Drift is a change the code never saw

Drift is any difference between the live account and its code. It comes from changes made around the pipeline: a console edit, a command typed during an incident, another tool. Kael's hand fixes on Monday and Wednesday were drift too, in the safe direction.

At 16:10 Dax raises the health check threshold on the uplink-status load balancer, in the console. Its alarms had been flapping during passes. The change is sound. Nothing in the pipeline saw it.

A scheduled job runs terraform plan against the account every 15 minutes. At 16:25 it reports that the load balancer has changed outside Terraform. The next apply would put the old threshold back.

The policy check stopped two risky settings before they existed. Dax's console change never went through the pipeline, so only the scheduled drift check could find it, 15 minutes later.

Drift detection has limits. It checks only the resources the code manages, and only the settings the tool can read. AWS CloudFormation, for example, marks resource types it cannot check as not checked.

YOUR CALL

The 16:10 fix

The 16:25 drift report names Dax's change to the uplink-status load balancer. Dax says the alarms are quiet now and asks you to leave it alone.

  1. What happens to the console change tonight?

  2. When does the change go into the templates?

Show the strong calls
  1. Keep it live, and record who changed what, and why. The alarms stay quiet through the evening pass. The drift report now has a name and a reason beside it.
  2. Within a day, through a pull request that passes the check. Dax opens it that evening. The next apply keeps his threshold instead of reverting it.

What a template check cannot see

A plan check reads what someone intends to build. It cannot see what a workload does at runtime, what data lands in a bucket, or who reads it.

It also misses anything made outside the code. A bucket created by hand never appears in a plan, so no plan check ever judges it. That is why the posture tool keeps running on the live account after the templates exist.

The tool's own records need care too. Terraform keeps a state file that maps the code to real resources. HashiCorp's documentation says state is stored in plain text and can hold secret values from the configuration. The JSON form of a plan can show them as well. Treat both as secrets: encrypted storage, narrow access.

So the pipeline check, the drift check, and the posture tool each cover a gap the others leave. None of them is enough alone.

CHECK YOUR JUDGMENT

Friday, 09:30. Sloane asks you what evidence shows the path will stay closed after the board signs at 10:00. Which answer gives her that?

CASE FILE · CASE 12 · ENTRY 5 OF 5

Answer the closing question correctly to add this entry to your case file.

Fixed in code, held by checks

The path was closed in templates; a pipeline check fails any privileged pod or wildcard action, and a drift check finds console changes the code never saw.

Open the case file ↗

Review sheet: exam notes and quick reference

Find your next idea.

Tip: press / to open search. Escape closes this window.