title | platform |
---|---|
About the google_compute_firewall Resource |
gcp |
Use the google_compute_firewall
InSpec audit resource to test properties of a single GCP compute compute firewall.
A google_compute_firewall
resource block declares the tests for a single GCP compute firewall by project and name.
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
it { should exist }
its('name') { should eq 'firewall-rule' }
end
The following examples show how to use this InSpec audit resource.
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
its('allowed_ssh?') { should be true }
end
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
its('allowed_http?') { should be false }
end
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
its('allowed_https?') { should be true }
end
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
its('direction') { should eq "INGRESS" }
end
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
its('source_ranges') { should_not eq ["0.0.0.0/0"] }
# or using helpers
its('direction') { should eq "INGRESS" }
it { should_not allow_ip_ranges ["0.0.0.0/0"] }
end
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
# similar to the http / ssh helpers above
it { should_not allow_port_protocol("22", "tcp") }
it { should allow_port_protocol("80", "tcp") }
end
describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
its('direction') { should eq "INGRESS" }
it { should allow_source_tags ["allow-gcp-tag"] }
it { should allow_target_tags ["allow-gcp-other-tag"] }
# stricter
it { should allow_source_tags_only ["allow-gcp-tag"] }
it { should allow_target_tags_only ["allow-gcp-other-tag"] }
end
allowed
,creation_timestamp
,description
,direction
,id
,kind
,name
,network
,priority
,source_ranges
,target_tags
In addition, the following helpers are available:
allowed_http?
,allowed_ssh?
,allow_port_protocol
,allow_source_tags
,allow_source_tags_only
,allow_target_tags
,allow_target_tags_only
,allow_ip_ranges
,allow_ip_ranges_only
Ensure the Compute Engine API is enabled for the project where the resource is located.