-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from inspec/sql_server
Add azure_sql_server(s) resources
- Loading branch information
Showing
19 changed files
with
495 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
title: About the azure_sql_server Resource | ||
platform: azure | ||
--- | ||
|
||
# azure_sql_server | ||
|
||
Use the `azure_sql_server` InSpec audit resource to test properties and configuration of an Azure SQL Server. | ||
|
||
## Azure REST API version, endpoint and http client parameters | ||
|
||
This resource interacts with api versions supported by the resource provider. | ||
The `api_version` can be defined as a resource parameter. | ||
If not provided, the latest version will be used. | ||
For more information, refer to [`azure_generic_resource`](azure_generic_resource.md). | ||
|
||
Unless defined, `azure_cloud` global endpoint, and default values for the http client will be used . | ||
For more information, refer to the resource pack [README](../../README.md). | ||
|
||
## Availability | ||
|
||
### Installation | ||
|
||
This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure). | ||
For an example `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal). | ||
|
||
## Syntax | ||
|
||
`resource_group` and `name` or the `resource_id` must be given as a parameter. | ||
```ruby | ||
describe azure_sql_server(resource_group: 'inspec-resource-group-9', name: 'example_server') do | ||
it { should exist } | ||
end | ||
``` | ||
```ruby | ||
describe azure_sql_server(resource_id: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}') do | ||
it { should exist } | ||
end | ||
``` | ||
## Parameters | ||
|
||
| Name | Description | | ||
|--------------------------------|-----------------------------------------------------------------------------------| | ||
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` | | ||
| name | Name of the SQL server to test. `MyServer` | | ||
| server_name | Alias for the `name` parameter. | | ||
| resource_id | The unique resource ID. `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}` | | ||
|
||
Either one of the parameter sets can be provided for a valid query: | ||
- `resource_id` | ||
- `resource_group` and `name` | ||
- `resource_group` and `server_name` | ||
|
||
## Properties | ||
|
||
| Property | Description | | ||
|---------------------------|-------------| | ||
| firewall_rules | A list of all firewall rules in the targeted server with [these](https://docs.microsoft.com/en-us/rest/api/sql/firewallrules/listbyserver#firewallrulelistresult) properties. | | ||
| administrators | A list of all administrators for the targeted server with [these](https://docs.microsoft.com/en-us/rest/api/sql/serverazureadadministrators/listbyserver#serverazureadadministrator) properties. | | ||
| encryption_protector | A list of all encryption protectors for the targeted server with [these](https://docs.microsoft.com/en-us/rest/api/sql/encryptionprotectors/listbyserver#encryptionprotector) properties. | | ||
| auditing_settings | Auditing settings for the targeted server with [these](https://docs.microsoft.com/en-us/rest/api/sql/server%20auditing%20settings/listbyserver#serverblobauditingpolicylistresult) properties. | | ||
| threat_detection_settings | Threat detection settings for the targeted server with [these](https://docs.microsoft.com/en-us/rest/api/sql/databasethreatdetectionpolicies/get#databasesecurityalertpolicy) properties. | | ||
| sku | The SKU (pricing tier) of the server. | | ||
|
||
For properties applicable to all resources, such as `type`, `name`, `id`, `properties`, refer to [`azure_generic_resource`](azure_generic_resource.md#properties). | ||
|
||
Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/sql/servers/get#server) for other properties available. | ||
Any attribute in the response may be accessed with the key names separated by dots (`.`), eg. `properties.<attribute>`. | ||
|
||
## Examples | ||
|
||
### Test If a SQL Server is Referenced with a Valid Name | ||
```ruby | ||
describe azure_sql_server(resource_group: 'my-rg', name: 'sql-server-1') do | ||
it { should exist } | ||
end | ||
``` | ||
### Test If a SQL Server is Referenced with an Invalid Name | ||
```ruby | ||
describe azure_sql_server(resource_group: 'my-rg', name: 'i-dont-exist') do | ||
it { should_not exist } | ||
end | ||
``` | ||
### Test If a SQL Server Has Firewall Rules Set | ||
```ruby | ||
describe azure_sql_server(resource_group: 'my-rg', name: 'my-server') do | ||
its('firewall_rules') { should_not be_empty } | ||
end | ||
``` | ||
### Test a SQL Server's Location and Kind | ||
```ruby | ||
describe azure_sql_server(resource_id: '/subscriptions/.../my-server') do | ||
its('kind') { should cmp 'v12.0' } | ||
its('location') { should cmp 'westeurope' } | ||
end | ||
``` | ||
### Test a SQL Server's Auditing Settings | ||
```ruby | ||
describe azure_sql_server(resource_group: 'my-rg', name: 'my-server') do | ||
its('auditing_settings.properties.state') { should cmp 'Disabled' } | ||
its('auditing_settings.properties.retentionDays') { should be 0 } | ||
its('auditing_settings.properties.isStorageSecondaryKeyInUse') { should be false } | ||
its('auditing_settings.properties.isAzureMonitorTargetEnabled') { should be false } | ||
end | ||
``` | ||
## Matchers | ||
|
||
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](/inspec/matchers/). | ||
|
||
### exists | ||
```ruby | ||
# If we expect a resource to always exist | ||
describe azure_sql_server(resource_group: 'my-rg', server_name: 'server-name-1') do | ||
it { should exist } | ||
end | ||
# If we expect a resource to never exist | ||
describe azure_sql_server(resource_group: 'my-rg', server_name: 'server-name-1') do | ||
it { should_not exist } | ||
end | ||
``` | ||
## Azure Permissions | ||
|
||
Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `contributor` role on the subscription you wish to test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
title: About the azure_sql_servers Resource | ||
platform: azure | ||
--- | ||
|
||
# azure_sql_servers | ||
|
||
Use the `azure_sql_servers` InSpec audit resource to test properties and configuration of multiple Azure SQL Servers. | ||
|
||
## Azure REST API version, endpoint and http client parameters | ||
|
||
This resource interacts with api versions supported by the resource provider. | ||
The `api_version` can be defined as a resource parameter. | ||
If not provided, the latest version will be used. | ||
For more information, refer to [`azure_generic_resource`](azure_generic_resource.md). | ||
|
||
Unless defined, `azure_cloud` global endpoint, and default values for the http client will be used . | ||
For more information, refer to the resource pack [README](../../README.md). | ||
|
||
## Availability | ||
|
||
### Installation | ||
|
||
This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure). | ||
For an example `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal). | ||
|
||
## Syntax | ||
|
||
An `azure_sql_servers` resource block returns all Azure SQL Servers, either within a Resource Group (if provided), or within an entire Subscription. | ||
```ruby | ||
describe azure_sql_servers do | ||
it { should exist } | ||
end | ||
``` | ||
or | ||
```ruby | ||
describe azure_sql_servers(resource_group: 'my-rg') do | ||
it { should exist } | ||
end | ||
``` | ||
## Parameters | ||
|
||
- `resource_group` (Optional) | ||
|
||
## Properties | ||
|
||
|Property | Description | Filter Criteria<superscript>*</superscript> | | ||
|---------------|--------------------------------------------------------------------------------------|-----------------| | ||
| ids | A list of the unique resource ids. | `id` | | ||
| locations | A list of locations for all the resources being interrogated. | `location` | | ||
| names | A list of names of all the resources being interrogated. | `name` | | ||
| kinds | A list of kinds of all the resources being interrogated. | `kind` | | ||
| tags | A list of `tag:value` pairs defined on the resources. | `tags` | | ||
| skus | A list of the SKUs (pricing tiers) of the servers. | `sku` | | ||
| types | A list of the types of resources being interrogated. | `type` | | ||
| properties | A list of properties for all the resources being interrogated. | `properties` | | ||
|
||
<superscript>*</superscript> For information on how to use filter criteria on plural resources refer to [FilterTable usage](https://github.com/inspec/inspec/blob/master/docs/dev/filtertable-usage.md#a-where-method-you-can-call-with-hash-params-with-loose-matching). | ||
|
||
## Examples | ||
|
||
### Check a Specific SQL Server is Present | ||
```ruby | ||
describe azure_sql_servers do | ||
its('names') { should include 'my-server-name' } | ||
end | ||
``` | ||
### Filters the Results to Include Only Those Servers which Include the Given Name (Client Side Filtering) | ||
```ruby | ||
describe azure_sql_servers.where{ name.include?('production') } do | ||
it { should exist } | ||
end | ||
``` | ||
## Filters the Results to Include Only Those Servers which Reside in a Given Location (Client Side Filtering) | ||
```ruby | ||
describe azure_sql_servers.where{ location.eql?('westeurope') } do | ||
it { should exist } | ||
end | ||
``` | ||
## Filters the Results to Include Only Those Servers which Reside in a Given Location and Include the Given Name (Server Side Filtering - Recommended) | ||
```ruby | ||
describe azure_generic_resources(resource_provider: 'Microsoft.Sql/servers', substring_of_name: 'production', location: 'westeurope') do | ||
it {should exist} | ||
end | ||
``` | ||
## Matchers | ||
|
||
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/). | ||
|
||
### exists | ||
|
||
The control will pass if the filter returns at least one result. Use `should_not` if you expect zero matches. | ||
```ruby | ||
describe azure_sql_servers do | ||
it { should exist } | ||
end | ||
``` | ||
## Azure Permissions | ||
|
||
Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `contributor` role on the subscription you wish to test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.