Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion avd_docs/google/gke/GCP-0061/Terraform.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Enable master authorized networks
Enable master authorized networks or DNS-based endpoints

```hcl
resource "google_container_cluster" "good_example" {
Expand All @@ -13,6 +13,20 @@ resource "google_container_cluster" "good_example" {
}
}
```
```hcl
resource "google_container_cluster" "good_example" {
name = "my-gke-cluster"
location = "us-central1"
control_plane_endpoints_config {
dns_endpoint_config {
allow_external_traffic = true
}
ip_endpoints_config {
enabled = false
}
}
}
```

#### Remediation Links
- https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#
Expand Down
3 changes: 3 additions & 0 deletions checks/cloud/google/gke/enable_master_networks.rego
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# provider: google
# service: gke
# severity: HIGH
# minimum_trivy_version: 0.77.0
# recommended_action: Enable master authorized networks
# input:
# selector:
Expand All @@ -28,10 +29,12 @@ package builtin.google.gke.google0061
import rego.v1

import data.lib.cloud.metadata
import data.lib.cloud.value

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
value.is_true(cluster.controlplaneendpoints.ipendpoints.enabled)
not cluster.masterauthorizednetworks.enabled.value
res := result.new(
"Cluster does not have master authorized networks enabled.",
Expand Down
23 changes: 23 additions & 0 deletions checks/cloud/google/gke/enable_master_networks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,32 @@ terraform:
}
}
}
- |-
resource "google_container_cluster" "good_example" {
name = "my-gke-cluster"
location = "us-central1"
control_plane_endpoints_config {
dns_endpoint_config {
allow_external_traffic = true
}
ip_endpoints_config {
enabled = false
}
}
}
bad:
- |-
resource "google_container_cluster" "bad_example" {
name = "my-gke-cluster"
location = "us-central1"
}
- |-
resource "google_container_cluster" "bad_example" {
name = "my-gke-cluster"
location = "us-central1"
control_plane_endpoints_config {
ip_endpoints_config {
enabled = true
}
}
}
35 changes: 34 additions & 1 deletion checks/cloud/google/gke/enable_master_networks_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import rego.v1
import data.builtin.google.gke.google0061 as check

test_deny_master_networks_disabled if {
inp := {"google": {"gke": {"clusters": [{"masterauthorizednetworks": {"enabled": {"value": false}}}]}}}
inp := {"google": {"gke": {"clusters": [{
"masterauthorizednetworks": {"enabled": {"value": false}},
"controlplaneendpoints": {"ipendpoints": {"enabled": {"value": true}}},
}]}}}

res := check.deny with input as inp
count(res) == 1
Expand All @@ -17,3 +20,33 @@ test_allow_master_networks_enabled if {
res := check.deny with input as inp
res == set()
}

test_allow_master_networks_enabled_with_ip_endpoints_enabled if {
inp := {"google": {"gke": {"clusters": [{
"masterauthorizednetworks": {"enabled": {"value": true}},
"controlplaneendpoints": {"ipendpoints": {"enabled": {"value": true}}},
}]}}}

res := check.deny with input as inp
res == set()
}

test_allow_ip_endpoints_disabled if {
inp := {"google": {"gke": {"clusters": [{
"masterauthorizednetworks": {"enabled": {"value": false}},
"controlplaneendpoints": {"ipendpoints": {"enabled": {"value": false}}},
}]}}}

res := check.deny with input as inp
res == set()
}

test_allow_ip_endpoints_unresolvable if {
inp := {"google": {"gke": {"clusters": [{
"masterauthorizednetworks": {"enabled": {"value": false}},
"controlplaneendpoints": {"ipendpoints": {"enabled": {"value": false, "unresolvable": true}}},
}]}}}

res := check.deny with input as inp
res == set()
}