-
Notifications
You must be signed in to change notification settings - Fork 71
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 #18 from inspec/add-plural-resources
Add plural resources
- Loading branch information
Showing
22 changed files
with
502 additions
and
22 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,76 @@ | ||
--- | ||
title: About the google_compute_firewalls Resource | ||
platform: gcp | ||
--- | ||
|
||
# google\_compute\_firewalls | ||
|
||
Use the `google_compute_firewalls` InSpec audit resource to test properties of all, or a filtered group of, GCP compute firewalls for a project. | ||
|
||
<br> | ||
|
||
## Syntax | ||
|
||
A `google_compute_firewalls` resource block collects GCP firewalls by project then tests that group. | ||
|
||
describe google_compute_firewalls(project: 'chef-inspec-gcp') do | ||
it { should exist } | ||
end | ||
|
||
Use this InSpec resource to enumerate IDs then test in-depth using `google_compute_firewall`. | ||
|
||
google_compute_firewalls(project: 'chef-inspec-gcp').firewall_names.each do |firewall_name| | ||
describe google_compute_firewall(project: 'chef-inspec-gcp', name: firewall_name) do | ||
it { should exist } | ||
its('kind') { should eq "compute#firewall" } | ||
end | ||
end | ||
|
||
<br> | ||
|
||
## Examples | ||
|
||
The following examples show how to use this InSpec audit resource. | ||
|
||
### Test that there are no more than a specified number of firewalls available for the project | ||
|
||
describe google_compute_firewalls(project: 'chef-inspec-gcp') do | ||
its('count') { should be <= 100} | ||
end | ||
|
||
### Test that an expected firewall is available for the project | ||
|
||
describe google_compute_firewalls(project: 'chef-inspec-gcp') do | ||
its('firewall_names') { should include "my-app-firewall-rule" } | ||
end | ||
|
||
### Test that a particular named rule does not exist | ||
|
||
describe google_compute_firewalls(project: 'chef-inspec-gcp') do | ||
its('firewall_names') { should_not include "default-allow-ssh" } | ||
end | ||
|
||
### Test there are no firewalls for the "INGRESS" direction | ||
|
||
describe google_compute_firewalls(project: 'chef-inspec-gcp').where(firewall_direction: 'INGRESS') do | ||
it { should_not exist } | ||
end | ||
|
||
<br> | ||
|
||
## Filter Criteria | ||
|
||
This resource supports the following filter criteria: `firewall_id`; `firewall_name`; and `firewall_direction`. Any of these may be used with `where`, as a block or as a method. | ||
|
||
## Properties | ||
|
||
* `firewall_ids` - an array of google_compute_firewall identifier integers | ||
* `firewall_names` - an array of google_compute_firewall name strings | ||
* `firewall_directions`- an array of google_compute_firewall directions containing strings e.g. "INGRESS" or "EGRESS" | ||
|
||
<br> | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the project where the resource is located. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
title: About the google_compute_zone Resource | ||
platform: gcp | ||
--- | ||
|
||
# google\_compute\_zone | ||
|
||
Use the `google_compute_zone` InSpec audit resource to test properties of a single GCP compute zone. | ||
|
||
<br> | ||
|
||
## Syntax | ||
|
||
A `google_compute_zone` resource block declares the tests for a single GCP zone by project and name. | ||
|
||
describe google_compute_zone(project: 'chef-inspec-gcp', zone: 'us-east1-b') do | ||
its('name') { should match 'us-east1-b' } | ||
end | ||
|
||
<br> | ||
|
||
## Examples | ||
|
||
The following examples show how to use this InSpec audit resource. | ||
|
||
### Test that a GCP compute zone exists | ||
|
||
describe google_compute_zone(project: 'chef-inspec-gcp', zone: 'us-east1-b') do | ||
it { should exist } | ||
end | ||
|
||
### Test that a GCP compute zone is in the expected state | ||
|
||
describe google_compute_zone(project: 'chef-inspec-gcp', zone: 'us-east1-b') do | ||
its('status') { should eq 'UP' } | ||
# or equivalently | ||
it { should be_up } | ||
end | ||
|
||
### Test that a GCP compute zone has an expected CPU platform | ||
|
||
describe google_compute_zone(project: 'chef-inspec-gcp', zone: 'us-east1-b') do | ||
its('available_cpu_platforms') { should include "Intel Skylake" } | ||
end | ||
|
||
<br> | ||
|
||
## Properties | ||
|
||
* `available_cpu_platforms`, `creation_timestamp`, `description`, `id`, `kind`, `name`, `region`, `status`, `region_name` | ||
|
||
<br> | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the project where the resource is located. |
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,77 @@ | ||
--- | ||
title: About the google_compute_zones Resource | ||
platform: gcp | ||
--- | ||
|
||
# google\_compute\_zones | ||
|
||
Use the `google_compute_zones` InSpec audit resource to test properties of all, or a filtered group of, GCP compute zones for a project in a particular zone. | ||
|
||
<br> | ||
|
||
## Syntax | ||
|
||
A `google_compute_zones` resource block collects GCP zones by project then tests that group. | ||
|
||
describe google_compute_zones(project: 'chef-inspec-gcp') do | ||
it { should exist } | ||
end | ||
|
||
Use this InSpec resource to enumerate IDs then test in-depth using `google_compute_zone`. | ||
|
||
google_compute_zones(project: 'chef-inspec-gcp').zone_names.each do |zone_name| | ||
describe google_compute_zone(project: 'chef-inspec-gcp', zone: zone_name) do | ||
it { should exist } | ||
its('kind') { should eq "compute#zone" } | ||
its('status') { should eq 'UP' } | ||
end | ||
end | ||
|
||
<br> | ||
|
||
## Examples | ||
|
||
The following examples show how to use this InSpec audit resource. | ||
|
||
### Test that there are no more than a specified number of zones available for the project | ||
|
||
describe google_compute_zones(project: 'chef-inspec-gcp') do | ||
its('count') { should be <= 100} | ||
end | ||
|
||
### Test the exact number of zones in the project | ||
|
||
describe google_compute_zones(project: 'chef-inspec-gcp') do | ||
its('zone_ids.count') { should cmp 9 } | ||
end | ||
|
||
### Test that an expected zone is available for the project | ||
|
||
describe google_compute_zones(project: 'chef-inspec-gcp') do | ||
its('zone_names') { should include "us-east1-b" } | ||
end | ||
|
||
### Test whether any zones are in status "DOWN" | ||
|
||
describe google_compute_zones(project: 'chef-inspec-gcp') do | ||
its('zone_statuses') { should_not include "DOWN" } | ||
end | ||
|
||
<br> | ||
|
||
## Filter Criteria | ||
|
||
This resource supports the following filter criteria: `zone_id`; `zone_name` and `zone_status`. Anyy of these may be used with `where`, as a block or as a method. | ||
|
||
## Properties | ||
|
||
* `zone_ids` - an array of google_compute_zone identifier integers | ||
* `zone_names` - an array of google_compute_zone name strings | ||
* `zone_statuses`- an array of google_compute_zone statuses | ||
|
||
<br> | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the project where the resource is located. |
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'gcp_backend' | ||
|
||
module Inspec::Resources | ||
class GoogleComputeFirewalls < GcpResourceBase | ||
name 'google_compute_firewalls' | ||
desc 'Verifies settings for GCP compute firewalls in bulk' | ||
|
||
example " | ||
describe google_compute_firewalls(project: 'chef-inspec-gcp') do | ||
it { should exist } | ||
... | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
# Call the parent class constructor | ||
super(opts) | ||
@display_name = opts[:name] | ||
@project = opts[:project] | ||
end | ||
|
||
# FilterTable setup | ||
filter_table_config = FilterTable.create | ||
filter_table_config.add(:firewall_ids, field: :firewall_id) | ||
filter_table_config.add(:firewall_names, field: :firewall_name) | ||
filter_table_config.add(:firewall_directions, field: :firewall_direction) | ||
filter_table_config.connect(self, :fetch_data) | ||
|
||
def fetch_data | ||
firewall_rows = [] | ||
next_page = nil | ||
loop do | ||
catch_gcp_errors do | ||
@firewalls = @gcp.gcp_compute_client.list_firewalls(@project, page_token: next_page) | ||
end | ||
return [] if !@firewalls.items | ||
@firewalls.items.map do |firewall| | ||
firewall_rows+=[{ firewall_id: firewall.id, | ||
firewall_name: firewall.name, | ||
firewall_direction: firewall.direction }] | ||
end | ||
next_page = @firewalls.next_page_token | ||
break unless next_page | ||
end | ||
@table = firewall_rows | ||
end | ||
end | ||
end |
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.