Skip to content

Commit acfa06c

Browse files
committed
Hardening nginx: use non-root port; do not mount favicon here as that creates directory creation permission issues and is already copied anyway in another process.
1 parent d748f88 commit acfa06c

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

charts/geonode/templates/nginx/nginx-conf.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ metadata:
66
data:
77
geonode.conf: |
88
server {
9-
listen 80 default_server;
10-
listen [::]:80 default_server;
9+
listen 8080 default_server;
10+
listen [::]:8080 default_server;
1111
1212
# resolver is required because we use variables as upstream
1313
# resolver kube-dns.kube-system.svc 8.8.8.8 8.8.4.4 valid=300s;
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
apiVersion: apps/v1
32
kind: Deployment
43
metadata:
@@ -17,44 +16,58 @@ spec:
1716
checksum/config: {{ include (print $.Template.BasePath "/nginx/nginx-conf.yaml") . | sha256sum }}
1817
spec:
1918
terminationGracePeriodSeconds: 3
20-
2119
{{- if not (empty .Values.nginx.imagePullSecret) }}
2220
imagePullSecrets:
2321
- name: {{ .Values.nginx.imagePullSecret }}
2422
{{ end }}
25-
23+
securityContext:
24+
runAsNonRoot: true
25+
runAsUser: {{ .Values.nginx.securityContext.runAsUser }}
26+
fsGroup: {{ .Values.nginx.securityContext.runAsUser }}
2627
containers:
2728
- name: {{ .Values.nginx.container_name }}
2829
image: "{{ .Values.nginx.image.name }}:{{ .Values.nginx.image.tag }}"
2930
imagePullPolicy: {{ .Values.nginx.imagePullPolicy }}
3031
ports:
3132
- name: http
32-
containerPort: 80
33-
33+
containerPort: 8080
34+
securityContext:
35+
runAsUser: {{ .Values.nginx.securityContext.runAsUser }}
36+
runAsNonRoot: {{ .Values.nginx.securityContext.runAsNonRoot }}
37+
allowPrivilegeEscalation: {{ .Values.nginx.securityContext.allowPrivilegeEscalation }}
38+
readOnlyRootFilesystem: true
39+
capabilities:
40+
drop:
41+
- ALL
42+
seccompProfile:
43+
type: RuntimeDefault
3444
volumeMounts:
35-
- name: "{{ include "persistant_volume_name" . }}"
45+
- name: pvc-statics
3646
mountPath: /mnt/volumes/statics
37-
subPath: statics
38-
- name: geonode-favicon
39-
mountPath: /mnt/volumes/statics/static/geonode/img/favicon.ico
40-
subPath: favicon.ico
4147
- name: nginx-confd
4248
mountPath: /etc/nginx/conf.d
43-
44-
# this will fail as long as statics are not build by the geonode sts
49+
# Writable scratch directories for nginx
50+
- name: nginx-cache
51+
mountPath: /var/cache/nginx
52+
- name: nginx-run
53+
mountPath: /var/run
54+
- name: nginx-tmp
55+
mountPath: /tmp
4556
livenessProbe:
4657
{{- toYaml $.Values.nginx.livenessProbe | nindent 10 }}
47-
4858
resources:
4959
{{- toYaml $.Values.nginx.resources | nindent 10 }}
50-
5160
volumes:
5261
- name: nginx-confd
5362
configMap:
5463
name: {{ .Release.Name }}-nginx-confd
55-
- name: geonode-favicon
56-
configMap:
57-
name: {{ .Release.Name }}-geonode-favicon
58-
- name: "{{ include "persistant_volume_name" . }}"
64+
- name: pvc-statics
5965
persistentVolumeClaim:
60-
claimName: pvc-{{ .Release.Name }}-geonode
66+
claimName: {{ include "pvc_statics_name" . }}
67+
# emptyDir for all nginx scratch directories
68+
- name: nginx-cache
69+
emptyDir: {}
70+
- name: nginx-run
71+
emptyDir: {}
72+
- name: nginx-tmp
73+
emptyDir: {}

charts/geonode/templates/nginx/nginx-svc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ spec:
88
selector:
99
org.geonode.instance: "{{ include "nginx_pod_name" . }}"
1010
ports:
11-
- targetPort: 80
11+
- targetPort: 8080
1212
port: 80
1313
type: ClusterIP

0 commit comments

Comments
 (0)