From fa0d3f179db41cc9c539e486342c72270b681391 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sun, 1 May 2022 19:43:55 +0300 Subject: [PATCH] fix(meshcentral): fix config file generation (#2591) * fix(meshcentral): fix config file generation * updates * some fixes * some more fixes * fixes * whoops * fixes * see output * comma * cleanup --- charts/incubator/meshcentral/Chart.yaml | 2 +- charts/incubator/meshcentral/questions.yaml | 20 ++++++ charts/incubator/meshcentral/values.yaml | 68 +++++++++++++++++++-- 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/charts/incubator/meshcentral/Chart.yaml b/charts/incubator/meshcentral/Chart.yaml index e8ef87b5e07..c78498f6028 100644 --- a/charts/incubator/meshcentral/Chart.yaml +++ b/charts/incubator/meshcentral/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 kubeVersion: ">=1.16.0-0" name: meshcentral -version: 1.1.6 +version: 1.1.7 appVersion: "1.0.1" description: MeshCentral is a full computer management web site type: application diff --git a/charts/incubator/meshcentral/questions.yaml b/charts/incubator/meshcentral/questions.yaml index d463a43b11b..b91534535a1 100644 --- a/charts/incubator/meshcentral/questions.yaml +++ b/charts/incubator/meshcentral/questions.yaml @@ -74,6 +74,26 @@ questions: - value: "OnDelete" description: "(Legacy) OnDelete: ignore .spec.template changes" # Include{controllerExpert} + - variable: env + group: "Container Configuration" + label: "Image Environment" + schema: + additional_attrs: true + type: dict + attrs: + - variable: hostname + label: "hostname" + description: "Hostname of your meshcentral instance, used to generate self singed certs, eg. mesh.example.com or 192.168.1.100." + schema: + type: string + required: true + default: "" + - variable: reverseProxyUrl + label: "reverseProxyUrl" + description: "HTTPS URL on which you will reach this instance, can't be IP. eg. https://mesh.example.com/" + schema: + type: string + default: "" # Include{containerConfig} diff --git a/charts/incubator/meshcentral/values.yaml b/charts/incubator/meshcentral/values.yaml index 4f24a2ee746..8d9dd693f7d 100644 --- a/charts/incubator/meshcentral/values.yaml +++ b/charts/incubator/meshcentral/values.yaml @@ -3,6 +3,8 @@ image: pullPolicy: IfNotPresent tag: v1.0.1@sha256:d8642b3909fcd1dad6b920629dac8e6e3a609230f38c9d62ca01ca67c26a4730 +extraArgs: ["--cert", "$hostname"] + securityContext: readOnlyRootFilesystem: false runAsNonRoot: false @@ -11,6 +13,10 @@ podSecurityContext: runAsUser: 0 runAsGroup: 0 +env: + hostname: "test.example.com" + reverseProxyUrl: "https://test.example.com" + service: main: ports: @@ -25,6 +31,10 @@ initContainers: - name: data mountPath: "/home/node/meshcentral/meshcentral-data" env: + - name: hostname + value: "{{ .Values.env.hostname }}" + - name: reverseProxyUrl + value: "{{ .Values.env.reverseProxyUrl }}" - name: svcPort value: "{{ .Values.service.main.ports.main.port }}" - name: "mongodbURL" @@ -32,19 +42,69 @@ initContainers: secretKeyRef: name: mongodbcreds key: url - command: ["/bin/sh", "-c"] + command: ["/bin/bash", "-c"] args: - > export configfile='/home/node/meshcentral/meshcentral-data/config.json'; + export basePath='/home/node/meshcentral/meshcentral-data/truecharts'; + mkdir -p $basePath; if [ -f $configfile ]; then - echo 'Config File exists, skipping...'; + echo 'Config File exists, updating values...'; + + # Update hostname + sed -i 's/^ "cert":.*,$/ "cert": "'$hostname'",/1' $configfile; + + export lastreverse=$(cat $basePath/.lastreverse); + if [ ! -z $reverseProxyUrl ]; then + if [[ $lastreverse == "NOT_PROVIDED" ]]; then + # Update reverseProxyUrl + echo "Adding $reverseProxyUrl..."; + sed -i 's/^ "_certUrl": "'$lastreverse'",'$/ "certUrl": "'$reverseProxyUrl'",'/1' $configfile; + echo $reverseProxyUrl > $basePath/.lastreverse; + else + echo "Updating $lastreverse to $reverseProxyUrl..."; + sed -i 's/^ "certUrl": "'$lastreverse'",'$/ "certUrl": "'$reverseProxyUrl'",'/1' $configfile; + echo $reverseProxyUrl > $basePath/.lastreverse; + fi; + else + echo "Removing reverse proxy url..." + sed -i 's/^ "_?certUrl":.*,$/ "_certUrl": "NOT_PROVIDED",/1' $configfile; + echo "NOT_PROVIDED" > $basePath/.lastreverse; + fi; + + export lastport=$(cat $basePath/.lastport); + if [ ! -z $lastport ]; then + # Update port + echo "Updating $lastport to $svcPort..."; + sed -i 's/^ "port": '$lastport',$/ "port": '$svcPort',/1' $configfile; + # Save new port. + echo "$svcPort" > $basePath/.lastport; + fi; else + echo "DO NOT DELETE DOT FILES IN THIS DIR" > $basePath/DO_NOT_DELETE_DOT_FILES_IN_THIS_DIR; echo 'Creating basic config to $configfile...'; echo '{' >> $configfile; - echo ' "$schema": "http://info.meshcentral.com/downloads/meshcentral-config-schema.json",' >> $configfile + echo ' "$schema": "http://info.meshcentral.com/downloads/meshcentral-config-schema.json",' >> $configfile; echo ' "settings": {' >> $configfile; + # Save last port used + echo "$svcPort" > $basePath/.lastport; echo ' "port": '$svcPort',' >> $configfile; - echo ' "mongoDb": "'$mongodbURL'"' >> $configfile; + echo ' "mongoDb": "'$mongodbURL'",' >> $configfile; + echo ' "cert": "'$hostname'"' >> $configfile; + echo ' },' >> $configfile; + echo ' "domains": {' >> $configfile; + echo ' "": {' >> $configfile; + if [ ! -z $reverseProxyUrl ]; then + echo ' "certUrl": "'$reverseProxyUrl'"' >> $configfile; + # Save last reverse url used + echo $reverseProxyUrl > $basePath/.lastreverse; + else + # Underscore in front the the key is making it invisible to meshcentral + echo ' "_certUrl": "NOT_PROVIDED"' >> $configfile; + # Save last reverse url used + echo "NOT_PROVIDED" > $basePath/.lastreverse; + fi; + echo ' }' >> $configfile; echo ' }' >> $configfile; echo '}' >> $configfile; fi;