Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unauthenticated external elasticsearch no longer forces password… #1990

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions charts/camunda-platform-latest/templates/camunda/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ https://docs.bitnami.com/kubernetes/apps/keycloak/configuration/manage-passwords
{{- end }}
{{- end -}}

{{/*
[elasticsearch] Used as a boolean to determine whether any password is defined.
do not use this for its string value.
*/}}
{{- define "elasticsearch.passwordIsDefined" -}}
{{- (cat .Values.global.elasticsearch.auth.existingSecret .Values.global.elasticsearch.auth.password) -}}
{{- end -}}


{{/*
[opensearch] Get name of elasticsearch auth existing secret. For more details:
https://docs.bitnami.com/kubernetes/apps/keycloak/configuration/manage-passwords/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
securityContext: {{- toYaml .Values.operate.containerSecurityContext | nindent 12 }}
{{- end }}
env:
{{- if .Values.global.elasticsearch.external }}
{{- if and .Values.global.elasticsearch.external (include "elasticsearch.passwordIsDefined" .) }}
- name: CAMUNDA_OPERATE_ELASTICSEARCH_PASSWORD
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
securityContext: {{- toYaml .Values.optimize.containerSecurityContext | nindent 12 }}
{{- end }}
env:
{{- if .Values.global.elasticsearch.external }}
{{- if and .Values.global.elasticsearch.external (include "elasticsearch.passwordIsDefined" .) }}
- name: CAMUNDA_OPTIMIZE_ELASTICSEARCH_SECURITY_PASSWORD
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -117,7 +117,7 @@ spec:
securityContext: {{- toYaml .Values.optimize.containerSecurityContext | nindent 12 }}
{{- end }}
env:
{{- if .Values.global.elasticsearch.external }}
{{- if and .Values.global.elasticsearch.external (include "elasticsearch.passwordIsDefined" .) }}
- name: CAMUNDA_OPTIMIZE_ELASTICSEARCH_SECURITY_PASSWORD
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
- name: SERVER_SERVLET_CONTEXT_PATH
value: {{ .Values.tasklist.contextPath | quote }}
{{- end }}
{{- if .Values.global.elasticsearch.external }}
{{- if and .Values.global.elasticsearch.external (include "elasticsearch.passwordIsDefined" .) }}
- name: CAMUNDA_TASKLIST_ELASTICSEARCH_PASSWORD
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
value: {{ .Values.zeebe.logLevel | quote }}
- name: ZEEBE_BROKER_GATEWAY_ENABLE
value: "false"
{{- if .Values.global.elasticsearch.external }}
{{- if and .Values.global.elasticsearch.external (include "elasticsearch.passwordIsDefined" .) }}
- name: ZEEBE_BROKER_EXPORTERS_ELASTICSEARCH_ARGS_AUTHENTICATION_PASSWORD
valueFrom:
secretKeyRef:
Expand Down
102 changes: 102 additions & 0 deletions charts/camunda-platform-latest/test/unit/operate/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,105 @@ func (s *deploymentTemplateTest) TestOperateWithLog4j2Configuration() {
s.Require().Equal("config", volume.Name)
s.Require().Equal("camunda-platform-test-operate-configuration", volume.ConfigMap.Name)
}

func (s *deploymentTemplateTest) TestOperateDoesNotSetElasticsearchPasswordIfNoneProvidedAndExternal() {
// given
options := &helm.Options{
SetValues: map[string]string{
"global.elasticsearch.external": "true",
"global.elasticsearch.url.protocol": "http",
"global.elasticsearch.url.host": "elasticexternal",
"global.elasticsearch.url.port": "9200",
"elasticsearch.enabled": "false",
},
KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace),
}

// when
output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates)
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(s.T(), output, &deployment)

// then
envVars := deployment.Spec.Template.Spec.Containers[0].Env

for _, envVar := range envVars {
if envVar.Name == "CAMUNDA_OPERATE_ELASTICSEARCH_PASSWORD" || envVar.Name == "CAMUNDA_OPERATE_ZEEBE_ELASTICSEARCH_PASSWORD" {
s.Fail("The elasticsearch password vars should not be set when external elasticsearch is unauthenticated")
}
}
}
func (s *deploymentTemplateTest) TestOperateSetsElasticsearchPasswordIfProvidedByExplicitValueAndExternal() {
// given
options := &helm.Options{
SetValues: map[string]string{
"global.elasticsearch.external": "true",
"global.elasticsearch.url.protocol": "http",
"global.elasticsearch.url.host": "elasticexternal",
"global.elasticsearch.url.port": "9200",
"elasticsearch.enabled": "false",
"global.elasticsearch.auth.password": "supersecret",
},
KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace),
}

// when
output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates)
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(s.T(), output, &deployment)

// then
envVars := deployment.Spec.Template.Spec.Containers[0].Env

var camundaOperateElasticPassword corev1.EnvVar
var camundaOperateZeebeElasticPassword corev1.EnvVar
for _, envVar := range envVars {
if envVar.Name == "CAMUNDA_OPERATE_ELASTICSEARCH_PASSWORD" {
camundaOperateElasticPassword = envVar
continue
}
if envVar.Name == "CAMUNDA_OPERATE_ZEEBE_ELASTICSEARCH_PASSWORD" {
camundaOperateZeebeElasticPassword = envVar
}
}

s.Require().Equal(camundaOperateElasticPassword.ValueFrom.SecretKeyRef.Name, "camunda-platform-test-elasticsearch")
s.Require().Equal(camundaOperateZeebeElasticPassword.ValueFrom.SecretKeyRef.Name, "camunda-platform-test-elasticsearch")
}
func (s *deploymentTemplateTest) TestOperateSetsElasticsearchPasswordIfProvidedBySecretNameAndExternal() {
// given
options := &helm.Options{
SetValues: map[string]string{
"global.elasticsearch.external": "true",
"global.elasticsearch.url.protocol": "http",
"global.elasticsearch.url.host": "elasticexternal",
"global.elasticsearch.url.port": "9200",
"elasticsearch.enabled": "false",
"global.elasticsearch.auth.existingSecret": "supersecret",
},
KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace),
}

// when
output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates)
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(s.T(), output, &deployment)

// then
envVars := deployment.Spec.Template.Spec.Containers[0].Env

var camundaOperateElasticPassword corev1.EnvVar
var camundaOperateZeebeElasticPassword corev1.EnvVar
for _, envVar := range envVars {
if envVar.Name == "CAMUNDA_OPERATE_ELASTICSEARCH_PASSWORD" {
camundaOperateElasticPassword = envVar
continue
}
if envVar.Name == "CAMUNDA_OPERATE_ZEEBE_ELASTICSEARCH_PASSWORD" {
camundaOperateZeebeElasticPassword = envVar
}
}

s.Require().Equal(camundaOperateElasticPassword.ValueFrom.SecretKeyRef.Name, "supersecret")
s.Require().Equal(camundaOperateZeebeElasticPassword.ValueFrom.SecretKeyRef.Name, "supersecret")
}