Skip to content
Tutorials Center
My learning

Topics

Lesson 44 of 57 ยท Security, Monitoring and Cost

Security Best Practices and Defender for Cloud

Learn Azure security: shared responsibility, defense in depth, zero trust, secure score, Defender for Cloud, encryption and the misconfigurations that cause breaches.

Moving to the cloud does not make you secure, and it does not make you insecure either. It changes who is responsible for what. Microsoft secures the datacenters, the hardware and the hypervisors. You secure your identities, your data, your configuration and your code. Almost every real cloud breach comes from the second list: a storage container left public, a management port open to the internet, an over-privileged account, a leaked key.

This lesson gives you a mental model (shared responsibility, defense in depth, zero trust), then shows how Microsoft Defender for Cloud measures your posture with recommendations and a secure score, what encryption Azure provides, and the misconfigurations to look for first. The commands are read-only because they need a subscription. The runnable examples are JavaScript stand-ins: a configuration scanner that flags the classic mistakes, and a layer model that shows why one control is never enough.

The shared responsibility model

You met this idea in What Is Cloud Computing?. The security view of it is a matrix: the more managed the service, the more Microsoft does.

You always own Depends on the service type
Your data and its classification Operating system patching (yours on VMs, Microsoft's on PaaS)
Identities, accounts and access Network controls (yours to configure on every type)
Devices that connect Application code and its dependencies (yours on IaaS and PaaS)

Choosing a PaaS service such as App Service or Azure SQL (see Choosing a Compute Service) removes whole categories of work: nobody forgets to patch the OS that Microsoft patches. But no service takes away your duty to decide who can access what.

Defense in depth

No single control is perfect, so you stack several, each protecting if the previous one fails. Typical layers, from the outside in:

  1. Physical and platform: Microsoft's datacenters (not your job).
  2. Identity: strong authentication, MFA, conditional access (see Microsoft Entra ID).
  3. Perimeter: DDoS protection, firewalls, WAF.
  4. Network: segmentation with subnets and NSGs, private endpoints (see Network Security Groups and Firewalls).
  5. Compute: patching, endpoint protection, minimum open ports.
  6. Application: secure code, input validation, secrets in a vault (see Key Vault).
  7. Data: encryption, backups, access control, classification.
flowchart TB
    A["Identity<br/>MFA, conditional access"] --> B["Perimeter<br/>DDoS, WAF, firewall"]
    B --> C["Network<br/>subnets, NSGs, private endpoints"]
    C --> D["Compute<br/>patching, minimal ports"]
    D --> E["Application<br/>secure code, Key Vault"]
    E --> F[("Data<br/>encryption, backups, RBAC")]

An attacker has to get through every layer to reach the data.

The stand-in below puts numbers on the idea. The numbers are made up and the layers are treated as independent, which is a simplification (real attackers chain weaknesses and some failures are correlated), but the shape of the result is real: several imperfect layers beat one strong one, and removing any layer lets many more attempts through.

JS Why layers beat a single control

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Zero trust

The older security model was a castle: a hard outside, a trusted inside. Once an attacker got in, or a laptop with malware joined the network, everything was reachable. Zero trust drops the idea of a trusted network. Its three principles:

  • Verify explicitly. Authenticate and authorize every request using all available signals: identity, device health, location, risk level.
  • Use least privilege. Give the minimum access, for the minimum time, with just-in-time elevation (Privileged Identity Management) and scoped RBAC (see Role-Based Access Control).
  • Assume breach. Design as if an attacker is already inside: segment networks, encrypt everything, log everything, and limit the blast radius.

In Azure this translates into conditional access policies, managed identities instead of shared secrets, private endpoints instead of public ones, and policy that forbids insecure configurations (see Azure Policy, Locks and Tags).

Microsoft Defender for Cloud

Microsoft Defender for Cloud is the security posture and threat protection service. It does two jobs:

  • Cloud Security Posture Management (CSPM). It continuously compares your resources with a security baseline (the Microsoft cloud security benchmark by default) and gives recommendations: "Storage accounts should restrict network access", "Management ports should be closed on your virtual machines". Each has a severity and a remediation guide, and some have a "Fix" button. The free foundational CSPM tier covers the basics; paid plans add attack-path analysis and more.
  • Cloud Workload Protection (CWP). Paid Defender plans per resource type (Servers, Storage, SQL, App Service, Containers, Key Vault and others) add threat detection: suspicious sign-ins, malware uploads, SQL injection attempts, crypto-mining containers. Alerts show up in Defender and can be sent to Microsoft Sentinel, the SIEM.

The secure score summarizes your posture as a percentage. The more recommendations you resolve, weighted by their impact on the score, the higher it goes. It is a guide to what to fix first, not a certificate of safety: a score of 90 percent does not mean you cannot be breached.

Terminal
# Read-only examples
az security pricing list -o table                        # which Defender plans are on
az security secure-scores list -o table                  # current secure score
az security assessment list --query "[?status.code=='Unhealthy'].{name:displayName, id:name}" -o table
az security pricing create --name VirtualMachines --tier Standard   # enable a plan (costs money)

Treat enabling paid plans as a cost decision (see Pricing, Cost Management and Budgets): turn on the plans for resources that hold real data, and check the price per resource first.

A configuration scanner

The program below is not Defender for Cloud. It is a stand-in that applies the same idea: a list of resources, a list of checks (each with an id, a severity and a test function), and a report sorted worst-first. The resource list is made-up data containing mistakes you see in real subscriptions. It also computes a simplified score as the share of check weight that passes. The real secure score uses its own formula over controls, so the number is only an illustration.

JS A misconfiguration scanner

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Fix the four high-severity findings in the resources array (set publicBlobAccess to false, httpsOnly to true, change the SSH rule's source, set diskEncrypted to true) and watch the score jump. That is how a real remediation plan works: fix by severity, not by convenience. Note what the scanner cannot see, such as a weak password or a vulnerable library. Posture tools find configuration problems, not every kind of problem.

Encryption

Encryption protects data if someone gets the bytes without getting the keys.

  • At rest. Azure Storage, Azure SQL, Cosmos DB and managed disks are encrypted by default with platform-managed keys, using AES-256, with no action from you. If a rule or regulation demands control over the key, use customer-managed keys stored in Key Vault (see Key Vault). For VMs, encryption at host also covers temporary disks and caches.
  • In transit. Require TLS. Set storage accounts to "secure transfer required" and a minimum TLS version of 1.2, make App Service HTTPS only, and turn off plain-text protocols. Between your own services, prefer TLS too.
  • In use. Confidential computing VMs encrypt data while it is processed in memory, for the strictest workloads.

Encryption is not access control: anyone with permission to read the data through the service gets plaintext. That is why identity and RBAC come first.

The misconfigurations that cause real incidents

Learn this list; it covers most of what goes wrong.

  1. Public storage. Blob containers or file shares reachable without authentication. Disable public blob access at the account level.
  2. Open management ports. SSH (22) and RDP (3389) open to * or Internet. Use Azure Bastion or just-in-time access.
  3. Secrets in code or settings. Keys in repositories and pipelines. Use managed identities and Key Vault.
  4. Too much privilege. Owner for everyone, roles assigned at the subscription instead of a resource group, permanent admin accounts.
  5. No MFA on administrator accounts.
  6. Public database endpoints with a firewall rule of 0.0.0.0-255.255.255.255.
  7. No logging. You cannot investigate an incident without audit logs and activity logs (see Azure Monitor, Log Analytics and Application Insights).
  8. Unpatched or forgotten resources: old VMs, test environments that became production.
  9. Weak or missing backups, or backups in the same place as the data.

Many of these can be prevented by policy: deny public blob access, require HTTPS, require tags, allow only approved regions.

A practical order of work

  1. Turn on MFA for every admin and for all users via conditional access.
  2. Enable Defender for Cloud's free posture management and fix the high-severity recommendations.
  3. Remove public access paths: storage, databases, management ports.
  4. Move secrets to Key Vault and use managed identities.
  5. Apply least-privilege RBAC and review role assignments regularly.
  6. Turn on logging and alerts, and enable Defender plans for your most valuable resources.
  7. Use Azure Policy to keep it that way.

Microsoft Sentinel and Conditional Access

Defender for Cloud looks at how well your resources are configured and protects workloads. A SIEM (security information and event management) system answers a different question: across all logs, from Azure, Microsoft 365, firewalls and other clouds, is something suspicious happening right now? Microsoft Sentinel is Azure's cloud-native SIEM and SOAR (security orchestration and automated response). Microsoft is moving the Sentinel experience into the Defender portal, so labels may differ from the Azure portal pages you see; the concepts are stable.

How Sentinel is built

Sentinel is enabled on a Log Analytics workspace (see Azure Monitor, Log Analytics and Application Insights), so everything you know about KQL, tables and retention applies. Its building blocks:

  • Data connectors bring logs in: Microsoft Entra ID sign-in and audit logs, Azure Activity, Microsoft Defender products, Microsoft 365, firewalls, syslog, other clouds. Ingestion is billed per GB, so choose sources deliberately.
  • Analytics rules run KQL on a schedule (or in near real time) and create alerts when a pattern matches, for example "ten failed sign-ins followed by a success". Some rules come from Microsoft, others from templates you tune.
  • Incidents group related alerts for an analyst to investigate, with entities such as accounts, hosts and IP addresses and a timeline.
  • Automation rules and playbooks (built on Logic Apps) respond automatically: disable an account, post to a chat channel, open a ticket.
  • Workbooks and hunting queries let analysts explore data proactively.
KUSTO
// Sentinel analytic rule idea: many failed sign-ins, then success, from one IP
SigninLogs
| where TimeGenerated > ago(1h)
| summarize Failures = countif(ResultType != "0"), Successes = countif(ResultType == "0") by UserPrincipalName, IPAddress
| where Failures >= 10 and Successes >= 1

Conditional Access and its alerts

Conditional Access is the policy engine of Microsoft Entra ID (see Microsoft Entra ID Basics). A policy reads signals (who the user is, which app, device state, location, sign-in risk) and makes a decision: allow, require multifactor authentication, require a compliant device, or block. It is the practical core of zero trust (see the zero trust section above). Roll out new policies in report-only mode first, because a policy that blocks everyone, including you, is an easy mistake; keep at least one excluded emergency access account.

Sentinel and Entra logs give you two useful views: which sign-ins were blocked or challenged by a policy (ConditionalAccessStatus in SigninLogs), and which sign-ins bypassed the intended policies, which hints at a gap. An alert such as "a privileged user signed in with no MFA, from a new country" combines both, and application security with Entra means registering apps, requiring sign-in and checking roles, covered in Managed Identities and Service Principals.

KUSTO
SigninLogs
| where ConditionalAccessStatus == "failure"
| summarize Blocked = count() by AppDisplayName, UserPrincipalName
| order by Blocked desc

Rules and policies: a stand-in

The stand-in runs a tiny Conditional Access evaluator over invented sign-ins and a brute-force detection rule. Real policies have many more conditions and grant controls.

JS Conditional Access decisions and an analytics rule

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Report-only mode is the same evaluator without enforcing the result: it logs what would have happened, so you can find the people a new policy would lock out before it does.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which of these is always the customer's responsibility, even on a fully managed PaaS service?

    Microsoft handles physical and platform layers. Identities, access and data stay with the customer for every service type.
  2. 2. What is the idea behind defense in depth?

    Each layer stops some attacks and limits damage if another layer fails, so the combination is much stronger than any single control.
  3. 3. What does the zero trust principle 'assume breach' lead you to do?

    Assuming an attacker may already be inside pushes you to contain damage and detect it, instead of relying on a trusted perimeter.
  4. 4. What is the secure score in Defender for Cloud?

    The score is a prioritization guide built from recommendations. A high score reduces risk but does not prove safety.
  5. 5. Data in Azure Storage is encrypted at rest by default. Why is that not enough to keep it private?

    Encryption at rest protects against stolen disks or media. It does not stop an over-privileged account or a public container from reading the data.

Summary

  • Security in the cloud is shared: Microsoft secures the platform; you secure identities, data, configuration and code.
  • Use defense in depth (identity, perimeter, network, compute, application, data) and zero trust (verify explicitly, least privilege, assume breach).
  • Defender for Cloud gives recommendations and a secure score (posture) and, with paid plans, threat detection for specific resource types.
  • Data is encrypted at rest by default; require TLS in transit; use customer-managed keys in Key Vault when you must control the key.
  • Fix the classic mistakes first: public storage, open management ports, secrets in code, excess privilege, no MFA, no logging.
  • Use Azure Policy to prevent insecure configurations from coming back.

Next: Pricing, Cost Management and Budgets.