Security recommendations and score in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time to get security recommendations and scores changes as we check more resources.
How does the work grow when the number of resources increases?
Analyze the time complexity of this Azure Security Center operation.
// Get security recommendations and score for a subscription
var securityClient = new SecurityCenterClient(credentials);
var recommendations = securityClient.Recommendations.List(subscriptionId);
var secureScore = securityClient.SecureScores.Get(subscriptionId);
foreach (var rec in recommendations)
{
Console.WriteLine($"Recommendation: {rec.Name} - Status: {rec.Status}");
}
Console.WriteLine($"Secure Score: {secureScore.Score}");
This code fetches all security recommendations and the overall secure score for a subscription, then lists them.
Look at what repeats when fetching recommendations and scores.
- Primary operation: API call to list all security recommendations.
- How many times: One call to get all recommendations, but internally it may page through many items.
- Secondary operation: Single API call to get the secure score.
- Dominant operation: Listing recommendations, because it may involve many items and paging.
As the number of recommendations grows, the time to fetch them grows roughly in direct proportion.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 recommendations | About 1-2 API calls (depending on paging) |
| 100 recommendations | Several API calls to page through all items |
| 1000 recommendations | Many API calls, roughly proportional to number of pages |
Pattern observation: More recommendations mean more paging calls, so time grows roughly linearly with the number of recommendations.
Time Complexity: O(n)
This means the time to get all security recommendations grows roughly in direct proportion to how many recommendations there are.
[X] Wrong: "Getting security recommendations is always a single quick call regardless of number of resources."
[OK] Correct: The API pages results, so more recommendations mean more calls and more time.
Understanding how API calls grow with data size helps you design efficient cloud monitoring and security checks in real projects.
"What if we fetched recommendations for multiple subscriptions instead of one? How would the time complexity change?"
Practice
Solution
Step 1: Understand the purpose of security score
The security score is designed to give a simple measure of how secure your cloud environment is.Step 2: Identify what the score reflects
It reflects how many security recommendations you have fixed and how protected your resources are.Final Answer:
A number showing how well your cloud resources are protected -> Option AQuick Check:
Security score = protection level [OK]
- Confusing security score with cost or usage metrics
- Thinking it counts users or storage instead of security
- Assuming it is a percentage instead of a score
Solution
Step 1: Identify the command related to security
The command to get security recommendations and score is under the 'security' group in Azure CLI.Step 2: Match the command to the correct syntax
'az security assessment list' lists security assessments and recommendations.Final Answer:
az security assessment list -> Option DQuick Check:
Security info = az security assessment list [OK]
- Choosing commands unrelated to security
- Confusing VM or storage commands with security commands
- Using commands that list resources but not security info
az security assessment list and see 5 recommendations. After fixing 3, what happens to your security score?Solution
Step 1: Understand how fixing recommendations affects score
Fixing security recommendations improves your protection, so the score should increase.Step 2: Eliminate incorrect options
The score does not decrease or reset to zero when fixing issues; it reflects improvement.Final Answer:
It increases because you fixed some recommendations -> Option BQuick Check:
Fixing issues = score up [OK]
- Thinking score decreases when fixing issues
- Believing score stays constant regardless of fixes
- Assuming score resets after changes
az security assessment list but got an error saying 'command not found'. What is the likely cause?Solution
Step 1: Analyze the error message
'Command not found' usually means the CLI tool or extension is missing or outdated.Step 2: Check other options
Internet off would cause different errors; subscription content or VM location does not cause 'command not found'.Final Answer:
Azure CLI is not installed or not updated -> Option AQuick Check:
Command not found = CLI missing or outdated [OK]
- Assuming internet off causes 'command not found'
- Thinking subscription content affects command availability
- Trying to run commands only inside VMs
Solution
Step 1: Identify the security risk
Open ports increase attack surface; closing unnecessary ports reduces risk.Step 2: Choose the best action to reduce risk
Network security groups control ports; closing ports improves security score.Step 3: Eliminate unrelated options
Increasing VM size, adding storage, or creating networks do not reduce open ports or improve security score.Final Answer:
Close unnecessary ports using network security groups -> Option CQuick Check:
Close ports = better security score [OK]
- Thinking bigger VMs improve security score
- Adding storage or networks unrelated to port security
- Ignoring network security group rules
