Microsoft Azure Learning Journey

Azure Policy and Defender for Cloud: Guardrails That Scale

Prevent risky configurations, measure security posture, and collect operational evidence without confusing policy with access control.

10 min read · 1846 words
Microsoft AzureAzure PolicyMicrosoft Defender for CloudCloud SecurityDevOps
Azure Policy and Defender for Cloud: Guardrails That Scale cover image

One team deploys resources in any region, another skips diagnostic settings, and a third exposes a service publicly to fix a deadline. Security reviews find the problems later, when the platform already contains hundreds of resources and each correction is a separate project.

Azure Policy and Microsoft Defender for Cloud help address different parts of this challenge. Policy evaluates and governs resource configuration. Defender for Cloud assesses posture and, depending on the enabled plan, provides workload protection and security findings. Neither replaces identity, network controls, monitoring, or engineering ownership.

What you’ll learn

Where this fits

This is Module 9 and Phase 2, Part 5. It builds on Key Vault and managed identities. The last Phase 2 article is the GitHub Actions OIDC deployment lab, which uses the identity and access patterns from the phase.

Prerequisites


Azure Policy: express a resource rule and assign it to a scope

Azure Policy evaluates Azure resources and certain requests against a policy definition. An initiative (policy set) groups definitions that support a shared objective, such as allowed locations or secure resource configuration. A policy assignment applies a definition or initiative to a scope such as a management group, subscription, resource group, or supported resource.

Policy assignments inherit down resource hierarchy scopes. Exclusions should be deliberate, documented, and time-bounded where possible.

Effects determine the behavior

Effect behavior depends on the policy and resource operation. Policy is not a universal real-time network firewall or a substitute for RBAC. It can constrain resource configuration while Azure RBAC still controls who may make a request.

Roll out guardrails safely

  1. Start with audit to learn which resources would be affected.
  2. Check compliance and exceptions with the resource owners.
  3. Test the policy in a development scope, including create, update, and remediation behavior.
  4. Move to deny or remediation effects only when the operational path and permissions are understood.
  5. Monitor exemptions and exclusions, and review them for expiration.

For modify and deployIfNotExists, distinguish evaluation from remediation. The assignment identity needs appropriate permissions for the action it performs. Granting broad Owner to make remediation work is a warning sign; identify the required operations and scope instead.

Microsoft Defender for Cloud: posture and workload protection

Microsoft Defender for Cloud is a cloud security platform that brings together cloud security posture management (CSPM), workload protection (CWPP), and development security capabilities. It can assess supported Azure, hybrid, and multicloud environments, with features and coverage depending on the connected environment and enabled plans.

Recommendations highlight security improvements based on assessments. A secure score summarizes a set of findings under a particular score model. It is a prioritization aid, not proof that a system is secure, compliant, or free of vulnerabilities. Current Defender experiences and score models can differ between portals; verify the model and scope before comparing numbers.

Some baseline posture capabilities are available without enabling paid workload plans; advanced protections are plan-specific and may charge based on resources or usage. Review the current subscription plan, resource coverage, and pricing before enabling a plan. Do not activate every plan in a learning subscription just to make a score change.

Defender for Cloud findings are inputs to engineering decisions. Assign an owner, evaluate business impact, test remediations, and track accepted risks with an expiration and accountable approver.

Audit and diagnostics: collect evidence for different questions

The Azure Activity Log records subscription-level control-plane events, such as who initiated a resource change and whether it succeeded. It is available for Azure subscriptions, but retaining, routing, and analyzing it beyond the built-in experience requires configuration.

Resource diagnostic settings route logs and metrics emitted by individual Azure services to destinations such as Log Analytics, Storage, or Event Hubs. The categories differ by service. Log Analytics ingestion and retention can cost money.

Together, these sources answer different questions:

Enable the relevant diagnostics, choose destinations and retention to meet requirements, and verify that records actually arrive. A configured destination is not proof of complete coverage.

Hands-on: inspect policy assignments

This read-only exercise does not create assignments, change policy, or enable Defender plans.

Select your development subscription explicitly:

az account list \
  --query "[?state=='Enabled'].{Name:name, IsDefault:isDefault}" \
  --output table

az account set --subscription "<YOUR_DEVELOPMENT_SUBSCRIPTION_NAME_OR_ID>"

List policy assignments applicable at the selected subscription:

az policy assignment list \
  --disable-scope-strict-match true \
  --query "[].{Name:name, DisplayName:displayName, Scope:scope, PolicyDefinitionId:policyDefinitionId}" \
  --output table

Use the Azure portal’s Policy compliance view or a read-only policy state query to inspect compliance results if your identity can access them. A policy assignment is not the same as a compliance result: the resource evaluation may be pending or may not apply to a particular resource type.

✅ Checkpoint: You can identify a policy assignment’s scope and definition, and distinguish its presence from a resource’s evaluated compliance state. No policy settings changed.

Cost implications

The policy-assignment exercise is read-only and creates no billable resources. Defender for Cloud plans, Log Analytics ingestion and retention, Event Hubs or Storage destinations, and remediation deployments can incur charges. Estimate the specific plan and data volume before enabling broad coverage; check current regional pricing and terms.

Troubleshooting

Production-readiness checklist

Cleanup

This exercise only reads policy assignments and optionally views compliance results. It creates no Azure resources or policy changes. No cleanup is required.

Key takeaways

Quick self-check

  1. Does an Azure Policy audit effect block a non-compliant resource deployment?
  2. What identity performs a DeployIfNotExists remediation?
  3. Which log source records a subscription-level resource create operation?
  4. Does a higher Defender secure score guarantee compliance?

Answers

  1. No. Audit records the state; it does not deny the request.
  2. The managed identity configured for the policy assignment, with required remediation permissions.
  3. Azure Activity Log.
  4. No. It is a prioritization metric for its included assessment model, not proof of compliance or security.

References

What’s next

The final Phase 2 article is a hands-on project: Deploy from GitHub Actions to Azure Without a Client Secret. It creates a GitHub environment-bound federated identity, grants resource-group access, and tests both success and denial.


Series navigation


Disclaimer: Azure Policy behavior, Defender plans, portal experiences, log categories, and pricing change. Verify current documentation before implementation.

Share this article

LinkedIn post draft