Use the azurerm_security_center_policy InSpec audit resource to test properties of the default Security Center Policy. Azure currently only supports looking up the default policy via their Rest API. If you attempt to look up a different Security Policy you will receive an error.
An Azure Security Center Policy defines a set of controls recommended for resources within this subscription. These settings will generate alerts if something is found to violate the recommendations. This resource allows you to inspect what alerts you have configured for your account.
This resource interacts with version 2015-06-01-Preview of the Azure Management API. For more information see the official Azure documentation.
At the moment, there doesn’t appear to be a way to select the version of the Azure API docs. If you notice a newer version being referenced in the official documentation please open an issue or submit a pull request using the updated version.
This resource is available in the inspec-azure resource pack. To use it, add the following to your inspec.yml in your top-level profile:
depends:
- name: inspec-azure
git: https://github.com/inspec/inspec-azure.git
You’ll also need to setup your Azure credentials; see the resource pack README.
This resource first became available in 1.0.0 of the inspec-azure resource pack.
An azurerm_security_center_policy resource block identifies a Security Center Policy by name. In the current Rest API you may only lookup a default policy. If no policy is given the default one will be used.
describe azurerm_security_center_policy(name: 'default') do
...
end
describe azurerm_security_center_policy(name: 'default') do
it { should exist }
end
describe azurerm_security_center_policy(name: 'default') do
its('log_collection') { should eq('On') }
end
describe azurerm_security_center_policy(name: 'NonDefaultPolicy') do
it { should_not exist }
end
nameThe name of the Security Center Policy. It must be default. If no name is given then it will search for the default Security Center Policy (Optional).
describe azurerm_security_center_policy(name: 'default') do
its('log_collection') { should eq('On') }
end
idnamelog_collectionpatchbaselineanti_malwaredisk_encryptionnetwork_security_groupsweb_application_firewallnext_generation_firewallvulnerability_assessmentstorage_encryptionjust_in_time_network_accessapp_whitelistingsql_auditingsql_transparent_data_encryptionnotifications_enabled,send_security_email_to_admincontact_emailscontact_phonepricing_tierThe id of the Security Center Policy.
its('id') { should eq('/subscriptions/<SUBSCRIPTION_ID>/providers/Microsoft.Security/policies/default') }
The name of the Security Center Policy.
its('name') { should eq('default') }
Log collection indicates if the monitoring agent will collect security data (On|Off).
its('log_collection') { should eq('On') }
Cost/Feature Model under which the subscription is operating (Standard|Free).
its('pricing_tier') { should eq('Standard') }
Patch indicates if system updates should be enabled for virtual machines (On|Off).
its('patch') { should eq('On') }
Baseline indicates if OS vulnerabilities recommendations for virtual machines are enabled (On|Off).
its('baseline') { should eq('On') }
Anti-Malware indicates if endpoint protection recommendations for virtual machines are enabled (On|Off).
its('anti_malware') { should eq('On') }
Disk Encryption indicates if recommendations for virtual machines are enabled (On|Off).
its('disk_encryption') { should eq('On') }
Network security groups indicates if recommendations for virtual machines are enabled (On|Off).
its('network_security_groups') { should eq('On') }
Web application firewall indicates if recommendations for virtual machines are enabled (On|Off).
its('web_application_firewall') { should eq('On') }
Next generation firewall indicates if recommendations for virtual machines are enabled (On|Off).
its('next_generation_firewall') { should eq('On') }
Vulnerability assessment indicates if recommendations for virtual machines are enabled (On|Off).
its('vulnerability_assessment') { should eq('On') }
Storage Encryption indicates if new data in Azure Blobs and Files will be encrypted by default (On|Off).
its('storage_encryption') { should eq('On') }
Just in time network access indicates if recommendations for virtual machines are enabled (On|Off).
its('just_in_time_network_access') { should eq('On') }
App whitelisting indicates if adaptive application controls are enabled (On|Off).
its('app_whitelisting') { should eq('On') }
SQL auditing indicates if auditing and threat detection recommendations are enabled (On|Off).
its('sql_auditing') { should eq('On') }
SQL transparent data encryption indicates if recommendations are enabled (On|Off).
its('sql_transparent_data_encryption') { should eq('On') }
Notifications enabled indicates if security alerts are emailed to the security contact (true|false).
its('notifications_enabled') { should eq(true) }
Send security email to admin indicates if the subscription admin will receive security alerts (true|false).
its('send_security_email_to_admin') { should eq(true) }
Contact emails contains a list of security email addresses.
its('contact_emails') { should include('[email protected]') }
Contact phone contains the security contact phone number.
its('contact_phone') { should eq('1-111-111-1111') }
There are additional attributes that may be accessed that we have not documented. Please take a look at the Azure documentation. Any attribute in the response may be accessed with the key names separated by dots (.).
The API may not always return keys that do not have any associated data. There may be cases where the deeply nested property may not have the desired attribute along your call chain. If you find yourself writing tests against properties that may be nil, fork this resource pack and add an accessor to the resource. Within that accessor you’ll be able to guard against nil keys. Pull requests are always welcome.
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our Universal Matchers page.
The control will pass if the resource returns a result. Use should_not if you expect zero matches.
# default should always exist
describe azurerm_security_center_policy(name: 'default') do
it { should exist }
end
# this security center policy should not exist
describe azurerm_security_center_policy(name: 'DoesNotExist') do
it { should_not exist }
end
Your Service Principal must be setup with a contributor role on the subscription you wish to test.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/inspec/resources/azurerm_security_center_policy/