DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • SSRF Prevention in C#: Securing File Imports From User-Supplied URLs
  • Your Email Security Is a DNS Configuration Problem
  • Securing the IT and OT Boundary in Geospatial Enterprise Systems
  • Smart Controls for Infrastructure as Code with LLMs

Trending

  • Zero Trust for Agents: A New Lens to Secure Agents
  • Engineering Responsible AI for High-Stakes Financial Applications
  • PWA on iOS, Part 6: Performance, Rendering, and Keyboard
  • AI Didn't Replace Software Engineering; It Changed the Bottleneck

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Your Infrastructure Didn't Change, Your Policy Did: Detecting Governance-Transition Drift in IaC

Your Infrastructure Didn't Change, Your Policy Did: Detecting Governance-Transition Drift in IaC

Drift tools miss non-compliance caused by a policy change when IaC and cloud state still match. Here is how to detect it and validate fixes against policy intent.

By 
Raghu Balam
·
Nov. 26, 26 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
3 Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

The Blind Spot

Every infrastructure-as-code (IaC) team knows configuration drift: someone changes a resource in the portal, and the live state no longer matches the Terraform or Bicep in Git. Tools like terraform plan, driftctl, and cloud-native drift detection exist to catch exactly that.

Now consider a different failure:

  • Day 1: Policy v4 allows storage accounts with public network access. Your storage account is compliant.
  • Day 30: Policy v5 requires private endpoints. Nobody touched anything.
  • Day 31: The same storage account is now non-compliant. The IaC still matches the cloud. terraform plan reports "No changes."

Nothing drifted between code and cloud. What drifted is the definition of "correct." I call this governance-transition drift: non-compliance introduced by a policy version change, while IaC and live state remain mutually consistent.

Configuration drift compares IaC to live state; governance-transition drift compares both to a changed policy

Standard drift detection answers: "Does reality match the code?" Governance-transition drift detection answers: "Does the code still match the rules?"

These are different questions, and the second one is usually answered only by a periodic compliance scan, which tells you that a resource fails, but not why it started failing or which policy change caused it.

Why Compliance Scanners Don't Close the Gap

A policy scanner (Azure Policy, OPA/Conftest, Sentinel, AWS Config) will flag the non-compliant storage account after v5 ships. That's useful, but three things are missing:

  1. Causality. The finding says "public access enabled." It does not say "this became a violation when clause SEC-STORAGE-014 was added in v5."
  2. Traceability. The finding points at a cloud resource ID, not at the Terraform module and address that owns it.
  3. Fix quality. Fixes are judged by whether the scanner turns green, not by whether the policy's purpose was met.

Solving these requires treating policy as a versioned artifact and diffing it, the same way we diff code.

The Approach: From Policy Change to Approved Fix

I built a prototype (Python/FastAPI backend, VS Code extension front end, Bicep for the Azure footprint) around the pipeline below. The first five steps explain what changed and which resources are affected; the last three produce a safe fix.

Eight-step pipeline from ingesting policy baselines to an approval-gated pull request

Detection comes down to four ideas: normalize, diff, map, and detect.

  1. Normalize policies into versioned, atomic control clauses.
  2. Diff two policy versions semantically at clause level.
  3. Map each clause to the resources it governs and to the IaC block that declares them.
  4. Detect resources that were compliant under the old version and are not under the new one.

Step 1: Policies as Atomic, Machine-Readable Clauses

Policy documents come in many formats. The first step is to reduce them to one internal shape. A clause has a predicate (what must be true) and, importantly, an intent (why it exists):

Python
 
@dataclass
class IntentMetadata:
    objective: str
    intent_assertions: List[str]

@dataclass
class ControlClause:
    clause_id: str
    name: str
    resource_type: str
    predicate_field: str
    predicate_operator: str   # equals | not_equals | contains | exists
    predicate_value: str
    intent: IntentMetadata
    severity: str = "high"

    def evaluate(self, resource_attributes: dict) -> bool:
        actual = resource_attributes.get(self.predicate_field)
        if self.predicate_operator == "equals":
            return str(actual).lower() == str(self.predicate_value).lower()
        ...


A baseline is just a versioned list of these clauses. Because clauses carry a stable clause_id, two versions can be compared by ID rather than by fuzzy text matching.

Step 2: A Semantic Delta, Not a Text Diff

A text diff of two policy files tells you lines changed. A semantic delta tells you what changed in meaning. Each difference is classified as added, tightened, rescoped, relaxed, or removed.

Table showing that only added, tightened and rescoped clauses can introduce new drift

The asymmetry is the key insight: only three of the five change types can make a previously compliant resource non-compliant, so the detector only needs to examine those.

Python
 
@property
def introduces_drift(self) -> bool:
    return self.change_type in ("added", "tightened", "rescoped")


Step 3: A Dependency Graph From Clause to Source Block

A finding is only actionable if an engineer can go from the finding to the line of code that needs changing. The graph links three layers:

Plain Text
 
policy clause  ->  cloud resource  ->  IaC block (file, module, address)


Each graph node also carries ownership, application, and any active exception (waiver). That last part matters: a resource with a valid, unexpired exception should be reported as excepted, not open.

Step 4: Detecting the Transition

The core algorithm is deliberately small. For each drift-introducing change in the delta:

  1. Find the resources of the type the clause governs.
  2. Evaluate each under the old baseline. For an added clause it was implicitly compliant; for a tightened clause, evaluate the old predicate.
  3. Evaluate it under the new clause.
  4. If it was compliant and is now non-compliant, it is a governance-transition finding.
  5. Apply exception filtering.
Python
 
was_compliant = self._evaluate_under_old(node, change, old_baseline)
is_non_compliant = not clause.evaluate(node.resource.attributes)

if was_compliant and is_non_compliant:
    status = "excepted" if node.exception_id and self._is_exception_valid(node) else "open"
    findings.append(DriftFinding(
        ...
        root_cause={
            "policy_version_old": old_baseline.version,
            "policy_version_new": new_baseline.version,
            "clause_change": change.change_type,
            "iac_live_consistent": True,
        },
        iac_block={"file": ..., "module": ..., "address": ...},
        status=status,
    ))


The "was compliant, now isn't" condition is what separates this from an ordinary compliance scan. It isolates resources whose status changed purely because the rules changed, and the root_cause payload records exactly which versions and which clause were responsible.

This turns a vague notification ("some resources are non-compliant") into a precise, explainable one. From the prototype's demo run:

Finding GD-2026-0001: storage account stproddata01 became non-compliant when clause SEC-STORAGE-014 (Storage Private Endpoint Only) was added in policy v5.0. IaC and live state are identical and unchanged. The offending block is infrastructure/storage.tf, address module.storage.azurerm_storage_account.main.

The Second Problem: Fixes That Satisfy the Scanner but Not the Policy

Once you know what to fix, you have to fix it. Here's a trap: many remediations are judged by whether the scanner passes.

Consider a clause whose predicate is public_network_access == disabled, with the intent "no public path to the data." A quick fix sets the property to disabled. The scanner passes. But if no private endpoint or private DNS zone exists, then nothing can reach the account at all, or worse, a service-endpoint bypass still leaves a path open. The predicate is satisfied; the intent is not.

Comparison of a scanner-only fix that fails intent validation and a complete fix that passes

To catch this, each clause carries intent assertions, and the validator evaluates the post-remediation state against them, not only the predicate:

Python
 
is_scanner_only = clause.evaluate(post_remediation_state) and not passed


The prototype's demo runs both cases against the same clause:

  • Scanner-only fix (public access off, but no private endpoint or DNS link): predicate passes, intent validation fails, flagged as a scanner-only fix.
  • Complete fix (public access off, private endpoint configured, private DNS zone linked): both pass.

This is cheap to express and surfaces a class of "green but wrong" changes that otherwise get merged.

Generating the Fix in the Right Dialect

Remediation is emitted in the same IaC format as the finding's source block (Terraform, Bicep, CloudFormation), as a before/after patch rather than an essay. Each remediation carries:

  • the exact property change,
  • the Well-Architected Framework recommendation it satisfies (for example, Azure WAF SE:06 for network isolation),
  • a pointer to the official verified module (Azure Verified Modules for Terraform/Bicep) so teams converge on maintained patterns instead of hand-rolled snippets.

For the storage example, the Terraform change is small:

Ruby
 
# before
public_network_access_enabled = true

# after
public_network_access_enabled = false
network_rules {
  default_action = "Deny"
  bypass         = ["AzureServices"]
}


paired with a private endpoint and DNS zone link. The principle is to choose the least-disruptive change that satisfies the intent, and to put it behind an approval-gated pull request with the evidence attached: policy versions, clause, resource, and validation result.

Running It

The prototype includes a runnable demo that loads two sample baselines, computes the delta, detects drift, and then runs the intent validator:

Shell
 
cd backend
python -m src.services.demo


On the bundled sample data, the move from policy v4.0 to v5.0 adds three clauses: private endpoint only, TLS 1.2 minimum, and private DNS zone required. Detection reports five findings across three storage accounts: three open, and two excepted because the legacy account stprodlegacy04 has an active waiver (EXC-2026-001). Every finding records that IaC and live state are still consistent, so a conventional drift tool would have reported nothing.

The demo then runs the intent check from the previous section: the scanner-only fix passes the predicate but fails intent validation, and the complete fix passes both.

Honest Limitations

This is a prototype, and the gaps are worth stating plainly:

  • Tightened vs. changed. The current delta engine classifies any change to a predicate's value, operator, or field as "tightened." Determining whether a change is truly stricter or merely different needs per-operator reasoning (for example, ordering TLS versions, or set inclusion for allowed values). Misclassification here yields false positives.
  • Heuristic intent checks. The intent validator currently matches assertion text (such as "public", "encrypt", "TLS") against known state fields. A production version needs a real exposure and reachability model, for example, NSG rules, routes, and endpoint policies.
  • Sample data. Baselines and the resource graph are in-memory samples. The connectors for Azure Policy, Azure Resource Graph, AWS Config, Sentinel, and IaC parsers exist as scaffolding and need hardening against real tenants.
  • Evaluation scope. Predicates compare flat attributes. Policies with complex conditions (anyOf/allOf nesting, effects like DeployIfNotExists) need a richer clause model.

Takeaways

  1. Treat policy as a versioned input to your delivery pipeline. If code is diffed and reviewed, the rules it is judged against deserve the same discipline.
  2. Diff at the clause level. Only added, tightened, and rescoped clauses can create new violations, which keeps detection focused and explainable.
  3. Record causality. "Compliant under v4, non-compliant under v5, IaC unchanged" is far more actionable than a bare violation list, and it makes policy rollouts something you can preview before they land.
  4. Validate intent, not just predicates. A fix that silences the scanner but leaves the exposure intact is worse than no fix, because it ends the investigation.

A natural next step is to run the delta before a policy is published, as a blast-radius preview: "if v5 ships today, these resources, owned by these teams, in these repositories, become non-compliant." That turns governance changes from surprises into planned migrations.

Domain Name System Infrastructure security

Opinions expressed by DZone contributors are their own.

Related

  • SSRF Prevention in C#: Securing File Imports From User-Supplied URLs
  • Your Email Security Is a DNS Configuration Problem
  • Securing the IT and OT Boundary in Geospatial Enterprise Systems
  • Smart Controls for Infrastructure as Code with LLMs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook