Skip to content

Commit

Permalink
feat(helm-local_settings): Add option to add local_settings.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Nov 20, 2024
1 parent e59c395 commit 1397f77
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/content/en/getting_started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ When you deploy DefectDojo in a **Kubernetes** cluster, you can set environment

An example can be found in [`template_env`](https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/template-env).

### local_settings.py (not with Kubernetes)
### local_settings.py

`local_settings.py` can contain more complex customizations such as adding MIDDLEWARE or INSTALLED_APP entries.
This file is processed *after* settings.dist.py is processed, so you can modify settings delivered by DefectDojo out of the box.
Expand All @@ -34,6 +34,8 @@ An example can be found in [`dojo/settings/template-local_settings`](https://git

In Docker Compose release mode, files in `docker/extra_settings/` (relative to the file `docker-compose.yml`) will be copied into `dojo/settings/` in the docker container on startup.

`local_settings.py` can be used in Kubernetes as well. Variable `localsettingspy` will be stored as ConfigMap and mounted to responsible location of containers.

## Configuration in the UI

Users with the superuser status can configure more options via the UI under `Configuration` / `System Settings`.
11 changes: 11 additions & 0 deletions helm/defectdojo/templates/celery-beat-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ spec:
volumes:
- name: run
emptyDir: {}
{{- if .Values.localsettingspy }}
- name: localsettingspy
configMap:
name: {{ $fullName }}-localsettingspy
{{- end }}
{{- if .Values.django.uwsgi.certificates.enabled }}
- name: cert-mount
configMap:
Expand Down Expand Up @@ -107,6 +112,12 @@ spec:
volumeMounts:
- name: run
mountPath: /run/defectdojo
{{- if .Values.localsettingspy }}
- name: localsettingspy
readOnly: true
mountPath: /app/dojo/settings/local_settings.py
subPath: file
{{- end }}
{{- if .Values.django.uwsgi.certificates.enabled }}
- name: cert-mount
mountPath: {{ .Values.django.uwsgi.certificates.certMountPath }}
Expand Down
11 changes: 11 additions & 0 deletions helm/defectdojo/templates/celery-worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ spec:
- name: {{ .Values.imagePullSecrets }}
{{- end }}
volumes:
{{- if .Values.localsettingspy }}
- name: localsettingspy
configMap:
name: {{ $fullName }}-localsettingspy
{{- end }}
{{- if .Values.django.uwsgi.certificates.enabled }}
- name: cert-mount
configMap:
Expand Down Expand Up @@ -102,6 +107,12 @@ spec:
{{- end }}
command: ['/entrypoint-celery-worker.sh']
volumeMounts:
{{- if .Values.localsettingspy }}
- name: localsettingspy
readOnly: true
mountPath: /app/dojo/settings/local_settings.py
subPath: file
{{- end }}
{{- if .Values.django.uwsgi.certificates.enabled }}
- name: cert-mount
mountPath: {{ .Values.django.uwsgi.certificates.certMountPath }}
Expand Down
15 changes: 15 additions & 0 deletions helm/defectdojo/templates/configmap-local-settings-py.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.localsettingspy }}
{{- $fullName := include "defectdojo.fullname" . -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $fullName }}-localsettingspy
labels:
app.kubernetes.io/name: {{ include "defectdojo.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "defectdojo.chart" . }}
data:
file:
{{ toYaml .Values.localsettingspy | indent 4 }}
{{- end }}
11 changes: 11 additions & 0 deletions helm/defectdojo/templates/django-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ spec:
volumes:
- name: run
emptyDir: {}
{{- if .Values.localsettingspy }}
- name: localsettingspy
configMap:
name: {{ $fullName }}-localsettingspy
{{- end }}
{{- if .Values.django.uwsgi.certificates.enabled }}
- name: cert-mount
configMap:
Expand Down Expand Up @@ -138,6 +143,12 @@ spec:
volumeMounts:
- name: run
mountPath: /run/defectdojo
{{- if .Values.localsettingspy }}
- name: localsettingspy
readOnly: true
mountPath: /app/dojo/settings/local_settings.py
subPath: file
{{- end }}
{{- if .Values.django.uwsgi.certificates.enabled }}
- name: cert-mount
mountPath: {{ .Values.django.uwsgi.certificates.certMountPath }}
Expand Down
11 changes: 11 additions & 0 deletions helm/defectdojo/templates/initializer-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ spec:
- name: {{ .Values.imagePullSecrets }}
{{- end }}
volumes:
{{- if .Values.localsettingspy }}
- name: localsettingspy
configMap:
name: {{ $fullName }}-localsettingspy
{{- end }}
{{- range .Values.initializer.extraVolumes }}
- name: userconfig-{{ .name }}
{{ .type }}:
Expand Down Expand Up @@ -101,6 +106,12 @@ spec:
{{- toYaml .Values.securityContext.djangoSecurityContext | nindent 10 }}
{{- end }}
volumeMounts:
{{- if .Values.localsettingspy }}
- name: localsettingspy
readOnly: true
mountPath: /app/dojo/settings/local_settings.py
subPath: file
{{- end }}
{{- range .Values.initializer.extraVolumes }}
- name: userconfig-{{ .name }}
readOnly: true
Expand Down
12 changes: 12 additions & 0 deletions helm/defectdojo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,15 @@ extraConfigs: {}
# configMapKeyRef:
# name: my-other-postgres-configmap
# key: cluster_endpoint

# To add code snippet which would extend setting functionality, you might add it here
# It will be stored as ConfigMap and mounted `dojo/settings/local_settings.py`.
# For more see: https://documentation.defectdojo.com/getting_started/configuration/
# For example:
# localsettingspy: |
# INSTALLED_APPS += (
# 'debug_toolbar',
# )
# MIDDLEWARE = [
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
# ] + MIDDLEWARE

0 comments on commit 1397f77

Please sign in to comment.