Skip to content

Commit 19b1947

Browse files
committed
allow st2web to use https and auto-generate the ssl cert as needed
1 parent b0c73e7 commit 19b1947

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

templates/deployments.yaml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ spec:
400400
image: '{{ template "imageRepository" . }}/st2web:{{ tpl (.Values.st2web.image.tag | default .Values.image.tag) . }}'
401401
imagePullPolicy: {{ .Values.image.pullPolicy }}
402402
ports:
403-
- containerPort: 80
403+
- containerPort: {{ .Values.st2web.use_https | ternary 443 80 }}
404404
# Probe to check if app is running. Failure will lead to a pod restart.
405405
livenessProbe:
406406
httpGet:
407-
scheme: HTTP
407+
scheme: {{ .Values.st2web.use_https | ternary "HTTPS" "HTTP" }}
408408
path: /
409-
port: 80
409+
port: {{ .Values.st2web.use_https | ternary 443 80 }}
410410
initialDelaySeconds: 1
411411
# Probe to check if app is ready to serve traffic. Failure will lead to temp stop serving traffic.
412412
# TODO: Failing to add readinessProbe, since st2 requires authorization (401) and we don't have `/healthz` endpoints yet (https://github.com/StackStorm/st2/issues/4020)
@@ -419,18 +419,29 @@ spec:
419419
# path: /api/
420420
# port: 443
421421
# initialDelaySeconds: 3
422-
{{- if .Values.st2web.env }}
423-
env: {{- include "stackstorm-ha.customEnv" .Values.st2web | nindent 8 }}
422+
{{- if or .Values.st2web.env .Values.st2web.use_https }}
423+
env:
424+
{{- if .Values.st2web.env }}
425+
{{- include "stackstorm-ha.customEnv" .Values.st2web | nindent 10 }}
426+
{{- end }}
427+
{{- if .Values.st2web.use_https }}
428+
- name: ST2WEB_HTTPS
429+
value: "1"
430+
{{- end }}
424431
{{- end }}
425432
envFrom:
426433
- configMapRef:
427434
name: {{ .Release.Name }}-st2-urls
428435
optional: true
429-
{{- if or .Values.st2web.config .Values.st2web.postStartScript }}
436+
{{- if or .Values.st2web.use_https .Values.st2web.config .Values.st2web.postStartScript }}
430437
volumeMounts:
431438
{{- else }}
432439
volumeMounts: []
433440
{{- end }}
441+
{{- if .Values.st2web.use_https }}
442+
- name: st2web-ssl-certs-vol
443+
mountPath: /etc/ssl/st2
444+
{{- end }}
434445
{{- if .Values.st2web.config }}
435446
- name: st2web-config-vol
436447
mountPath: /opt/stackstorm/static/webui/config.js
@@ -450,11 +461,21 @@ spec:
450461
{{- if .Values.st2web.serviceAccount.attach }}
451462
serviceAccountName: {{ template "stackstorm-ha.serviceAccountName" . }}
452463
{{- end }}
453-
{{- if or .Values.st2web.config .Values.st2web.postStartScript }}
464+
{{- if or .Values.st2web.use_https .Values.st2web.config .Values.st2web.postStartScript }}
454465
volumes:
455466
{{- else }}
456467
volumes: []
457468
{{- end }}
469+
{{- if .Values.st2web.use_https }}
470+
- name: st2web-ssl-certs-vol
471+
secret:
472+
secretName: {{ .Release.Name }}-st2web-ssl-certs
473+
items:
474+
- key: ssl_certificate
475+
path: st2.crt
476+
- key: ssl_certificate_key
477+
path: st2.key
478+
{{- end }}
458479
{{- if .Values.st2web.config }}
459480
- name: st2web-config-vol
460481
configMap:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{- if .Values.st2web.use_https }}
2+
---
3+
apiVersion: v1
4+
kind: Secret
5+
metadata:
6+
{{- $name := print .Release.Name "-st2web-ssl-certs" }}
7+
name: {{ $name }}
8+
annotations:
9+
description: StackStorm st2web SSL Certificates
10+
labels:
11+
app: st2
12+
tier: backend
13+
vendor: stackstorm
14+
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
15+
release: "{{ .Release.Name }}"
16+
heritage: "{{ .Release.Service }}"
17+
type: Opaque
18+
data:
19+
# SSL Cert+Key used to serve HTTPS from st2web (default: auto-generated)
20+
{{- $previous := lookup "v1" "Secret" .Release.Namespace $name }}
21+
{{- if and .Values.st2web.ssl_certifcate .Values.st2web.ssl_certificate_key }}
22+
ssl_certificate: |
23+
{{- .Values.st2web.ssl_certificate | b64enc | nindent 4 }}
24+
ssl_certificate_key: |
25+
{{- .Values.st2web.ssl_certificate_key | b64enc | nindent 4 }}
26+
{{- else if $previous }}
27+
ssl_certificate: |
28+
{{- $previous.data.ssl_certificate | nindent 4 }}
29+
ssl_certificate_key: |
30+
{{- $previous.data.ssl_certificate_key | nindent 4 }}
31+
{{- else }}
32+
{{- $hosts := list .Values.st2web.service.hostname (printf "%s-st2web.%s.svc" .Release.Name .Release.Namespace) | compact }}
33+
{{- $altNamesDict := dict "altNames" (list) }}
34+
{{- range $domain := (append "" (.Values.dnsConfig.searches | default (list)) }}
35+
{{- range $host := $hosts }}
36+
{{- $_ := printf "%s.%s" $host $domain | trimSuffix "." | append $altNamesDict.altNames | set $altNamesDict "altNames" }}
37+
{{- end }}
38+
{{- end }}
39+
{{- $altNames := append (printf "%s-st2web.%s" .Release.Name .Release.Namespace) $altNamesDict.altNames }}
40+
{{- $ca := genCA (print .Release.Name "-st2web-ca") 365 }}
41+
{{- $generated := genSignedCert (print .Release.Name "-st2web") nil $altNames 365 $ca }}
42+
ssl_certificate: |
43+
{{- $generated.Cert | b64enc | nindent 4 }}
44+
ssl_certificate_key: |
45+
{{- $generated.Key | b64enc | nindent 4 }}
46+
{{- end }}
47+
{{- end }}

templates/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ spec:
9999
{{- end }}
100100
ports:
101101
- protocol: TCP
102-
port: 80
102+
port: {{ .Values.st2web.use_https | ternary 443 80 }}
103103

104104
{{ if .Values.st2chatops.enabled -}}
105105
---

values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ st2web:
297297
# HTTP_PROXY: http://proxy:1234
298298
serviceAccount:
299299
attach: false
300+
# Have st2web pod and service use HTTPS on port 443 when true. default: false (use HTTP on port 80)
301+
use_https: false
302+
# User-defined st2web ssl certificate+key (ignored for http; defaults to autogenerated for https)
303+
# ssl_certificate: |
304+
# # x.509 certficate
305+
# ssl_certificate_key: |
306+
# # x.509 private key
300307
# User-defined st2web config with custom settings to replace default config.js
301308
# See https://github.com/StackStorm/st2web#connecting-to-st2-server for more info
302309
# config: |

0 commit comments

Comments
 (0)