Skip to content

Commit 2c0048c

Browse files
feat(helm): add nginx ConfigMap for reana-ui security headers (#945)
1 parent 4f2ba90 commit 2c0048c

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{{- if .Values.components.reana_ui.enabled }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: nginx-config
7+
namespace: {{ .Release.Namespace }}
8+
data:
9+
reana-ui.conf: |
10+
server {
11+
listen 80;
12+
root /usr/share/nginx/html;
13+
server_name localhost;
14+
index index.html index.htm;
15+
{{- with .Values.components.reana_ui.nginx.security_headers.hsts }}
16+
add_header Strict-Transport-Security "{{ . }}" always;
17+
{{- end }}
18+
{{- with .Values.components.reana_ui.nginx.security_headers.x_frame_options }}
19+
add_header X-Frame-Options "{{ . }}" always;
20+
{{- end }}
21+
{{- with .Values.components.reana_ui.nginx.security_headers.x_content_type_options }}
22+
add_header X-Content-Type-Options "{{ . }}" always;
23+
{{- end }}
24+
{{- with .Values.components.reana_ui.nginx.security_headers.cross_origin_opener_policy }}
25+
add_header Cross-Origin-Opener-Policy "{{ . }}" always;
26+
{{- end }}
27+
{{- with .Values.components.reana_ui.nginx.security_headers.cross_origin_resource_policy }}
28+
add_header Cross-Origin-Resource-Policy "{{ . }}" always;
29+
{{- end }}
30+
{{- with .Values.components.reana_ui.nginx.security_headers.referrer_policy }}
31+
add_header Referrer-Policy "{{ . }}" always;
32+
{{- end }}
33+
{{- with .Values.components.reana_ui.nginx.security_headers.permissions_policy }}
34+
add_header Permissions-Policy "{{ . }}" always;
35+
{{- end }}
36+
{{- with .Values.components.reana_ui.nginx.security_headers.csp }}
37+
# NOTE: keep in sync with reana-server config.py content security policy headers
38+
add_header Content-Security-Policy "{{ . }}" always;
39+
{{- end }}
40+
41+
#Enable serving of pre-compressed files
42+
gzip_static on;
43+
44+
location / {
45+
try_files $uri /index.html;
46+
}
47+
location = /index.html {
48+
# If the file for the requested URL does not exist, then `/index.html` is always
49+
# served. This might cause some issues given that `index.html` is cached by
50+
# the browser (e.g. in case of an URL to an interactive session).
51+
# This setting makes sure that `index.html` is revalidated on each request.
52+
expires -1;
53+
}
54+
}
55+
{{- end }}

helm/reana/templates/reana-ui.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,24 @@ spec:
2929
metadata:
3030
labels:
3131
app: {{ include "reana.prefix" . }}-ui
32+
annotations:
33+
checksum/nginx-config: {{ include (print $.Template.BasePath "/nginx-config.yaml") . | sha256sum }}
3234
spec:
3335
containers:
3436
- name: ui
3537
image: {{ .Values.components.reana_ui.image }}
3638
imagePullPolicy: {{ .Values.components.reana_ui.imagePullPolicy }}
3739
ports:
3840
- containerPort: 80
41+
volumeMounts:
42+
- name: nginx-config
43+
mountPath: /etc/nginx/conf.d/default.conf
44+
subPath: reana-ui.conf
45+
volumes:
46+
- name: nginx-config
47+
configMap:
48+
defaultMode: 420
49+
name: nginx-config
3950
{{- if .Values.node_label_infrastructure }}
4051
{{- $full_label := split "=" .Values.node_label_infrastructure }}
4152
nodeSelector:

helm/reana/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ components:
9393
file_preview_size_limit: "5242880" # 5 * 1024**2 = 5 MiB
9494
imagePullPolicy: IfNotPresent
9595
image: docker.io/reanahub/reana-ui:0.95.0-alpha.3
96+
nginx:
97+
security_headers:
98+
hsts: "max-age=31536000; includeSubDomains"
99+
x_frame_options: "DENY"
100+
x_content_type_options: "nosniff"
101+
cross_origin_opener_policy: "same-origin"
102+
cross_origin_resource_policy: "same-origin"
103+
referrer_policy: "strict-origin-when-cross-origin"
104+
permissions_policy:
105+
"accelerometer=(), ambient-light-sensor=(), camera=(),
106+
display-capture=(), geolocation=(), gyroscope=(), magnetometer=(),
107+
microphone=(), payment=(), usb=()"
108+
# NOTE: keep in sync with reana-server config.py content security policy headers
109+
csp:
110+
"default-src 'self'; script-src 'self'; style-src 'self'
111+
'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data:;
112+
font-src 'self' data: https://fonts.gstatic.com; connect-src 'self';
113+
frame-ancestors 'none'; object-src 'none'; base-uri 'self';"
96114
reana_db:
97115
enabled: true
98116
image: docker.io/library/postgres:12.13

0 commit comments

Comments
 (0)