Skip to content

Commit 07d3274

Browse files
authored
Merge pull request #129 from rosmo/security-2
Update security settings for Kubernetes and Helm chart, update tests and README.
2 parents e5942be + a257945 commit 07d3274

5 files changed

Lines changed: 125 additions & 53 deletions

File tree

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ This will create all the Kubernetes resources required to support `autoneg` and
129129
### Installation via Terraform
130130

131131
You can use the Terraform module in `terraform/autoneg` to deploy Autoneg in a GKE cluster of your choice.
132+
An end-to-end example is provided in the [`terraform/test`](terraform/test) directory as well (simply set your `project_id`).
132133

133134
Example:
134135

@@ -153,6 +154,51 @@ module "autoneg" {
153154
}
154155
```
155156

157+
### Installation via Helm charts
158+
159+
A Helm chart is also provided in [`deploy/chart`](deploy/chart) and via
160+
`https://googlecloudplatform.github.io/gke-autoneg-controller/` repository.
161+
162+
You can also use it with Terraform like this:
163+
164+
```tf
165+
module "autoneg" {
166+
source = "github.com/GoogleCloudPlatform/gke-autoneg-controller//terraform/gcp?ref=master"
167+
168+
project_id = module.project.project_id
169+
service_account_id = "autoneg"
170+
workload_identity = {
171+
namespace = "autoneg-system"
172+
service_account = "autoneg-controller-manager"
173+
}
174+
# To add shared VPC configuration, also set shared_vpc variable
175+
}
176+
177+
resource "helm_release" "autoneg" {
178+
name = "autoneg"
179+
chart = "autoneg-controller-manager"
180+
repository = "https://googlecloudplatform.github.io/gke-autoneg-controller/"
181+
namespace = "autoneg-system"
182+
183+
create_namespace = true
184+
185+
set {
186+
name = "createNamespace"
187+
value = false
188+
}
189+
190+
set {
191+
name = "serviceAccount.annotations.iam\\.gke\\.io/gcp-service-account"
192+
value = module.autoneg.service_account_email
193+
}
194+
195+
set {
196+
name = "serviceAccount.automountServiceAccountToken"
197+
value = true
198+
}
199+
}
200+
```
201+
156202
### Customizing your installation
157203

158204
`autoneg` is based on [Kubebuilder](https://kubebuilder.io), and as such, you can customize and

deploy/chart/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ kube_rbac_proxy:
4747
securityContext:
4848
allowPrivilegeEscalation: false
4949
privileged: false
50+
capabilities:
51+
drop:
52+
- ALL
53+
readOnlyRootFilesystem: true
54+
runAsUser: 65532
55+
runAsGroup: 65532
56+
runAsNonRoot: true
57+
seccompProfile:
58+
type: RuntimeDefault
5059
args:
5160
- --secure-listen-address=0.0.0.0:8443
5261
- --upstream=http://127.0.0.1:8080/
@@ -67,6 +76,15 @@ gke_autoneg_controller:
6776
securityContext:
6877
allowPrivilegeEscalation: false
6978
privileged: false
79+
capabilities:
80+
drop:
81+
- ALL
82+
readOnlyRootFilesystem: true
83+
runAsUser: 65532
84+
runAsGroup: 65532
85+
runAsNonRoot: true
86+
seccompProfile:
87+
type: RuntimeDefault
7088
livenessProbe:
7189
httpGet:
7290
path: /healthz

terraform/kubernetes/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ resource "kubernetes_deployment" "deployment_autoneg_controller_manager" {
302302
security_context {
303303
allow_privilege_escalation = false
304304
privileged = false
305+
capabilities {
306+
drop = ["ALL"]
307+
}
308+
read_only_root_filesystem = true
309+
run_as_non_root = true
310+
run_as_user = 65532
311+
run_as_group = 65532
312+
seccomp_profile {
313+
type = "RuntimeDefault"
314+
}
305315
}
306316

307317
liveness_probe {
@@ -345,6 +355,16 @@ resource "kubernetes_deployment" "deployment_autoneg_controller_manager" {
345355
security_context {
346356
allow_privilege_escalation = false
347357
privileged = false
358+
capabilities {
359+
drop = ["ALL"]
360+
}
361+
read_only_root_filesystem = true
362+
run_as_non_root = true
363+
run_as_user = 65532
364+
run_as_group = 65532
365+
seccomp_profile {
366+
type = "RuntimeDefault"
367+
}
348368
}
349369

350370
port {

terraform/test/main.tf

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Google LLC
2+
* Copyright 2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@
1616

1717
locals {
1818
project_id = var.project_create ? module.project.project_id : var.project_id
19-
ilb_name = "autoneg-test-ilb"
20-
backend_service = "autoneg-test-be"
19+
suffix = var.add_suffix
20+
ilb_name = format("autoneg-test-ilb%s", local.suffix)
21+
backend_service = format("autoneg-test-be%s", local.suffix)
2122
}
2223

2324
module "project" {
24-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=daily-2023.03.14"
25+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=daily-2024.04.19"
2526
name = var.project_id
2627
project_create = var.project_create
2728
services = [
@@ -37,12 +38,12 @@ module "project" {
3738
}
3839

3940
module "vpc" {
40-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=daily-2023.03.14"
41+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=daily-2024.04.19"
4142
project_id = var.vpc_config.network_project != null ? var.vpc_config.network_project : local.project_id
42-
name = var.vpc_config.network
43+
name = format("%s%s", var.vpc_config.network, local.suffix)
4344
subnets = var.vpc_config.create ? [{
4445
ip_cidr_range = var.vpc_subnets.main_cidr_range
45-
name = var.vpc_config.subnetwork
46+
name = format("%s%s", var.vpc_config.subnetwork, local.suffix)
4647
region = var.region
4748
secondary_ip_ranges = {
4849
(var.vpc_subnets.pods_name) = var.vpc_subnets.pods_ip_cidr_range
@@ -53,7 +54,7 @@ module "vpc" {
5354
subnets_proxy_only = [
5455
{
5556
ip_cidr_range = var.vpc_subnets.proxy_only_cidr_range
56-
name = format("%s-proxy", var.vpc_config.network)
57+
name = format("%s-proxy%s", var.vpc_config.network, local.suffix)
5758
region = var.region
5859
active = true
5960
}
@@ -62,26 +63,26 @@ module "vpc" {
6263
}
6364

6465
module "nat" {
65-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-cloudnat?ref=daily-2023.03.14"
66+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-cloudnat?ref=daily-2024.04.19"
6667
project_id = local.project_id
6768
region = var.region
68-
name = format("%s-nat", module.vpc.name)
69+
name = format("%s-nat%s", module.vpc.name, local.suffix)
6970
router_network = module.vpc.name
7071
}
7172

7273
module "firewall" {
73-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc-firewall?ref=daily-2023.03.14"
74+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc-firewall?ref=daily-2024.04.19"
7475
project_id = local.project_id
7576
network = module.vpc.name
7677
default_rules_config = {}
7778
ingress_rules = {
78-
allow-ingress-from-ilb = {
79+
(format("allow-ingress-from-ilb%s", local.suffix)) = {
7980
description = "Allow ingress from ILB"
8081
source_ranges = [var.vpc_subnets.proxy_only_cidr_range]
8182
targets = ["autoneg-test"]
8283
rules = [{ protocol = "tcp", port = 80 }]
8384
}
84-
allow-ingress-healthchecks = {
85+
(format("allow-ingress-healthchecks%s", local.suffix)) = {
8586
description = "Allow healthcheck ranges."
8687
source_ranges = ["35.191.0.0/16", "130.211.0.0/22"]
8788
targets = ["autoneg-test"]
@@ -91,9 +92,9 @@ module "firewall" {
9192
}
9293

9394
module "cluster-service-account" {
94-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/iam-service-account?ref=daily-2023.03.14"
95+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/iam-service-account?ref=daily-2024.04.19"
9596
project_id = local.project_id
96-
name = format("autoneg-test-sa")
97+
name = format("autoneg-test-sa%s", local.suffix)
9798
generate_key = false
9899
iam = {}
99100
iam_project_roles = {
@@ -105,17 +106,17 @@ module "cluster-service-account" {
105106
}
106107

107108
module "cluster" {
108-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/gke-cluster?ref=daily-2023.03.14"
109+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/gke-cluster-autopilot?ref=daily-2024.04.19"
109110

110111
project_id = local.project_id
111-
name = "autoneg-test"
112+
name = format("autoneg-test%s", local.suffix)
112113
location = var.region
113114

114115
release_channel = "REGULAR"
115116

116117
vpc_config = {
117118
network = module.vpc.self_link
118-
subnetwork = module.vpc.subnet_self_links[format("%s/%s", var.region, var.vpc_config.subnetwork)]
119+
subnetwork = module.vpc.subnet_self_links[format("%s/%s%s", var.region, var.vpc_config.subnetwork, local.suffix)]
119120
secondary_range_names = {
120121
pods = var.vpc_subnets.pods_name
121122
services = var.vpc_subnets.services_name
@@ -125,13 +126,16 @@ module "cluster" {
125126
internal-vms = "0.0.0.0/0"
126127
}
127128
}
128-
max_pods_per_node = 32
129129

130130
private_cluster_config = {
131131
enable_private_endpoint = false
132132
master_global_access = false
133133
}
134134

135+
node_config = {
136+
tags = ["autoneg-test"]
137+
}
138+
135139
enable_features = {
136140
dataplane_v2 = true
137141
workload_identity = true
@@ -142,30 +146,6 @@ module "cluster" {
142146
}
143147
}
144148

145-
module "cluster-nodepool" {
146-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/gke-nodepool?ref=daily-2023.03.14"
147-
project_id = local.project_id
148-
149-
cluster_name = module.cluster.name
150-
location = module.cluster.location
151-
name = "autoneg-test-nodepool-1"
152-
153-
service_account = {
154-
email = module.cluster-service-account.email
155-
oauth_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
156-
}
157-
158-
node_config = {
159-
machine_type = "e2-standard-4"
160-
gvnic = true
161-
}
162-
node_count = {
163-
initial = 1
164-
}
165-
166-
tags = ["autoneg-test"]
167-
}
168-
169149
data "google_client_config" "provider" {}
170150

171151
provider "kubernetes" {
@@ -177,19 +157,20 @@ provider "kubernetes" {
177157
}
178158

179159
module "autoneg" {
180-
source = "github.com/GoogleCloudPlatform/gke-autoneg-controller//terraform/autoneg?ref=kubebuilder3"
181-
182-
project_id = local.project_id
160+
source = "../autoneg"
183161

184-
controller_image = var.autoneg_image
162+
project_id = local.project_id
163+
service_account_id = format("autoneg%s", local.suffix)
164+
controller_image = var.autoneg_image
165+
custom_role_add_random_suffix = local.suffix != "" ? true : false
185166

186167
depends_on = [
187-
module.cluster-nodepool.name
168+
module.cluster
188169
]
189170
}
190171

191172
module "ilb" {
192-
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-ilb-l7?ref=daily-2023.03.14"
173+
source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-lb-app-int?ref=daily-2024.04.19"
193174
name = local.ilb_name
194175
project_id = local.project_id
195176
region = var.region
@@ -214,7 +195,7 @@ module "ilb" {
214195

215196
vpc_config = {
216197
network = module.vpc.self_link
217-
subnetwork = module.vpc.subnet_self_links[format("%s/%s", var.region, var.vpc_config.subnetwork)]
198+
subnetwork = module.vpc.subnet_self_links[format("%s/%s%s", var.region, var.vpc_config.subnetwork, local.suffix)]
218199
}
219200
}
220201

@@ -296,4 +277,4 @@ resource "kubernetes_service" "hello-workload" {
296277
}
297278
type = "ClusterIP"
298279
}
299-
}
280+
}

terraform/test/variables.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Google LLC
2+
* Copyright 2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
variable "add_suffix" {
18+
description = "Add suffix to resources"
19+
type = string
20+
default = ""
21+
}
22+
1723
variable "project_create" {
1824
description = "Create project instead of using an existing one."
1925
type = bool
@@ -72,4 +78,5 @@ variable "vpc_subnets" {
7278
variable "autoneg_image" {
7379
type = string
7480
description = "Autoneg image to use"
75-
}
81+
default = "ghcr.io/googlecloudplatform/gke-autoneg-controller/gke-autoneg-controller:latest"
82+
}

0 commit comments

Comments
 (0)