From 52a209efc50579b18aca987a873295b7ed9fa10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 23 Oct 2024 15:04:17 +0200 Subject: [PATCH] Allow unsetting the host name env --- .changeset/clean-apes-teach.md | 5 ++ charts/openproject/templates/secret_core.yaml | 2 +- charts/openproject/values.yaml | 5 ++ spec/charts/openproject/host_name_spec.rb | 49 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .changeset/clean-apes-teach.md create mode 100644 spec/charts/openproject/host_name_spec.rb diff --git a/.changeset/clean-apes-teach.md b/.changeset/clean-apes-teach.md new file mode 100644 index 0000000..dafc162 --- /dev/null +++ b/.changeset/clean-apes-teach.md @@ -0,0 +1,5 @@ +--- +"@openproject/helm-charts": minor +--- + +Allow unsetting the host name env diff --git a/charts/openproject/templates/secret_core.yaml b/charts/openproject/templates/secret_core.yaml index cf1e6bc..009c8d9 100644 --- a/charts/openproject/templates/secret_core.yaml +++ b/charts/openproject/templates/secret_core.yaml @@ -23,7 +23,7 @@ stringData: OPENPROJECT_SEED_LOCALE: {{ .Values.openproject.seed_locale | quote }} {{- if .Values.ingress.enabled }} OPENPROJECT_HOST__NAME: {{ .Values.openproject.host | default .Values.ingress.host | quote }} - {{- else if .Values.openproject.host }} + {{- else if not .Values.openproject.prevent_host_output -}} OPENPROJECT_HOST__NAME: {{ .Values.openproject.host | quote }} {{- end }} OPENPROJECT_HSTS: {{ .Values.openproject.hsts | quote }} diff --git a/charts/openproject/values.yaml b/charts/openproject/values.yaml index fc3091d..5162e07 100644 --- a/charts/openproject/values.yaml +++ b/charts/openproject/values.yaml @@ -294,6 +294,11 @@ openproject: # host: + ## In most cases, you want to output OPENPROJECT_HOST__NAME + # to get additional host level protections from the application. + # If you need to support multiple hosts or dynamic hosts, enable this + prevent_host_output: false + ## Enable HSTS. # hsts: true diff --git a/spec/charts/openproject/host_name_spec.rb b/spec/charts/openproject/host_name_spec.rb new file mode 100644 index 0000000..c08c892 --- /dev/null +++ b/spec/charts/openproject/host_name_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe 'host name configuration' do + let(:template) { HelmTemplate.new(default_values) } + + subject { template.dig('Secret/optest-openproject-core', 'stringData') } + + context 'when setting host' do + let(:default_values) do + HelmTemplate.with_defaults(<<~YAML + openproject: + host: bla.example.com + YAML + ) + end + + it 'adds a respective ENV', :aggregate_failures do + expect(subject) + .to include("OPENPROJECT_HOST__NAME" => "bla.example.com") + end + end + + context 'when setting no host name' do + let(:default_values) do + HelmTemplate.with_defaults({}) + end + + it 'the host name is the default', :aggregate_failures do + expect(subject) + .to include("OPENPROJECT_HOST__NAME" => "openproject.example.com") + end + end + + context 'when setting no host name and disabling it' do + let(:default_values) do + HelmTemplate.with_defaults(<<~YAML + openproject: + prevent_host_output: true + YAML + ) + end + + it 'the host is not output', :aggregate_failures do + expect(subject.keys) + .not_to include("OPENPROJECT_HOST__NAME") + end + end +end