Skip to navigation

Claude Code Policy as Code: Audit Before Deny

In short: Roll out cloud policy checks in audit mode, inspect failures and require reviewed exceptions before enabling deny effects.

Published 20 min read
On this page

Direct answer

An audit effect in Azure Policy reports non-compliance without blocking resource creation or modification. A deny effect blocks the change. Rolling out policy as code for a Claude Code workflow means starting in audit mode, reading what fails, fixing or exempting the legitimate cases, and only then promoting the assignment to deny. An audit finding is evidence that a control was evaluated, not proof the resource is compliant, and it is not a preventive control at all. The sequence matters because a deny effect enabled before the team understands the workload will block legitimate changes in production, and the resulting emergency is worse than the original non-compliance.

The concrete win is a guardrail that prevents a whole class of misconfiguration once it reaches deny. The concrete loss is that audit mode gives a team a false sense of prevention: a dashboard full of audit findings that nobody acts on is not a control. The practical implication is that policy promotion is a governance decision with an owner and a date, not a toggle an engineer flips when the audit report looks clean enough.

Why audit first is not optional

A policy assignment at deny scope is a production change to the platform. When it fires, it rejects a deployment that was otherwise valid from the application team’s point of view. A deny effect on public network access, applied to a subscription where a legacy app intentionally uses a public endpoint, breaks that app on the next deployment. The app team finds out from a failed pipeline, not from a policy review.

Audit mode exists to prevent exactly that. In audit, the same policy definition evaluates the same resources and produces the same compliance state, but nothing is blocked. The team sees the full set of non-compliant resources, can classify them, and can decide which need remediation and which need an exception. Only after that classification is done does deny become safe.

Claude Code’s role in this sequence is to help draft the assignment, run the audit queries and produce the classification. Deciding whether a finding is a real violation or a legitimate exception is a human decision. Letting the agent grant its own exception is the specific anti-pattern this post avoids.

OWASP guidance on AI coding tools treats agent output as untrusted and calls for human review of CI/CD changes, which maps directly onto policy assignments. A policy that fires deny is a CI/CD control, and it deserves the same review discipline as any other change to the deployment path.

Evidence and its limits

Official, F025: Azure Policy built-in definitions cover configuration states including network access, encryption, identity and logging. Coverage varies by Azure service, resource type and policy definition, so a built-in that exists for one service may not have an equivalent for another.

Official, F026: Azure Policy audit effects report non-compliance without blocking resource creation or modification. An audit result is evidence of evaluation, not proof that the resource is compliant with every control, and it does not prevent the non-compliant state from being created.

Official, F027: Azure Policy definitions can use effects including Deny, Modify and DeployIfNotExists in addition to audit effects. Available effects and prerequisites depend on the specific definition and assignment, and some effects require a managed identity or additional configuration.

Official: The Azure Policy overview and the exemption structure pages were not fetched in full during the research pass behind this post. Version-specific fields on exemptions, including expiry and category, should be rechecked against current Microsoft documentation before relying on a fine detail.

Official: The AWS IAM policies reference is the equivalent control surface on AWS, where preventive controls take the form of service control policies and permission boundaries rather than policy definitions with effects. The cloud IAM permission boundary guide covers that mechanism.

Independent: OWASP Secure Coding with AI recommends least privilege and human review for agent-driven infrastructure changes.

No measured compliance improvement, no false positive rate and no remediation time is reported here. Every rollout depends on the actual workloads in the subscription.

Policy as a cloud guardrail

A policy definition describes a condition on a resource and an effect that fires when the condition is met. The condition is expressed in the policy rule as a JSON structure that references resource properties, and the effect determines what happens when the condition evaluates to true. Built-in definitions cover common misconfigurations, and custom definitions cover organization-specific rules.

The three effects that matter for rollout are audit, deny and the remediation effects. Audit reports. Deny blocks. Modify changes the resource during creation or update. DeployIfNotExists deploys a corrective resource when one is missing. Each has different prerequisites and different operational consequences.

Policy effect Operational behavior Review evidence required
Audit Reports non-compliance, blocks nothing Compliance dashboard entry, owner notified
Deny Rejects the create or update request Exception record for any legitimate case
Modify Changes resource properties during write Managed identity, rollback plan
DeployIfNotExists Deploys a missing corrective resource Managed identity, drift risk assessment

Reading the table as a maturity ladder, a team moves from audit to deny only after the audit findings have been classified. Modify and DeployIfNotExists are further along the ladder and carry their own risk, because they change the resource rather than just reporting on it.

Audit mode first

Every new policy assignment starts in audit. The assignment targets a scope, which can be a management group, a subscription or a resource group, and the effect is set to Audit. Within minutes, the compliance dashboard shows which resources in scope violate the condition.

The audit output is a list, and the list is the deliverable. Each entry names a resource, the policy that evaluated it and the compliance state. Claude Code can query the compliance data through the Azure CLI or ARM API and produce a grouped summary: how many resources fail each policy, which resource types are affected, and which subscriptions or resource groups have the highest counts.

bash
az policy assignment create \
--name audit-public-storage \
--policy "storage-accounts-should-not-allow-public-access" \
--scope /subscriptions/00000000-0000-0000-0000-000000000000 \
--params '{"effect": {"value": "Audit"}}'

# query compliance state after the assignment propagates
az policy state list \
--policy-assignment-name audit-public-storage \
--query "[?complianceState=='NonCompliant'].[resourceId, policyDefinitionName]" -o table

The pass condition for the audit phase is not a clean dashboard. It is a classified list: every non-compliant resource is marked as either needs-remediation or needs-exception, with an owner on each. A clean dashboard usually means the policy condition is too narrow, not that the subscription is compliant.

Audit finding Root cause Decision
Storage account created before the policy Legacy resource, predates the rule Remediate or exempt with expiry
Resource created by an automated pipeline Pipeline template does not set the property Fix the template, then remediate
Resource that legitimately needs the state Documented business reason Exception with owner and review date
Policy condition too broad Definition matches unintended resources Refine the definition before deny

Deny and remediation effects

Deny is the effect that changes behavior. When a create or update request matches a deny policy, the Azure Resource Manager rejects it with an error naming the policy. The deployment fails, and the application team sees the failure in their pipeline or CLI output.

Deny is safe to enable for a given definition only after the audit findings for that definition have been resolved. Resources that still violate the condition will not be blocked retroactively by enabling deny, but any new create or update that matches will be. A team that enables deny while unclassified resources still exist will discover those resources the hard way, the next time someone tries to update them.

Modify and DeployIfNotExists are preventive in a different way. Modify rewrites the resource during the write operation, which means the resource lands in a compliant state without the requester doing anything. DeployIfNotExists deploys a separate corrective resource when the condition is met. Both require a managed identity with permission to make the change, which is an additional identity to secure and review. The infrastructure threat model guide covers the trust boundaries around agent-held identities, and the Kubernetes RBAC least privilege reviews guide covers the equivalent least-privilege question for the cluster identity that deploys corrected resources.

Scope and assignment

Policy assignments are scoped. A management group assignment applies to every subscription beneath it. A subscription assignment applies to every resource group and resource beneath it. A resource group assignment applies only to resources in that group. Scope is the primary tool for applying the right control to the right set of resources.

Resource scope Policy assignment Exception owner
Management group: production Deny public storage, deny disk without encryption Platform governance
Subscription: development Audit public storage, audit disk encryption Application team lead
Resource group: legacy-app Exemption for public storage Legacy app owner, expiry 2027-06
Resource group: sandbox No assignment Not applicable

Scope decisions should match the risk of the workload and the trust of the team. A production management group can carry deny effects because the workloads there are expected to be compliant. A development subscription runs audit because experimentation happens there and blocking every non-compliant create would slow the team down.

Claude Code can produce the assignment manifest from a scope and policy list. Reviewing the scope is the reviewer’s job, because a policy assigned at the wrong scope either blocks too much or protects too little. The risk tiered infrastructure approvals guide covers classifying the change by blast radius, which is exactly the discipline a scope decision needs.

Exception workflow

An exception records a decision not to enforce a policy against a specific resource or scope, with a reason and an expiry. The security exception expiry guide covers the register design for exceptions generally. Azure Policy has its own exemption structure, and the two should align.

The workflow that matters for a Claude Code rollout is narrow. The agent can produce an audit report that names resources failing a policy. A human classifies each finding. For findings that are legitimate, a human creates the exemption with an owner, a reason, a compensating control and an expiry. The agent does not create the exemption.

The distinction is worth stating plainly: an agent that can grant its own exception has removed the control entirely. If Claude Code proposes an exemption as part of a change, the proposal goes to a human reviewer, and the reviewer creates the exemption under their own identity. The SOC 2 change evidence guide covers recording who approved the exception.

Exception field Required content Record owner
Resource or scope Specific resource ID or exemption scope Requesting team
Policy definition The specific policy exempted Platform governance
Reason Business justification, not “legacy” Requesting team lead
Compensating control What reduces the risk while the exemption is active Security reviewer
Expiry date A date, not “until further notice” Platform governance

Claude Code review packet

The change packet for a policy assignment contains five artifacts. Each one answers a specific question a reviewer or an auditor will ask.

The policy definition, either a built-in reference or the custom definition JSON, answers what control is being applied. The assignment scope answers where it applies. The audit output at the time of the change answers what failed before deny was enabled. The exception register for that policy answers which resources are legitimately exempt. The approval record answers who authorized the promotion from audit to deny.

Claude Code can produce the first four as text. It cannot produce the fifth, because authorization is a human act. A packet that omits the audit output or the exception register is missing the evidence that makes deny defensible.

Evidence map showing that audit mode measures non-compliance without preventing it, and that deny changes which changes are possible.
Editorial evidence map based on F025 and F026. Audit mode measures a guardrail; deny mode changes which changes are possible. Labels are the post author’s.

Promotion criteria

Promoting a policy from audit to deny is a decision, and the criteria should be written down before the first promotion happens. A checklist that a reviewer can evaluate is better than a judgment call made under pressure.

Criterion Pass condition Who verifies
Audit findings classified Every non-compliant resource marked remediate or exempt Policy owner
Exceptions recorded Each exemption has owner, reason, expiry Platform governance
Legitimate workloads tested A representative deployment succeeds against deny Application team
Rollback path documented Removing the assignment is a known procedure Platform team
Owner named A person owns the deny effect in production Platform governance
Review date set Next review of the assignment is scheduled Platform governance

The rollback path is the one most teams skip. Removing a deny assignment is straightforward, but the person who needs to do it at 3 a.m. during a failed deployment needs to know it is an option and how to do it. The runbook ownership guide covers the documentation structure that makes this discoverable under pressure.

Promotion is not a permanent state. A policy that was promoted to deny and has accumulated exemptions over time may be due for a review of whether the condition is still right, or whether the underlying misconfiguration pattern has been fixed at the template level and the deny is no longer needed. Ownership for the review is a RACI question, and the RACI for infrastructure changes guide covers making the accountable human explicit. Access that the policy grants to the agent identity belongs in the recertification process described by the access recertification guide.

Ongoing policy maintenance

Policies are not write-once. Azure adds new resource types and new built-in definitions regularly, and a custom definition can become stale as the platform evolves. The maintenance questions are the same as for any control: is the condition still right, is the effect still appropriate, and is the exception register still accurate.

A quarterly review aligned to the platform team’s existing cadence is a common pattern. The review reads the current compliance state, the exception register and any recent deployments that hit a deny effect. Findings feed back into definition tuning, exception expiry or template fixes.

Claude Code can help by producing a delta report: which resources became non-compliant since the last review, which exemptions are approaching expiry, and which deny effects fired in the window. Reviewing that report and deciding what to change is a human decision, and the decision belongs to the policy owner rather than to the agent.

Workflow from assigning a policy in audit mode through classifying findings, recording exemptions, promoting to deny, then reviewing compliance on a recurring cadence.
Editorial workflow based on F026 and F027. The sequence describes a reviewable rollout routine; it is not an official Microsoft procedure.

What audit mode does not do

Audit mode has three specific limits worth naming, because they are the failure modes of a rollout that stops at audit.

It does not prevent anything. A resource created in a non-compliant state is created, runs, and may expose data or cost money until someone reads the audit report and acts on it. A team that treats audit findings as a backlog rather than a fire alarm will have non-compliant resources in production indefinitely.

It does not prove compliance. An audit result is a point-in-time evaluation against one condition. It says nothing about the resource’s other properties, its runtime behavior or its access controls. A resource that passes ten audit policies can still be misconfigured in an eleventh way that no policy covers.

It does not assign accountability. A dashboard entry has no owner until a human claims it. The RACI for infrastructure changes guide covers making the accountable human explicit, and the same discipline applies to policy findings.

The concrete win, loss and implication

The concrete win is a guardrail that prevents a class of misconfiguration from reaching production at all once deny is enabled. A deny effect on public storage accounts means no new public bucket can be created in scope, regardless of which engineer or which agent proposed it. The control is at the platform layer, which is the only layer that applies to every deployment path.

The concrete loss is the operational risk of a premature deny. A deny effect enabled before the audit findings are classified will block a legitimate deployment, and the resulting emergency erodes trust in the policy program. Teams that experience one bad deny rollout tend to resist the next one, which is a real cost beyond the immediate incident.

The practical implication is that policy rollout is a governance process with named owners and dates, not a configuration task. The agent can accelerate the classification and the reporting. The decision to enable deny, and the accountability for what it blocks, belongs to a human.

Checklist before enabling deny

Check Pass condition If it fails
Audit phase complete Findings classified, not just observed Extend the audit window
Exceptions registered Every legitimate case has an exemption Create exemptions with expiry
Representative deploy tested A real deployment succeeds against deny Fix the definition or the template
Scope correct Assignment targets the intended resources Adjust scope before enabling deny
Rollback documented Removal procedure is in the runbook Write it before enabling deny
Owner named A person owns the deny effect Assign before enabling deny
Tradeoff between enabling deny immediately for fast prevention and the operational risk of blocking legitimate deployments before audit findings are classified.
Editorial tradeoff diagram based on F026 and F027. Deny prevents at the platform layer; enabling it too early blocks legitimate work and erodes trust in the program.

Policy as code is one governance mechanism among several this batch covers. On the identity side, the cloud IAM permission boundary guide covers capping what an agent identity can receive, which is a complementary preventive control at the identity layer rather than the resource layer. The pod security admission guide covers the equivalent gate for Kubernetes workloads. When the resource being gated is defined in Terraform, the Terraform plan review gates guide covers reading the proposal before it becomes a create or update a policy would evaluate.

On the exception side, the security exception expiry guide covers the register design that every policy exemption should live in. The platform governance council charter guide covers the council that owns the standards the policies enforce.

On cost, the cloud budget and quota guardrails guide covers a different kind of guardrail, where the controlled quantity is spend rather than configuration. The SOC 2 change evidence guide covers the evidence packet that records who approved the policy promotion.

Working with Claude Code on policy rollout

Give the agent three inputs: the policy definition or built-in reference, the target scope, and the desired effect with the promotion plan. Ask for an audit report grouped by resource type and resource group, and ask it to propose exemptions only as proposals for human approval rather than creating them.

Reviewing the proposal is the reviewer’s job. The agent can query compliance data and draft assignment manifests, but deciding which findings are legitimate and which need remediation is a risk decision. The Claude Code verification guide covers the review questions, and the false success guide covers why a clean audit dashboard is not proof of compliance. When the agent’s compliance export is large, the MCP output truncation guide covers why a summarized result can hide the resources that actually failed.

Control checklist covering audit phase completion, findings classification, exception registration with expiry, scope verification, rollback documentation and named ownership before enabling deny.
Editorial control checklist derived from F025 through F027. Passing it shows the promotion was reviewed honestly; it does not guarantee every future deployment will comply.
Verdict that audit mode first, then deny with reviewed exceptions, is the rollout sequence that avoids blocking legitimate work.
Editorial verdict based on F025 through F027. Measure with audit, classify with a human, then prevent with deny and an exception register.

Data gap and future update

The Azure Policy overview and exemption structure pages were not fetched in full during the research pass behind this post. The exact fields available on an exemption, including expiry and category values, and the current set of effects supported for a given built-in definition should be rechecked against current Microsoft documentation before relying on a fine detail. The audit-versus-deny behavior in F026 and the effects list in F027 are documented Microsoft statements.

No measured false positive rate, no remediation time and no compliance score is reported here. A future update quantifying how long a typical audit phase takes for a given subscription size would need telemetry from an actual rollout. No such data was collected.

AWS and GCP equivalents are out of scope beyond the IAM cross-reference. AWS preventive controls take a different form, covered in the cloud IAM permission boundary guide, and the change freeze and emergency change guide covers the emergency path when a deny effect blocks urgent work.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. It is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.

FAQ

Does audit mode prevent misconfiguration?

No. Audit reports non-compliance after the resource is created or updated. Prevention requires a deny effect, or a Modify or DeployIfNotExists effect that changes the resource during write.

Can Claude Code create its own policy exemption?

It should not, and a reviewer should not allow it. An exemption removes the control for a specific resource. The agent can propose an exemption and draft the justification, but a human creates it under their own identity with their own accountability.

What happens to existing non-compliant resources when deny is enabled?

Deny applies to new create and update requests. Resources that already exist in a non-compliant state are not retroactively blocked, but the next time someone tries to update them, the update will be rejected if it still violates the policy.

How long should the audit phase run?

Long enough to capture a representative set of deployments and resource creation. A few weeks is common for a subscription with regular deployment activity. The pass condition is classified findings, not a clean dashboard or a fixed duration.

What is the difference between Modify and DeployIfNotExists?

Modify rewrites properties on the resource during the create or update operation. DeployIfNotExists deploys a separate corrective resource when a condition is met. Both require a managed identity, and both change the resource rather than just reporting on it.

More from this batch

More Claude Code troubleshooting

More Claude Code troubleshooting

Sources

More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →