This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
forked from inspec/inspec-gcp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added several more resources, details below.
- Added google_storage_buckets plural resource. - Minor updates to README, projects, firewalls and zones documentation. - Added container clusters plural resource. - Added container node pools plural resource. Signed-off-by: Stuart Paterson <spaterson@chef.io>
- Loading branch information
Stuart Paterson
committed
Jun 19, 2018
1 parent
7052acb
commit 4eb5abf
Showing
17 changed files
with
449 additions
and
20 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
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,77 @@ | ||
--- | ||
title: About the google_container_clusters Resource | ||
platform: gcp | ||
--- | ||
|
||
# google\_container\_clusters | ||
|
||
Use the `google_container_clusters` InSpec audit resource to test properties of all, or a filtered group of, GCP container clusters for a project in a particular `google_compute_zone`. | ||
|
||
<br> | ||
|
||
## Syntax | ||
|
||
A `google_container_clusters` resource block collects GCP clusters by project and zone, then tests that group. | ||
|
||
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do | ||
it { should exist } | ||
end | ||
|
||
Use this InSpec resource to enumerate IDs then test in-depth using `google_container_cluster`. | ||
|
||
google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a').cluster_names.each do |cluster_name| | ||
describe google_container_cluster(project: 'chef-inspec-gcp', cluster: cluster_name) do | ||
it { should exist } | ||
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 clusters available for the project in a particular zone | ||
|
||
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do | ||
its('count') { should be <= 5} | ||
end | ||
|
||
### Test that an expected cluster is available for the project | ||
|
||
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do | ||
its('cluster_names') { should include "my-cluster" } | ||
end | ||
|
||
### Test whether any clusters are in status "STOPPED" | ||
|
||
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do | ||
its('cluster_statuses') { should_not include "STOPPED" } | ||
end | ||
|
||
### Test that a subset of all clusters matching "kube*" are "RUNNING" | ||
|
||
describe google_container_clusters(project: gcp_project_id).where(cluster_name: /^kube/).cluster_names.each do |cluster_name| | ||
describe google_container_cluster(project: 'chef-inspec-gcp', zone: 'europe-west2-a', name: cluster_name) do | ||
it { should exist } | ||
its('status') { should eq 'RUNNING' } | ||
end | ||
end | ||
|
||
<br> | ||
|
||
## Filter Criteria | ||
|
||
This resource supports the following filter criteria: `cluster_name` and `cluster_status`. Any of these may be used with `where`, as a block or as a method. | ||
|
||
## Properties | ||
|
||
* `cluster_names` - an array of google_container_cluster name strings | ||
* `cluster_statuses`- an array of google_container_cluster status stringss | ||
|
||
<br> | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Kubernetes Engine API](https://console.cloud.google.com/apis/library/container.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,72 @@ | ||
--- | ||
title: About the google_container_node_pools Resource | ||
platform: gcp | ||
--- | ||
|
||
# google\_container\_node_pools | ||
|
||
Use the `google_container_node_pools` InSpec audit resource to test properties of all, or a filtered group of, GCP container node_pools for a project, cluster and zone. | ||
|
||
<br> | ||
|
||
## Syntax | ||
|
||
A `google_container_node_pools` resource block collects GCP node pools by project, cluster and zone then tests that group. | ||
|
||
describe google_container_node_pools(project: 'chef-inspec-gcp', zone: 'europe-west2-a', cluster_name: 'inspec-gcp-cluster') do | ||
it { should exist } | ||
end | ||
|
||
Use this InSpec resource to enumerate IDs then test in-depth using `google_container_node_pool`. | ||
|
||
google_container_node_pools(project: 'chef-inspec-gcp', zone: 'europe-west2-a', cluster_name: 'inspec-gcp-cluster').node_pool_names.each do |node_pool_name| | ||
describe google_container_node_pool(project: 'chef-inspec-gcp', zone: 'europe-west2-a', cluster_name: 'inspec-gcp-cluster', nodepool_name: node_pool_name) do | ||
it { should exist } | ||
its('status') { should eq 'RUNNING' } | ||
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 node pools available for the project | ||
|
||
describe google_container_node_pools(project: 'chef-inspec-gcp') do | ||
its('count') { should be <= 10} | ||
end | ||
|
||
### Test that an expected node pool is available for the project | ||
|
||
describe google_container_node_pools(project: 'chef-inspec-gcp') do | ||
its('node_pool_names') { should include "us-east1-b" } | ||
end | ||
|
||
### Test that a subset of all node pools matching "mypooll*" are "UP" | ||
|
||
describe google_container_node_pools(project: 'chef-inspec-gcp', zone: 'europe-west2-a', cluster_name: 'inspec-gcp-cluster').where(node_pool_name: /^mypool/).node_pool_names.each do |node_pool_name| | ||
describe google_container_node_pool(project: 'chef-inspec-gcp', zone: 'europe-west2-a', cluster_name: 'inspec-gcp-cluster', nodepool_name: node_pool_name) do | ||
it { should exist } | ||
its('status') { should eq 'RUNNING' } | ||
end | ||
end | ||
|
||
<br> | ||
|
||
## Filter Criteria | ||
|
||
This resource supports the following filter criteria: `node_pool_name` and `node_pool_status`. Any of these may be used with `where`, as a block or as a method. | ||
|
||
## Properties | ||
|
||
* `node_pool_names` - an array of google_container_node_pool name strings | ||
* `node_pool_statuses`- an array of google_container_node_pool status stringss | ||
|
||
<br> | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Kubernetes Engine API](https://console.cloud.google.com/apis/library/container.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,75 @@ | ||
--- | ||
title: About the google_storage_buckets Resource | ||
platform: gcp | ||
--- | ||
|
||
# google\_storage\_bucket | ||
|
||
Use the `google_storage_buckets` InSpec audit resource to test properties of a GCP storage buckets. | ||
|
||
<br> | ||
|
||
## Syntax | ||
|
||
A `google_storage_buckets` resource block collects GCP buckets by project then tests that group. | ||
|
||
describe google_storage_buckets(project: 'chef-inspec-gcp') do | ||
it { should exist } | ||
end | ||
|
||
Use this InSpec resource to enumerate IDs then test in-depth using `google_storage_bucket`. | ||
|
||
google_storage_buckets(project: 'chef-inspec-gcp').bucket_names.each do |bucket_name| | ||
describe google_storage_bucket(name: bucket_name) do | ||
it { should exist } | ||
its('storage_class') { should eq 'STANDARD' } | ||
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 storage buckets for the project | ||
|
||
describe google_storage_buckets(project: 'chef-inspec-gcp') do | ||
its('count') { should be <= 100} | ||
end | ||
|
||
|
||
### Test that an expected named bucket is available | ||
|
||
describe google_storage_buckets do | ||
its('bucket_names'){ should include "my_expected_bucket" } | ||
end | ||
|
||
### Test that all buckets belong to the expected project number | ||
|
||
google_storage_buckets(project: 'chef-inspec-gcp').bucket_names.each do |bucket_name| | ||
describe google_storage_bucket(name: bucket_name) do | ||
it { should exist } | ||
its('project_number'){ should eq 1122334455 } | ||
end | ||
end | ||
|
||
<br> | ||
|
||
## Filter Criteria | ||
|
||
This resource supports the following filter criteria: `bucket_id`; `bucket_name`; `bucket_project_number` and `bucket_location`. Any of these may be used with `where`, as a block or as a method. | ||
|
||
## Properties | ||
|
||
* `bucket_ids` - an array of google_storage_bucket identifier strings | ||
* `bucket_names` - an array of google_storage_bucket name strings | ||
* `bucket_project_numbers`- an array of google_storage_bucket identifier integers | ||
* `bucket_locations`- an array of google_storage_bucket location strings | ||
|
||
<br | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Google Cloud Storage API](https://console.cloud.google.com/apis/api/storage-component.googleapis.com/) is enabled. |
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'gcp_backend' | ||
|
||
module Inspec::Resources | ||
class GoogleContainerClusters < GcpResourceBase | ||
name 'google_container_clusters' | ||
desc 'Verifies settings for GCP container clusters in bulk' | ||
|
||
example " | ||
describe google_container_clusters(project: 'chef-inspec-gcp', zone: 'europe-west2-a') do | ||
it { should exist } | ||
... | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
# Call the parent class constructor | ||
super(opts) | ||
@project = opts[:project] | ||
@zone = opts[:zone] | ||
end | ||
|
||
# FilterTable setup | ||
filter_table_config = FilterTable.create | ||
filter_table_config.add(:cluster_names, field: :cluster_name) | ||
filter_table_config.add(:cluster_statuses, field: :cluster_status) | ||
filter_table_config.connect(self, :fetch_data) | ||
|
||
def fetch_data | ||
cluster_rows = [] | ||
catch_gcp_errors do | ||
# below seemingly doesn't provide pagination | ||
@clusters = @gcp.gcp_client(Google::Apis::ContainerV1::ContainerService).list_zone_clusters(@project, @zone) | ||
end | ||
return [] if !@clusters.clusters | ||
@clusters.clusters.map do |cluster| | ||
cluster_rows+=[{ cluster_name: cluster.name, | ||
cluster_status: cluster.status }] | ||
end | ||
@table = cluster_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
Oops, something went wrong.