Skip to content

Commit

Permalink
fix: not to check unmanaged resources
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Pivkin <[email protected]>
  • Loading branch information
nikpivkin authored and simar7 committed Dec 6, 2024
1 parent f1ca50e commit a6ecb69
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 16 deletions.
9 changes: 9 additions & 0 deletions avd_docs/google/gke/AVD-GCP-0057/Terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
Set node metadata to SECURE or GKE_METADATA_SERVER

```hcl
resource "google_container_cluster" "primary" {
name = "my-gke-cluster"
location = "us-central1"
remove_default_node_pool = true
initial_node_count = 1
}
resource "google_container_node_pool" "good_example" {
cluster = google_container_cluster.primary.id
node_config {
workload_metadata_config {
node_metadata = "SECURE"
Expand Down
1 change: 1 addition & 0 deletions checks/cloud/aws/elb/alb_not_public.rego
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import data.lib.cloud.metadata

deny contains res if {
some lb in input.aws.elb.loadbalancers
isManaged(lb)
not is_gateway(lb)
not lb.internal.value

Expand Down
1 change: 1 addition & 0 deletions checks/cloud/aws/elb/drop_invalid_headers.rego
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import data.lib.cloud.metadata

deny contains res if {
some lb in input.aws.elb.loadbalancers
isManaged(lb)
lb.type.value == "application"
not lb.dropinvalidheaderfields.value
res := result.new(
Expand Down
1 change: 1 addition & 0 deletions checks/cloud/aws/lambda/enable_tracing.rego
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import data.lib.cloud.value

deny contains res if {
some func in input.aws.lambda.functions
isManaged(func)
not is_active_mode(func)
res := result.new(
"Function does not have tracing enabled.",
Expand Down
10 changes: 8 additions & 2 deletions checks/cloud/google/gke/enable_auto_repair.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ package builtin.google.gke.google0063

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
some pool in cluster.nodepools
pool.management.enableautorepair.value == false
res := result.new("Node pool does not have auto-repair enabled.", pool.management.enableautorepair)
not pool.management.enableautorepair.value
res := result.new(
"Node pool does not have auto-repair enabled.",
metadata.obj_by_path(pool, ["management", "enableautorepair"]),
)
}
10 changes: 8 additions & 2 deletions checks/cloud/google/gke/enable_auto_upgrade.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ package builtin.google.gke.google0058

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
some pool in cluster.nodepools
pool.management.enableautoupgrade.value == false
res := result.new("Node pool does not have auto-upgraade enabled.", pool.management.enableautoupgrade)
not pool.management.enableautoupgrade.value
res := result.new(
"Node pool does not have auto-upgraade enabled.",
metadata.obj_by_path(pool, ["management", "enableautoupgrade"]),
)
}
10 changes: 8 additions & 2 deletions checks/cloud/google/gke/enable_ip_aliasing.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ package builtin.google.gke.google0049

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
cluster.ipallocationpolicy.enabled.value == false
res := result.new("Cluster has IP aliasing disabled.", cluster.ipallocationpolicy.enabled)
isManaged(cluster)
not cluster.ipallocationpolicy.enabled.value
res := result.new(
"Cluster has IP aliasing disabled.",
metadata.obj_by_path(cluster, ["ipallocationpolicy", "enabled"]),
)
}
7 changes: 5 additions & 2 deletions checks/cloud/google/gke/enable_master_networks.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ package builtin.google.gke.google0061

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
cluster.masterauthorizednetworks.enabled.value == false
isManaged(cluster)
not cluster.masterauthorizednetworks.enabled.value
res := result.new(
"Cluster does not have master authorized networks enabled.",
cluster.masterauthorizednetworks.enabled,
metadata.obj_by_path(cluster, ["masterauthorizednetworks", "enabled"]),
)
}
7 changes: 5 additions & 2 deletions checks/cloud/google/gke/enable_private_cluster.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ package builtin.google.gke.google0059

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
cluster.privatecluster.enableprivatenodes.value == false
isManaged(cluster)
not cluster.privatecluster.enableprivatenodes.value
res := result.new(
"Cluster does not have private nodes.",
cluster.privatecluster.enableprivatenodes,
metadata.obj_by_path(cluster, ["privatecluster", "enableprivatenodes"]),
)
}
8 changes: 7 additions & 1 deletion checks/cloud/google/gke/enable_stackdriver_logging.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ package builtin.google.gke.google0060

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
cluster.loggingservice.value != "logging.googleapis.com/kubernetes"
res := result.new("Cluster does not use the logging.googleapis.com/kubernetes StackDriver logging service.", cluster.loggingservice)
res := result.new(
"Cluster does not use the logging.googleapis.com/kubernetes StackDriver logging service.",
metadata.obj_by_path(cluster, ["loggingservice"]),
)
}
9 changes: 7 additions & 2 deletions checks/cloud/google/gke/enable_stackdriver_monitoring.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ package builtin.google.gke.google0052

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
cluster.monitoringservice.value != "monitoring.googleapis.com/kubernetes"
isManaged(cluster)
not use_kub_service(cluster)
res := result.new(
"Cluster does not use the monitoring.googleapis.com/kubernetes StackDriver monitoring service.",
cluster.monitoringservice,
metadata.obj_by_path(cluster, ["monitoringservice"]),
)
}

use_kub_service(cluster) if cluster.monitoringservice.value == "monitoring.googleapis.com/kubernetes"
2 changes: 2 additions & 0 deletions checks/cloud/google/gke/metadata_endpoints_disabled.rego
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import rego.v1

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
cluster.removedefaultnodepool.value == true
some pool in cluster.nodepools
pool.nodeconfig.enablelegacyendpoints.value == true
Expand All @@ -49,6 +50,7 @@ deny contains res if {

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
not cluster.removedefaultnodepool.value
cluster.nodeconfig.enablelegacyendpoints.value == true
res := result.new(
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/google/gke/no_legacy_authentication.rego
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import data.lib.cloud.value

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
cluster.masterauth.clientcertificate.issuecertificate.value
res := result.new(
"Cluster allows the use of certificates for master authentication.",
Expand All @@ -45,6 +46,7 @@ deny contains res if {

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
not cluster.masterauth.clientcertificate.issuecertificate.value
value.is_not_empty(cluster.masterauth.username)
res := result.new(
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/google/gke/node_metadata_security.rego
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import rego.v1

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
metadata := cluster.nodeconfig.workloadmetadataconfig.nodemetadata
is_exposes(metadata.value)
res := result.new("Cluster exposes node metadata of pools by default.", metadata)
}

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
some pool in cluster.nodepools
metadata := pool.nodeconfig.workloadmetadataconfig.nodemetadata
is_exposes(metadata.value)
Expand Down
18 changes: 18 additions & 0 deletions checks/cloud/google/gke/node_metadata_security.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
terraform:
good:
- |-
resource "google_container_cluster" "primary" {
name = "my-gke-cluster"
location = "us-central1"
remove_default_node_pool = true
initial_node_count = 1
}
resource "google_container_node_pool" "good_example" {
cluster = google_container_cluster.primary.id
node_config {
workload_metadata_config {
node_metadata = "SECURE"
Expand All @@ -10,7 +19,16 @@ terraform:
}
bad:
- |-
resource "google_container_cluster" "primary" {
name = "my-gke-cluster"
location = "us-central1"
remove_default_node_pool = true
initial_node_count = 1
}
resource "google_container_node_pool" "bad_example" {
cluster = google_container_cluster.primary.id
node_config {
workload_metadata_config {
node_metadata = "EXPOSE"
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/google/gke/node_pool_uses_cos.rego
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import rego.v1

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
image_type := cluster.nodeconfig.imagetype
not lower(image_type.value) in {"cos", "cos_containerd", ""}
res := result.new(
Expand All @@ -40,6 +41,7 @@ deny contains res if {

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
some pool in cluster.nodepools
image_type := pool.nodeconfig.imagetype
not lower(image_type.value) in {"cos", "cos_containerd"}
Expand Down
10 changes: 8 additions & 2 deletions checks/cloud/google/gke/node_shielding_enabled.rego
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ package builtin.google.gke.google0055

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
cluster.enableshieldednodes.value == false
res := result.new("Cluster has shielded nodes disabled.", cluster.enableshieldednodes)
isManaged(cluster)
not cluster.enableshieldednodes.value
res := result.new(
"Cluster has shielded nodes disabled.",
metadata.obj_by_path(cluster, ["enableshieldednodes"]),
)
}
8 changes: 7 additions & 1 deletion checks/cloud/google/gke/use_cluster_labels.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ package builtin.google.gke.google0051

import rego.v1

import data.lib.cloud.metadata

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
count(cluster.resourcelabels.value) == 0
res := result.new("Cluster does not use GCE resource labels.", cluster.resourcelabels)
res := result.new(
"Cluster does not use GCE resource labels.",
metadata.obj_by_path(cluster, ["resourcelabels"]),
)
}
1 change: 1 addition & 0 deletions checks/cloud/google/gke/use_rbac_permissions.rego
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import rego.v1

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
cluster.enablelegacyabac.value == true
res := result.new("Cluster has legacy ABAC enabled.", cluster.enablelegacyabac)
}
2 changes: 2 additions & 0 deletions checks/cloud/google/gke/use_service_account.rego
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import data.lib.cloud.value

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
value.is_false(cluster.removedefaultnodepool)
default_account_is_not_overrided(cluster.nodeconfig)
res := result.new(
Expand All @@ -45,6 +46,7 @@ deny contains res if {

deny contains res if {
some cluster in input.google.gke.clusters
isManaged(cluster)
some pool in cluster.nodepools
default_account_is_not_overrided(pool.nodeconfig)
res := result.new(
Expand Down

0 comments on commit a6ecb69

Please sign in to comment.