瀏覽代碼

NAS-123843 / 24.04 / nextcloud: safely access nginxConfig (#1498)

Stavros Kois 1 年之前
父節點
當前提交
fa0eb1f2ef

+ 1 - 1
library/ix-dev/charts/nextcloud/Chart.yaml

@@ -4,7 +4,7 @@ description: A file sharing server that puts the control and security of your ow
 annotations:
   title: Nextcloud
 type: application
-version: 1.6.43
+version: 1.6.44
 apiVersion: v2
 appVersion: 27.0.2
 kubeVersion: '>=1.16.0-0'

+ 15 - 9
library/ix-dev/charts/nextcloud/templates/nginx-configmap.yaml

@@ -6,15 +6,21 @@ data:
   protocol: {{ include "nginx.scheme" . }}
   {{ $timeout := 60 }}
   {{ $size := .Values.nextcloud.max_upload_size | default 3 }}
-  {{ $externalAccessPort := printf ":%v" .Values.nginxConfig.externalAccessPort }}
-  {{/* If its 443, do not append it on the rewrite at all */}}
-  {{ if eq $externalAccessPort ":443" }}
-    {{ $externalAccessPort = "" }}
-  {{ end }}
+
+  {{ $useDiffAccessPort := false }}
+  {{ $externalAccessPort := "" }}
+
   {{/* Safely access key as it is conditionaly shown */}}
   {{ if hasKey .Values "nginxConfig" }}
+    {{ $useDiffAccessPort = .Values.useDifferentAccessPort }}
+    {{ $externalAccessPort = printf ":%v" .Values.nginxConfig.externalAccessPort }}
     {{ $timeout = .Values.nginxConfig.proxy_timeouts | default 60 }}
   {{ end }}
+
+  {{/* If its 443, do not append it on the rewrite at all */}}
+  {{ if eq $externalAccessPort ":443" }}
+    {{ $externalAccessPort = "" }}
+  {{ end }}
   nginx.conf: |-
     events {}
     http {
@@ -46,7 +52,7 @@ data:
         }
 
         location = /.well-known/carddav {
-          {{ if .Values.nginxConfig.useDifferentAccessPort }}
+          {{ if $useDiffAccessPort }}
           return 301 $scheme://$host{{ $externalAccessPort }}/remote.php/dav;
           {{ else }}
           return 301 $scheme://$host:$server_port/remote.php/dav;
@@ -54,7 +60,7 @@ data:
         }
 
         location = /.well-known/caldav {
-          {{ if .Values.nginxConfig.useDifferentAccessPort }}
+          {{ if $useDiffAccessPort }}
           return 301 $scheme://$host{{ $externalAccessPort }}/remote.php/dav;
           {{ else }}
           return 301 $scheme://$host:$server_port/remote.php/dav;
@@ -75,8 +81,8 @@ data:
           proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto https;
           proxy_set_header X-Forwarded-Host  $host;
-          {{ if .Values.nginxConfig.useDifferentAccessPort }}
-          proxy_set_header X-Forwarded-Port  {{ .Values.nginxConfig.externalAccessPort }};
+          {{ if $useDiffAccessPort }}
+          proxy_set_header X-Forwarded-Port  {{ $externalAccessPort | default "443" | trimPrefix ":" }};
           {{ else }}
           proxy_set_header X-Forwarded-Port  $server_port;
           {{ end }}