Skip to content

Commit 7963355

Browse files
authored
[DEV-3183]: Orl rule testcase (#23)
* feat(DEV-3183): new test case for avoiding anonymous system bindings in a gcp container cluster * refactor(DEV-3183): move files to abstract and change canBeApplied to false
1 parent cf90d4d commit 7963355

File tree

6 files changed

+200
-0
lines changed

6 files changed

+200
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
resource "google_container_cluster" "non_compliant_cluster" {
2+
name = var.cluster_name
3+
location = var.location
4+
5+
# Enable RBAC
6+
enable_legacy_abac = true
7+
8+
# The non-compliant setting: allow anonymous access by enabling the legacy ABAC
9+
# This allows unauthenticated users (system:anonymous) to have access,
10+
# which violates the CIS recommendation to avoid bindings to system:anonymous.
11+
12+
# Minimal required settings for a valid cluster
13+
initial_node_count = 1
14+
15+
node_config {
16+
machine_type = var.machine_type
17+
}
18+
19+
rbac_binding_config {
20+
enable_insecure_binding_system_unauthenticated = false
21+
}
22+
}
23+
24+
resource "google_container_cluster" "non_compliant_cluster_explicit" {
25+
name = var.cluster_name
26+
location = var.location
27+
28+
# Enable RBAC
29+
enable_legacy_abac = true
30+
31+
# The non-compliant setting: allow anonymous access by enabling the legacy ABAC
32+
# This allows unauthenticated users (system:anonymous) to have access,
33+
# which violates the CIS recommendation to avoid bindings to system:anonymous.
34+
35+
# Minimal required settings for a valid cluster
36+
initial_node_count = 1
37+
38+
node_config {
39+
machine_type = var.machine_type
40+
}
41+
42+
rbac_binding_config {
43+
enable_insecure_binding_system_unauthenticated = false
44+
}
45+
}
46+
47+
resource "google_container_cluster" "compliant_cluster" {
48+
name = var.cluster_name
49+
location = var.location
50+
51+
# Enable RBAC
52+
enable_legacy_abac = true
53+
54+
# Minimal required settings for a valid cluster
55+
initial_node_count = 1
56+
57+
node_config {
58+
machine_type = var.machine_type
59+
}
60+
61+
rbac_binding_config {
62+
enable_insecure_binding_system_unauthenticated = false
63+
}
64+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
variable "gcp_project" {
2+
type = string
3+
description = "The GCP project to create the cluster in"
4+
}
5+
6+
variable "cluster_name" {
7+
type = string
8+
description = "The name of the GKE cluster"
9+
default = "uut-cluster"
10+
}
11+
12+
variable "location" {
13+
type = string
14+
description = "The location/region for the cluster"
15+
default = "us-central1"
16+
}
17+
18+
variable "machine_type" {
19+
type = string
20+
description = "The machine type for the cluster nodes"
21+
default = "e2-medium"
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# yaml-language-server: $schema=../../../../gomboc-schema/test-case.yaml
2+
3+
name: Avoid bindings to system:anonymous
4+
5+
provider: GCP
6+
iac:
7+
language: terraform
8+
version: v1.5.8
9+
10+
canBeApplied: false
11+
12+
benchmarkRecommendations:
13+
- id: "4.1.8"
14+
name: "Avoid bindings to system:anonymous"
15+
benchmark: CIS Google Kubernetes Engine (GKE) Autopilot Benchmark
16+
benchmarkVersion: v1.0.0
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
resource "google_container_cluster" "non_compliant_cluster" {
2+
name = var.cluster_name
3+
location = var.location
4+
5+
# Enable RBAC
6+
enable_legacy_abac = true
7+
8+
# The non-compliant setting: allow anonymous access by enabling the legacy ABAC
9+
# This allows unauthenticated users (system:anonymous) to have access,
10+
# which violates the CIS recommendation to avoid bindings to system:anonymous.
11+
12+
# Minimal required settings for a valid cluster
13+
initial_node_count = 1
14+
15+
node_config {
16+
machine_type = var.machine_type
17+
}
18+
}
19+
20+
resource "google_container_cluster" "non_compliant_cluster_explicit" {
21+
name = var.cluster_name
22+
location = var.location
23+
24+
# Enable RBAC
25+
enable_legacy_abac = true
26+
27+
# The non-compliant setting: allow anonymous access by enabling the legacy ABAC
28+
# This allows unauthenticated users (system:anonymous) to have access,
29+
# which violates the CIS recommendation to avoid bindings to system:anonymous.
30+
31+
# Minimal required settings for a valid cluster
32+
initial_node_count = 1
33+
34+
node_config {
35+
machine_type = var.machine_type
36+
}
37+
38+
}
39+
40+
resource "google_container_cluster" "compliant_cluster" {
41+
name = var.cluster_name
42+
location = var.location
43+
44+
# Enable RBAC
45+
enable_legacy_abac = true
46+
47+
# Minimal required settings for a valid cluster
48+
initial_node_count = 1
49+
50+
node_config {
51+
machine_type = var.machine_type
52+
}
53+
54+
rbac_binding_config {
55+
enable_insecure_binding_system_unauthenticated = false
56+
}
57+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Provider config
2+
terraform {
3+
required_providers {
4+
google = {
5+
source = "hashicorp/google"
6+
version = ">= 6.13.0"
7+
}
8+
}
9+
10+
required_version = ">= 1.1.0"
11+
}
12+
13+
provider "google" {
14+
project = var.gcp_project
15+
default_labels = {
16+
"test-repo" = "rattleback",
17+
"test-path" = "gcp/terraform/container-cluster-avoid-bindings-to-system-anonymous"
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
variable "gcp_project" {
2+
type = string
3+
description = "The GCP project to create the cluster in"
4+
}
5+
6+
variable "cluster_name" {
7+
type = string
8+
description = "The name of the GKE cluster"
9+
default = "uut-cluster"
10+
}
11+
12+
variable "location" {
13+
type = string
14+
description = "The location/region for the cluster"
15+
default = "us-central1"
16+
}
17+
18+
variable "machine_type" {
19+
type = string
20+
description = "The machine type for the cluster nodes"
21+
default = "e2-medium"
22+
}

0 commit comments

Comments
 (0)