Skip to content

Commit 4f38f2f

Browse files
fix: add missing resources, securityContext and env entries (#13210)
* fix: add missing resources, securityContext and env entries * chore: docs and schema * fix: missing securityContext for initializer job * fix: add resources to all cloudsql containers * chore: add missing explicit namespace * chore: refactor, split container and pod security context * chore: docs and schema * fix: lint * chore: sort helper * fix: lint and add changes to release notes * chore: trigger CI * chore: move to 2.52, fix pending issues * chore: docs
1 parent 2da05de commit 4f38f2f

21 files changed

+661
-247
lines changed

docs/content/en/open_source/upgrading/2.52.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22
title: 'Upgrading to DefectDojo Version 2.52.x'
33
toc_hide: true
44
weight: -20251006
5-
description: No special instructions.
5+
description: Helm chart changes.
66
---
7-
There are no special instructions for upgrading to 2.52.x. Check the [Release Notes](https://github.com/DefectDojo/django-DefectDojo/releases/tag/2.52.0) for the contents of the release.
7+
8+
## Helm Chart Changes
9+
10+
This release introduces more important changes to the Helm chart configuration:
11+
12+
### Breaking changes
13+
14+
#### Security context
15+
16+
This Helm chart extends security context capabilities to all deployed pods and containers.
17+
You can define a default pod and container security context globally using `securityContext.podSecurityContext` and `securityContext.containerSecurityContext` keys.
18+
Additionally, each deployment can specify its own pod and container security contexts, which will override or merge with the global ones.
19+
20+
#### Fine-grained resources
21+
22+
Now each container can specify the resource requests and limits.
23+
24+
#### Moved values
25+
26+
The following Helm chart values have been modified in this release:
27+
28+
- `securityContext.djangoSecurityContext` → deprecated in favor of container-specific security contexts (`celery.beat.containerSecurityContext`, `celery.worker.containerSecurityContext`, `django.uwsgi.containerSecurityContext` and `dbMigrationChecker.containerSecurityContext`)
29+
- `securityContext.nginxSecurityContext` → deprecated in favor of container-specific security contexts (`django.nginx.containerSecurityContext`)
30+
31+
### Other changes
32+
33+
- **Extra annotations**: Now we can add common annotations to all resources.
34+
35+
There are other instructions for upgrading to 2.52.x. Check the [Release Notes](https://github.com/DefectDojo/django-DefectDojo/releases/tag/2.52.0) for the contents of the release.

helm/defectdojo/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,19 @@ A Helm chart for Kubernetes to install DefectDojo
524524
| admin.password | string | `""` | |
525525
| admin.secretKey | string | `""` | |
526526
| admin.user | string | `"admin"` | |
527-
| annotations | object | `{}` | |
527+
| alternativeHosts | list | `[]` | |
528528
| celery.annotations | object | `{}` | |
529529
| celery.beat.affinity | object | `{}` | |
530530
| celery.beat.annotations | object | `{}` | |
531+
| celery.beat.containerSecurityContext | object | `{}` | |
531532
| celery.beat.extraEnv | list | `[]` | |
532533
| celery.beat.extraInitContainers | list | `[]` | |
533534
| celery.beat.extraVolumeMounts | list | `[]` | |
534535
| celery.beat.extraVolumes | list | `[]` | |
535536
| celery.beat.livenessProbe | object | `{}` | |
536537
| celery.beat.nodeSelector | object | `{}` | |
537538
| celery.beat.podAnnotations | object | `{}` | |
539+
| celery.beat.podSecurityContext | object | `{}` | |
538540
| celery.beat.readinessProbe | object | `{}` | |
539541
| celery.beat.replicas | int | `1` | |
540542
| celery.beat.resources.limits.cpu | string | `"2000m"` | |
@@ -548,13 +550,15 @@ A Helm chart for Kubernetes to install DefectDojo
548550
| celery.worker.affinity | object | `{}` | |
549551
| celery.worker.annotations | object | `{}` | |
550552
| celery.worker.appSettings.poolType | string | `"solo"` | |
553+
| celery.worker.containerSecurityContext | object | `{}` | |
551554
| celery.worker.extraEnv | list | `[]` | |
552555
| celery.worker.extraInitContainers | list | `[]` | |
553556
| celery.worker.extraVolumeMounts | list | `[]` | |
554557
| celery.worker.extraVolumes | list | `[]` | |
555558
| celery.worker.livenessProbe | object | `{}` | |
556559
| celery.worker.nodeSelector | object | `{}` | |
557560
| celery.worker.podAnnotations | object | `{}` | |
561+
| celery.worker.podSecurityContext | object | `{}` | |
558562
| celery.worker.readinessProbe | object | `{}` | |
559563
| celery.worker.replicas | int | `1` | |
560564
| celery.worker.resources.limits.cpu | string | `"2000m"` | |
@@ -563,26 +567,35 @@ A Helm chart for Kubernetes to install DefectDojo
563567
| celery.worker.resources.requests.memory | string | `"128Mi"` | |
564568
| celery.worker.startupProbe | object | `{}` | |
565569
| celery.worker.tolerations | list | `[]` | |
570+
| cloudsql.containerSecurityContext | object | `{}` | |
566571
| cloudsql.enable_iam_login | bool | `false` | |
567572
| cloudsql.enabled | bool | `false` | |
573+
| cloudsql.extraEnv | list | `[]` | |
574+
| cloudsql.extraVolumeMounts | list | `[]` | |
568575
| cloudsql.image.pullPolicy | string | `"IfNotPresent"` | |
569576
| cloudsql.image.repository | string | `"gcr.io/cloudsql-docker/gce-proxy"` | |
570577
| cloudsql.image.tag | string | `"1.37.9"` | |
571578
| cloudsql.instance | string | `""` | |
579+
| cloudsql.resources | object | `{}` | |
572580
| cloudsql.use_private_ip | bool | `false` | |
573581
| cloudsql.verbose | bool | `true` | |
574582
| createPostgresqlSecret | bool | `false` | |
575583
| createRedisSecret | bool | `false` | |
576584
| createSecret | bool | `false` | |
585+
| dbMigrationChecker.containerSecurityContext | object | `{}` | |
577586
| dbMigrationChecker.enabled | bool | `true` | |
587+
| dbMigrationChecker.extraEnv | list | `[]` | |
588+
| dbMigrationChecker.extraVolumeMounts | list | `[]` | |
578589
| dbMigrationChecker.resources.limits.cpu | string | `"200m"` | |
579590
| dbMigrationChecker.resources.limits.memory | string | `"200Mi"` | |
580591
| dbMigrationChecker.resources.requests.cpu | string | `"100m"` | |
581592
| dbMigrationChecker.resources.requests.memory | string | `"100Mi"` | |
582593
| disableHooks | bool | `false` | |
583594
| django.affinity | object | `{}` | |
584595
| django.annotations | object | `{}` | |
596+
| django.extraEnv | list | `[]` | |
585597
| django.extraInitContainers | list | `[]` | |
598+
| django.extraVolumeMounts | list | `[]` | |
586599
| django.extraVolumes | list | `[]` | |
587600
| django.ingress.activateTLS | bool | `true` | |
588601
| django.ingress.annotations | object | `{}` | |
@@ -598,6 +611,7 @@ A Helm chart for Kubernetes to install DefectDojo
598611
| django.mediaPersistentVolume.persistentVolumeClaim.size | string | `"5Gi"` | |
599612
| django.mediaPersistentVolume.persistentVolumeClaim.storageClassName | string | `""` | |
600613
| django.mediaPersistentVolume.type | string | `"emptyDir"` | |
614+
| django.nginx.containerSecurityContext.runAsUser | int | `1001` | |
601615
| django.nginx.extraEnv | list | `[]` | |
602616
| django.nginx.extraVolumeMounts | list | `[]` | |
603617
| django.nginx.resources.limits.cpu | string | `"2000m"` | |
@@ -607,6 +621,7 @@ A Helm chart for Kubernetes to install DefectDojo
607621
| django.nginx.tls.enabled | bool | `false` | |
608622
| django.nginx.tls.generateCertificate | bool | `false` | |
609623
| django.nodeSelector | object | `{}` | |
624+
| django.podSecurityContext.fsGroup | int | `1001` | |
610625
| django.replicas | int | `1` | |
611626
| django.service.annotations | object | `{}` | |
612627
| django.service.type | string | `""` | |
@@ -619,6 +634,7 @@ A Helm chart for Kubernetes to install DefectDojo
619634
| django.uwsgi.certificates.certMountPath | string | `"/certs/"` | |
620635
| django.uwsgi.certificates.configName | string | `"defectdojo-ca-certs"` | |
621636
| django.uwsgi.certificates.enabled | bool | `false` | |
637+
| django.uwsgi.containerSecurityContext.runAsUser | int | `1001` | |
622638
| django.uwsgi.enableDebug | bool | `false` | |
623639
| django.uwsgi.extraEnv | list | `[]` | |
624640
| django.uwsgi.extraVolumeMounts | list | `[]` | |
@@ -644,6 +660,7 @@ A Helm chart for Kubernetes to install DefectDojo
644660
| django.uwsgi.startupProbe.periodSeconds | int | `5` | |
645661
| django.uwsgi.startupProbe.successThreshold | int | `1` | |
646662
| django.uwsgi.startupProbe.timeoutSeconds | int | `1` | |
663+
| extraAnnotations | object | `{}` | |
647664
| extraConfigs | object | `{}` | |
648665
| extraEnv | list | `[]` | |
649666
| extraLabels | object | `{}` | |
@@ -656,13 +673,15 @@ A Helm chart for Kubernetes to install DefectDojo
656673
| imagePullSecrets | string | `nil` | |
657674
| initializer.affinity | object | `{}` | |
658675
| initializer.annotations | object | `{}` | |
676+
| initializer.containerSecurityContext | object | `{}` | |
659677
| initializer.extraEnv | list | `[]` | |
660678
| initializer.extraVolumeMounts | list | `[]` | |
661679
| initializer.extraVolumes | list | `[]` | |
662680
| initializer.jobAnnotations | object | `{}` | |
663681
| initializer.keepSeconds | int | `60` | |
664682
| initializer.labels | object | `{}` | |
665683
| initializer.nodeSelector | object | `{}` | |
684+
| initializer.podSecurityContext | object | `{}` | |
666685
| initializer.resources.limits.cpu | string | `"2000m"` | |
667686
| initializer.resources.limits.memory | string | `"512Mi"` | |
668687
| initializer.resources.requests.cpu | string | `"100m"` | |
@@ -672,9 +691,13 @@ A Helm chart for Kubernetes to install DefectDojo
672691
| initializer.tolerations | list | `[]` | |
673692
| localsettingspy | string | `""` | |
674693
| monitoring.enabled | bool | `false` | |
694+
| monitoring.prometheus.containerSecurityContext | object | `{}` | |
675695
| monitoring.prometheus.enabled | bool | `false` | |
696+
| monitoring.prometheus.extraEnv | list | `[]` | |
697+
| monitoring.prometheus.extraVolumeMounts | list | `[]` | |
676698
| monitoring.prometheus.image | string | `"nginx/nginx-prometheus-exporter:1.4.2"` | |
677699
| monitoring.prometheus.imagePullPolicy | string | `"IfNotPresent"` | |
700+
| monitoring.prometheus.resources | object | `{}` | |
678701
| networkPolicy.annotations | object | `{}` | |
679702
| networkPolicy.egress | list | `[]` | |
680703
| networkPolicy.enabled | bool | `false` | |
@@ -715,12 +738,14 @@ A Helm chart for Kubernetes to install DefectDojo
715738
| repositoryPrefix | string | `"defectdojo"` | |
716739
| revisionHistoryLimit | int | `10` | |
717740
| secrets.annotations | object | `{}` | |
718-
| securityContext.djangoSecurityContext.runAsUser | int | `1001` | |
741+
| securityContext.containerSecurityContext.runAsNonRoot | bool | `true` | |
719742
| securityContext.enabled | bool | `true` | |
720-
| securityContext.nginxSecurityContext.runAsUser | int | `1001` | |
743+
| securityContext.podSecurityContext.runAsNonRoot | bool | `true` | |
721744
| serviceAccount.annotations | object | `{}` | |
722745
| serviceAccount.create | bool | `true` | |
723746
| serviceAccount.labels | object | `{}` | |
747+
| serviceAccount.name | string | `""` | |
748+
| siteUrl | string | `""` | |
724749
| tag | string | `"latest"` | |
725750
| tests.unitTests.resources.limits.cpu | string | `"500m"` | |
726751
| tests.unitTests.resources.limits.memory | string | `"512Mi"` | |

helm/defectdojo/templates/_helpers.tpl

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
{{/* vim: set filetype=mustache: */}}
2-
{{/*
3-
Expand the name of the chart.
1+
{{- /* vim: set filetype=mustache: */}}
2+
{{- /*
3+
Expand the name of the chart.
44
*/}}
55
{{- define "defectdojo.name" -}}
66
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
77
{{- end -}}
88

9-
{{/*
10-
Create a default fully qualified app name.
11-
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12-
If release name contains chart name it will be used as a full name.
9+
{{- /*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
1313
*/}}
1414
{{- define "defectdojo.fullname" -}}
1515
{{- if .Values.fullnameOverride -}}
@@ -24,15 +24,15 @@ If release name contains chart name it will be used as a full name.
2424
{{- end -}}
2525
{{- end -}}
2626

27-
{{/*
28-
Create chart name and version as used by the chart label.
27+
{{- /*
28+
Create chart name and version as used by the chart label.
2929
*/}}
3030
{{- define "defectdojo.chart" -}}
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
3232
{{- end -}}
3333

34-
{{/*
35-
Create the name of the service account to use
34+
{{- /*
35+
Create the name of the service account to use
3636
*/}}
3737
{{- define "defectdojo.serviceAccountName" -}}
3838
{{- if .Values.serviceAccount.create -}}
@@ -42,7 +42,7 @@ Create the name of the service account to use
4242
{{- end -}}
4343
{{- end -}}
4444

45-
{{/*
45+
{{- /*
4646
Determine the hostname to use for PostgreSQL/Redis.
4747
*/}}
4848
{{- define "postgresql.hostname" -}}
@@ -67,7 +67,7 @@ Create the name of the service account to use
6767
{{- end -}}
6868
{{- end -}}
6969

70-
{{/*
70+
{{- /*
7171
Determine the protocol to use for Redis.
7272
*/}}
7373
{{- define "redis.scheme" -}}
@@ -82,7 +82,7 @@ Create the name of the service account to use
8282
{{- end -}}
8383
{{- end -}}
8484

85-
{{/*
85+
{{- /*
8686
Builds the repository names for use with local or private registries
8787
*/}}
8888
{{- define "celery.repository" -}}
@@ -109,7 +109,7 @@ Create the name of the service account to use
109109
{{- end -}}
110110
{{- end -}}
111111

112-
{{/*
112+
{{- /*
113113
Creates the array for DD_ALLOWED_HOSTS in configmap
114114
*/}}
115115
{{- define "django.allowed_hosts" -}}
@@ -121,7 +121,7 @@ Create the name of the service account to use
121121
{{- end -}}
122122
{{- end -}}
123123

124-
{{/*
124+
{{- /*
125125
Creates the persistentVolumeName
126126
*/}}
127127
{{- define "django.pvc_name" -}}
@@ -132,7 +132,7 @@ Create the name of the service account to use
132132
{{- end -}}
133133
{{- end -}}
134134

135-
{{/*
135+
{{- /*
136136
Define db-migration-checker
137137
*/}}
138138
{{- define "dbMigrationChecker" -}}
@@ -145,7 +145,11 @@ Create the name of the service account to use
145145
imagePullPolicy: {{ .Values.imagePullPolicy }}
146146
{{- if .Values.securityContext.enabled }}
147147
securityContext:
148-
{{- toYaml .Values.securityContext.djangoSecurityContext | nindent 4 }}
148+
{{- include "helpers.securityContext" (list
149+
.Values
150+
"securityContext.containerSecurityContext"
151+
"dbMigrationChecker.containerSecurityContext"
152+
) | nindent 4 }}
149153
{{- end }}
150154
envFrom:
151155
- configMapRef:
@@ -163,9 +167,64 @@ Create the name of the service account to use
163167
secretKeyRef:
164168
name: {{ .Values.postgresql.auth.existingSecret | default "defectdojo-postgresql-specific" }}
165169
key: {{ .Values.postgresql.auth.secretKeys.userPasswordKey | default "postgresql-password" }}
166-
{{- if .Values.extraEnv }}
167-
{{- toYaml .Values.extraEnv | nindent 2 }}
170+
{{- with .Values.extraEnv }}
171+
{{- toYaml . | nindent 2 }}
172+
{{- end }}
173+
{{- with.Values.dbMigrationChecker.extraEnv }}
174+
{{- toYaml . | nindent 2 }}
168175
{{- end }}
169176
resources:
170177
{{- toYaml .Values.dbMigrationChecker.resources | nindent 4 }}
178+
{{- with .Values.dbMigrationChecker.extraVolumeMounts }}
179+
volumeMounts:
180+
{{- . | toYaml | nindent 4 }}
181+
{{- end }}
182+
{{- end -}}
183+
184+
{{- /*
185+
Returns the JSON representation of the value for a dot-notation path
186+
from a given context.
187+
Args:
188+
0: context (e.g., .Values)
189+
1: path (e.g., "foo.bar")
190+
*/}}
191+
{{- define "helpers.getValue" -}}
192+
{{- $ctx := merge dict (index . 0) -}}
193+
{{- $path := index . 1 -}}
194+
{{- $parts := splitList "." $path -}}
195+
{{- $value := $ctx -}}
196+
{{- range $idx, $part := $parts -}}
197+
{{- if kindIs "map" $value -}}
198+
{{- $value = index $value $part -}}
199+
{{- else -}}
200+
{{- $value = "" -}}
201+
{{- /* Exit early by setting to last iteration */}}
202+
{{- $idx = sub (len $parts) 1 -}}
203+
{{- end -}}
204+
{{- end -}}
205+
{{- toJson $value -}}
206+
{{- end -}}
207+
208+
{{- /*
209+
Build the security context.
210+
Args:
211+
0: values context (.Values)
212+
1: the default security context key (e.g. "securityContext.containerSecurityContext")
213+
2: the key under the context with security context (e.g., "foo.bar")
214+
*/}}
215+
{{- define "helpers.securityContext" -}}
216+
{{- $values := merge dict (index . 0) -}}
217+
{{- $defaultSecurityContextKey := index . 1 -}}
218+
{{- $securityContextKey := index . 2 -}}
219+
{{- $securityContext := dict -}}
220+
{{- with $values }}
221+
{{- $securityContext = (merge
222+
$securityContext
223+
(include "helpers.getValue" (list $values $defaultSecurityContextKey) | fromJson)
224+
(include "helpers.getValue" (list $values $securityContextKey) | fromJson)
225+
) -}}
226+
{{- end -}}
227+
{{- with $securityContext -}}
228+
{{- . | toYaml | nindent 2 -}}
229+
{{- end -}}
171230
{{- end -}}

0 commit comments

Comments
 (0)