Assess Azure Security Compliance with cnspec
cnspec assesses your full Microsoft Azure environment for misconfigurations that put your organization at risk. You can scan your Azure tenant for compliance with security policies created by Mondoo or the community, or create your own policies. You also can write individual tests to run on the fly or include in automated tasks.
cnspec can test any aspect of your Azure configuration. For a list of Azure resources you can test, read Mondoo Azure Resource Pack Reference and Mondoo Core Resource Pack Reference.
Connect cnspec with your Azure environment
Requirements
To test your Azure environment with cnspec, you must have:
- cnspec installed on your workstation.
- An Azure account
- The Azure CLI installed
Log into Azure
Using the Azure CLI, log into your subscription:
az login
Verify with a quick Azure check
To quickly confirm that cnspec has access to your Azure environment, run this check from your terminal:
cnspec run azure -c 'azure.subscription.resources { id!="foo" }'
It asserts that none of your Azure resources have the ID foo
.
cnspec lists your resources and indicates that the check is true, none of them has foo
as its ID:
azure.subscription.resources: [
0: {
id != "foo": true
}
1: {
id != "foo": true
}
2: {
id != "foo": true
}
3: {
id != "foo": true
}
4: {
id != "foo": true
}
]
You've successfully used cnspec to run your first check on your Azure environment. Now you're ready to explore. The method you choose depends on your goals:
- For widescale assessment of your Azure infrastructure, scan using policy bundles. These collections of tests work together to present a broad picture of your Azure security posture.
- To run ad hoc checks against your Azure environment, use cnspec's interactive shell. It has auto-complete to guide you, which is especially helpful when you're new to cnspec and learning MQL.
Assess Azure security with policy-based scanning
The Azure Security by Mondoo policy is available to all in Mondoo's cnspec-policies GitHub repo. This collection of tests evaluates how well your environment follows fundamental Azure security best practices. It checks for misconfigurations across your entire Azure infrastructure.
To scan using the Azure Security by Mondoo policy, run:
cnspec scan azure
cnspec finds the default policy for Azure and runs a scan based on that policy. It returns a report summarizing the scan results.
You can also create your own policies to meet your specific needs. To learn more about policies, read Policies.
Test Azure with the cnspec shell
The cnspec shell is handy for quick checks and tests, or for developing your MQL skills. Its auto-complete and help features guide you in writing checks.
To launch a shell into your Azure environment, enter:
cnspec shell azure
Discover capabilities with the help
command
Once inside the shell, use the help
command to learn what Azure resources you can test. This command lists all the Azure resources:
help azure
From the resulting list, you can drill down further. For example, enter this command to list all the Azure Compute resources you can test:
help azure.subscription.compute
From the resulting list, you can drill down even further. You can also learn about available Azure resources in the Mondoo Azure Resource Pack Reference.
Run tests in the cnspec shell
Now that you know how to discover what's possible with cnspec, let's run some actual tests in the shell.
Assess SQL server auditing
This test assures that auditing is turned on for your SQL servers:
azure.subscription.sql.servers { auditingPolicy['state'] == "Enabled" }
If the test passes (all SQL servers have auditing enabled) then cnspec returns ok
:
[ok] value: true
If the test fails, (one or more Cloud Storage buckets don't use uniform bucket-level access) then cnspec provides details about the failure.
Assess public access to storage
This test asserts that no storage accounts allow public access:
azure.subscription.storage.accounts { containers { properties['publicAccess'] == "None" }
If one or more storage accounts allow public access, cnspec lists them. Otherwise, cnspec indicates that the test passed.
Exit the cnspec shell
To exit the cnspec shell, either press Ctrl + D
or type exit
.
Learn more about querying Azure
- To learn more about how the MQL query language works, read Write Effective MQL.
- For a list of all the Azure resources and fields you can query, read the Mondoo Azure Resource Pack Reference.