inspec / inspec-gcp

InSpec GCP (Google Cloud Platform) Resource Pack
https://www.inspec.io/
Other
147 stars 71 forks source link

Issue with workload_meta_config.mode matcher #410

Open wyardley opened 2 years ago

wyardley commented 2 years ago

Describe the problem

I've got a situation where workloadMetadataConfig.mode is set to GKE_METADATA, and yet the workload_meta_config.mode matcher seesm to be nil. This is using a slightly older version of this that's vendored in with https://github.com/GoogleCloudPlatform/inspec-gcp-helpers, so I can try to doublecheck if this issue affects the latest version as well.

Described in more detail at: https://github.com/GoogleCloudPlatform/inspec-gke-cis-benchmark/issues/30

Possible Solution

wyardley commented 2 years ago

Basic POC that shows this against current trunk as well.

title "GKE Nodepool test"

gcp_project_id = input("gcp_project_id")
gke_cluster = input("gke_cluster")
gke_cluster_location = input("gke_cluster_location")
gke_nodepool_name = input("gke_nodepool_name")

# you add controls here
control "gke-cluster-1.0" do
  impact 1.0
  title "Ensure cluster exists."
  desc "Testing"
  describe google_container_cluster(project: gcp_project_id, name: gke_cluster, location: gke_cluster_location) do
    it { should exist }
  end
  describe google_container_node_pool(project: gcp_project_id, nodepool_name: gke_nodepool_name, cluster_name: gke_cluster, location: gke_cluster_location) do
    it { should exist }
    its('config.workload_meta_config.mode') { should be_in %w[GCE_METADATA GKE_METADATA] }
  end
end
  ×  gke-cluster-1.0: Ensure cluster exists. (1 failed)
     ✔  Cluster xyz is expected to exist
     ✔  NodePool default-node-pool is expected to exist
     ×  NodePool default-node-pool config.workload_meta_config.mode is expected to be in "GCE_METADATA" and "GKE_METADATA"
     expected `` to be in the list: `["GCE_METADATA", "GKE_METADATA"]`

dumping out the config object, it's got:

     +     "workloadMetadataConfig"=>{"mode"=>"GKE_METADATA"},

the GCP CLI also shows

config:
  workloadMetadataConfig:
    mode: GKE_METADATA
sa-progress commented 1 year ago

@wyardley this issue is fixed in this PR.

wyardley commented 1 year ago

Woo! thanks @sa-progress!