Skip to content

Commit

Permalink
Merge pull request #123 from snyk/fix/mount-ca-as-secret
Browse files Browse the repository at this point in the history
fix: move ca to secret, tests
  • Loading branch information
soniqua authored Jul 26, 2024
2 parents 99aa6f9 + aec8103 commit d56ea94
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 800 deletions.
2 changes: 1 addition & 1 deletion charts/snyk-broker/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: snyk-broker
version: 2.7.0
version: 2.7.1
description: A Helm chart for Kubernetes
type: application
20 changes: 15 additions & 5 deletions charts/snyk-broker/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,22 @@ Create the name of the broker service to use
{{- end -}}

{{/*
Create TLS secret name
Create a secret name.
Pass a dict of Context ($) and secretName:
include "snyk-broker.genericSecretName" (dict "Context" $ "secretName" "secret-name")
*/}}
{{- define "tls-secret-name" -}}
{{- if not .Values.disableSuffixes -}}
{{ include "snyk-broker.fullname" .}}-tls-secret
{{- define "snyk-broker.genericSecretName" -}}
{{- if not .Context.Values.disableSuffixes -}}
{{ printf "%s-%s" ( include "snyk-broker.fullname" .Context ) .secretName }}
{{- else -}}
tls-secret
{{- printf "snyk-broker-%s" .secretName }}
{{- end -}}
{{- end -}}

{{- define "snyk-broker.tlsSecretName" -}}
{{- include "snyk-broker.genericSecretName" (dict "Context" . "secretName" "tls-secret" ) -}}
{{- end }}

{{- define "snyk-broker.caCertSecretName" -}}
{{- include "snyk-broker.genericSecretName" (dict "Context" . "secretName" "cacert-secret" ) -}}
{{- end }}
9 changes: 4 additions & 5 deletions charts/snyk-broker/templates/broker_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ spec:
- name: HTTPS_KEY
value: /home/node/tls-cert/tls.key
{{- end }}

{{- if .Values.tlsRejectUnauthorized }}
{{- if or ( and .Values.tlsRejectUnauthorized (not .Values.caCert ) (not .Values.caCertFile) ) ( and (or .Values.caCert .Values.caCertFile ) .Values.disableCaCertTrust ) }}
# Troubleshooting - Set to 0 for SSL inspection testing
- name: NODE_TLS_REJECT_UNAUTHORIZED
value: "0"
Expand Down Expand Up @@ -497,13 +496,13 @@ spec:
{{- end }}
{{- if or (.Values.caCert) (.Values.caCertFile) }}
- name: {{ include "snyk-broker.fullname" . }}-cacert-volume
configMap:
name: {{ include "snyk-broker.fullname" . }}-cacert-configmap{{if not .Values.disableSuffixes }}-{{ .Release.Name }}{{ end }}
secret:
secretName: {{ include "snyk-broker.caCertSecretName" . }}
{{- end }}
{{- if and (.Values.httpsCert) (.Values.httpsKey) }}
- name: {{ include "snyk-broker.fullname" . }}-tls-secret-volume
secret:
secretName: {{ include "tls-secret-name" . }}
secretName: {{ include "snyk-broker.tlsSecretName" . }}
{{- end }}
{{- if .Values.extraVolumes }}
{{ tpl (toYaml .Values.extraVolumes | indent 6) . }}
Expand Down
23 changes: 0 additions & 23 deletions charts/snyk-broker/templates/cacert_configmap.yaml

This file was deleted.

18 changes: 17 additions & 1 deletion charts/snyk-broker/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,26 @@ stringData:
apiVersion: v1
kind: Secret
metadata:
name: {{ include "tls-secret-name" . }}
name: {{ include "snyk-broker.tlsSecretName" . }}
type: kubernetes.io/tls
data:
tls.crt: {{ (.Files.Get .Values.httpsCert) | b64enc | quote }}
tls.key: {{ (.Files.Get .Values.httpsKey) | b64enc | quote }}
---
{{- end }}
{{- if or .Values.caCert .Values.caCertFile }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "snyk-broker.caCertSecretName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "snyk-broker.labels" . | nindent 4 }}
data:
{{- if and .Values.caCert (not .Values.caCertFile) }}
{{ (.Files.Glob .Values.caCert).AsSecrets | nindent 2 }}
{{- else if and .Values.caCertFile (not .Values.caCert) }}
cacert: {{ .Values.caCertFile | trim | b64enc | nindent 4}}
{{- end }}
---
{{- end }}
Loading

0 comments on commit d56ea94

Please sign in to comment.