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
- Distinguish Azure Policy definitions, initiatives, assignments, and evaluations.
- Choose between audit, deny, modify, and deploy-if-not-exists effects.
- Explain remediation identities and why policy does not bypass Azure RBAC.
- Understand Defender for Cloud posture management, recommendations, and paid protections.
- Distinguish Activity Log from resource diagnostic logs.
- Inspect current policy assignments without changing the subscription.
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
- Knowledge: Azure subscriptions, resource groups, Azure RBAC, and basic security operations.
- Azure access: Optional for the read-only exercise; use a subscription you are authorized to inspect.
- Azure RBAC: Read access to applicable policy assignments. Creating policy assignments or remediation tasks requires additional permissions; assigning
modifyordeployIfNotExistspolicies may also require managed-identity configuration and role assignments. - Microsoft Entra roles: None for the CLI inspection. Defender administration and governance features have their own permissions and licensing requirements.
- Tools: Azure CLI 2.91.0 or later.
- Estimated cost: This exercise creates no resources. Defender plans, Log Analytics ingestion/retention, and remediation resources may incur charges; verify current pricing and plan coverage.
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
- Audit: Record a non-compliant configuration without blocking deployment. Useful for discovery and measuring impact.
- Deny: Reject a create or update request that violates the rule. Use after testing and communicating the expected behavior.
- Modify: Change or append supported properties during resource creation or update, subject to policy support and the required identity and permissions.
- DeployIfNotExists: Deploy a related configuration when an evaluated resource lacks it. A managed identity and remediation permissions are needed for remediation; evaluation alone does not grant those permissions.
- Disabled: Do not enforce the definition through that assignment.
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
- Start with audit to learn which resources would be affected.
- Check compliance and exceptions with the resource owners.
- Test the policy in a development scope, including create, update, and remediation behavior.
- Move to deny or remediation effects only when the operational path and permissions are understood.
- 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:
- Activity Log: who changed the Azure resource, and when?
- Resource logs: what did a service do or reject?
- Entra sign-in and audit logs: which identity authenticated or changed directory objects?
- Defender for Cloud: which security recommendations or workload alerts apply?
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
- A deployment is denied unexpectedly: Check the applicable policy assignment, inherited scope, excluded scopes, effect, and policy evaluation details. Confirm the request is not also blocked by RBAC.
- A resource is non-compliant but the policy did not block deployment: The assignment may use
audit, or the existing resource may only be evaluated after creation. Review the definition’s effect and evaluation timeline. - A DeployIfNotExists policy does not remediate: Check whether a remediation task exists, the assignment identity is configured, required roles are assigned at the correct scope, and the template deployment is supported.
- The policy assignment exists but no compliance state appears: Check resource type coverage, assignment scope, exemptions, evaluation status, and permissions to read policy state.
- A Defender recommendation persists after a fix: Verify the resource configuration and wait for reassessment; some recommendations update asynchronously or have prerequisites.
- A secure score changed unexpectedly: Confirm the portal and score model, scope, included standards, recent resource changes, and whether recommendations were added or recalculated.
- Logs are missing from Log Analytics: Check diagnostic settings for the specific resource and log category, destination workspace, identity/permissions, and ingestion delay.
- Monitoring costs rise after enabling diagnostics: Review volume, retention, table plans, and the destination. Route only the log categories needed for the operational or compliance requirement.
Production-readiness checklist
- Reliability: Test policy effects and remediation paths in a safe scope; ensure diagnostic pipelines have health checks and owners.
- Security: Enforce critical configuration with tested deny policies; use narrow remediation identities; enable only Defender plans justified by risk and coverage.
- Cost Optimization: Estimate Defender plans, Log Analytics ingestion, retention, and remediation resources before rollout; avoid unnecessary diagnostic categories.
- Operational Excellence: Assign policy owners, document exemptions, track remediation, and route Activity Log and resource diagnostics to monitored destinations.
- Performance Efficiency: Evaluate policy scope and diagnostic volume to avoid unnecessary evaluations, noisy recommendations, and excessive log ingestion.
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
- Azure Policy evaluates resource configuration; an assignment is not an RBAC grant.
- Initiatives group definitions; assignments apply them to scopes.
- Audit is a safer first rollout step than deny or remediation effects.
- Remediation identities need explicit, appropriately scoped permissions.
- Defender recommendations and score help prioritize work but are not proof of security.
- Activity Log, resource diagnostics, Entra logs, and Defender findings answer different questions.
- Diagnostic ingestion, retention, and Defender plans may incur charges.
Quick self-check
- Does an Azure Policy
auditeffect block a non-compliant resource deployment? - What identity performs a DeployIfNotExists remediation?
- Which log source records a subscription-level resource create operation?
- Does a higher Defender secure score guarantee compliance?
Answers
- No. Audit records the state; it does not deny the request.
- The managed identity configured for the policy assignment, with required remediation permissions.
- Azure Activity Log.
- No. It is a prioritization metric for its included assessment model, not proof of compliance or security.
References
- Azure Policy overview — Microsoft Learn
- Azure Policy definition structure — Microsoft Learn
- Remediate non-compliant resources with Azure Policy — Microsoft Learn
- Microsoft Defender for Cloud overview — Microsoft Learn
- Cloud Secure Score in Microsoft Defender for Cloud — Microsoft Learn
- Azure Activity Log — Microsoft Learn
- Create diagnostic settings — Microsoft Learn
- Microsoft Defender for Cloud pricing — Microsoft Azure
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
- ← Previous: Azure Key Vault and Managed Identities: Secrets Without Hardcoding
- → Next: Deploy from GitHub Actions to Azure Without a Client Secret
- 📚 Full series roadmap
Disclaimer: Azure Policy behavior, Defender plans, portal experiences, log categories, and pricing change. Verify current documentation before implementation.