2121 annotations :
2222 checksum/agent-configmap : {{ include (print $.Template.BasePath "/agent-configmap.yaml") . | sha256sum }}
2323 checksum/acquis-configmap : {{ include (print $.Template.BasePath "/acquis-configmap.yaml") . | sha256sum }}
24+ {{- if or (not .Values.tls.enabled) (not .Values.tls.appsec.tlsClientAuth) }}
25+ internal/local-api-credentials : " "
26+ {{- end }}
2427 {{- if .Values.podAnnotations }}
2528{{ toYaml .Values.podAnnotations | trim | indent 8 }}
2629 {{- end }}
3740{{ toYaml .Values.agent.podLabels | trim | indent 8 }}
3841 {{- end }}
3942 spec :
43+ {{- if or (not .Values.tls.enabled) (not .Values.tls.appsec.tlsClientAuth) }}
44+ serviceAccountName : {{ .Release.Name }}-config
45+ {{- end }}
4046 {{- with .Values.agent.tolerations }}
4147 tolerations :
4248 {{- toYaml . | nindent 8 }}
@@ -47,10 +53,122 @@ spec:
4753 {{- end }}
4854 initContainers :
4955 {{- if or (not .Values.tls.enabled) (not .Values.tls.agent.tlsClientAuth) }}
56+ {{- if .Values.utils.kubectl.enabled }}
57+ - name : install-kubectl
58+ image : " {{ .Values.utils.kubectl.image.repository }}:{{ .Values.utils.kubectl.image.tag }}"
59+ imagePullPolicy : {{ .Values.utils.kubectl.image.pullPolicy }}
60+ command :
61+ - sh
62+ - " -c"
63+ - |
64+ for f in $FILES_TO_COPY; do
65+ f_name=$(basename "$f")
66+
67+ if test ! -f "$f"; then
68+ echo "File $f not found, ignoring"
69+ continue
70+ fi
71+
72+ rm -rf "/utils/$f_name"
73+ install -v -Dm755 "$f" "/utils/$f_name"
74+ done
75+ env :
76+ - name : FILES_TO_COPY
77+ value : {{ .Values.utils.kubectl.files | default "/usr/bin/kubectl" }}
78+ resources :
79+ limits :
80+ memory : 100Mi
81+ requests :
82+ cpu : 1m
83+ memory : 10Mi
84+ securityContext :
85+ allowPrivilegeEscalation : false
86+ privileged : false
87+ runAsUser : 65534
88+ runAsGroup : 65534
89+ volumeMounts :
90+ - name : crowdsec-utils
91+ mountPath : /utils
92+ {{- end }}
93+ {{- if .Values.utils.openssl.enabled }}
94+ - name : install-openssl
95+ image : " {{ .Values.utils.openssl.image.repository }}:{{ .Values.utils.openssl.image.tag }}"
96+ imagePullPolicy : {{ .Values.utils.openssl.image.pullPolicy }}
97+ command :
98+ - sh
99+ - " -c"
100+ - |
101+ for f in $FILES_TO_COPY; do
102+ f_name=$(basename "$f")
103+
104+ if test ! -f "$f"; then
105+ echo "File $f not found, ignoring"
106+ continue
107+ fi
108+
109+ rm -rf "/utils/$f_name"
110+ install -v -Dm755 "$f" "/utils/$f_name"
111+ done
112+ env :
113+ - name : FILES_TO_COPY
114+ value : {{ .Values.utils.openssl.files | default "/usr/bin/openssl /usr/lib/libcrypto.so.3 /usr/lib/libssl.so.3" }}
115+ resources :
116+ limits :
117+ memory : 100Mi
118+ requests :
119+ cpu : 1m
120+ memory : 10Mi
121+ securityContext :
122+ allowPrivilegeEscalation : false
123+ privileged : false
124+ runAsUser : 65534
125+ runAsGroup : 65534
126+ volumeMounts :
127+ - name : crowdsec-utils
128+ mountPath : /utils
129+ {{- end }}
50130 - name : wait-for-lapi-and-register
51131 image : " {{ .Values.image.repository | default " crowdsecurity/crowdsec" }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
52132 imagePullPolicy : {{ .Values.image.pullPolicy }}
53- command : ['sh', '-c', 'until nc "$LAPI_HOST" "$LAPI_PORT" -z; do echo waiting for lapi to start; sleep 5; done; ln -s /staging/etc/crowdsec /etc/crowdsec && cscli lapi register --machine "$USERNAME" -u "$LAPI_URL" --token "$REGISTRATION_TOKEN" && cp /etc/crowdsec/local_api_credentials.yaml /tmp_config/local_api_credentials.yaml']
133+ command :
134+ - sh
135+ - " -c"
136+ - |
137+ until nc "$LAPI_HOST" "$LAPI_PORT" -z; do
138+ echo waiting for lapi to start
139+ sleep 5
140+ done
141+
142+ ln -s /staging/etc/crowdsec /etc/crowdsec
143+
144+ export PATH=/utils:$PATH
145+
146+ if test -n "$EXISTING_CREDENTIALS"; then
147+ set -e
148+ echo "$EXISTING_CREDENTIALS" | base64 -d > /tmp/local_api_credentials.yaml.enc
149+ openssl aes-256-cbc -d -pbkdf2 -pass env:ENCRYPTION_SECRET -in /tmp/local_api_credentials.yaml.enc -out /tmp/local_api_credentials.yaml
150+ install -Dm644 /tmp/local_api_credentials.yaml /etc/crowdsec/local_api_credentials.yaml
151+ set +e
152+
153+ cscli lapi status &>/dev/null
154+ val=$?
155+
156+ if test $val -eq 0
157+ then
158+ echo "Credentials found and valid"
159+ exit 0
160+ else
161+ echo "Credentials found but not valid, trying re-register"
162+ fi
163+ fi
164+
165+ set -e
166+ cscli lapi register --machine "$USERNAME" -u "$LAPI_URL" --token "$REGISTRATION_TOKEN"
167+ cp /etc/crowdsec/local_api_credentials.yaml /tmp_config/local_api_credentials.yaml
168+
169+ openssl aes-256-cbc -e -pbkdf2 -pass env:ENCRYPTION_SECRET -in /etc/crowdsec/local_api_credentials.yaml -out /tmp/local_api_credentials.yaml.enc
170+ SECRET=$(base64 -w0 /tmp/local_api_credentials.yaml.enc)
171+ kubectl annotate --overwrite pod $POD_NAME internal/local-api-credentials=$SECRET &>/dev/null
54172 {{- else }}
55173 - name : wait-for-lapi
56174 image : " {{ .Values.agent.wait_for_lapi.image.repository }}:{{ .Values.agent.wait_for_lapi.image.tag }}"
68186 privileged : false
69187 {{- if or (not .Values.tls.enabled) (not .Values.tls.agent.tlsClientAuth) }}
70188 volumeMounts :
189+ - name : crowdsec-utils
190+ mountPath : /utils
71191 - name : crowdsec-config
72192 mountPath : /tmp_config
73193 {{- end }}
@@ -84,6 +204,19 @@ spec:
84204 fieldPath : metadata.name
85205 - name : LAPI_URL
86206 value : " {{ .Values.agent.lapiURL | default (printf " http://%s-service.%s:8080" .Release.Name .Release.Namespace) }}"
207+ - name : ENCRYPTION_SECRET
208+ valueFrom :
209+ secretKeyRef :
210+ name : {{ include "config.encryptionSecretName" . }}
211+ key : encryptionSecret
212+ - name : POD_NAME
213+ valueFrom :
214+ fieldRef :
215+ fieldPath : metadata.name
216+ - name : EXISTING_CREDENTIALS
217+ valueFrom :
218+ fieldRef :
219+ fieldPath : metadata.annotations['internal/local-api-credentials']
87220 {{- end }}
88221 - name : LAPI_HOST
89222 value : " {{ .Values.agent.lapiHost | default (printf " %s-service.%s" .Release.Name .Release.Namespace) }}"
@@ -250,6 +383,8 @@ spec:
250383 {{- if or (not .Values.tls.enabled) (not .Values.tls.agent.tlsClientAuth) }}
251384 - name : crowdsec-config
252385 emptyDir : {}
386+ - name : crowdsec-utils
387+ emptyDir : {}
253388 {{- end }}
254389 {{- if .Values.agent.hostVarLog }}
255390 - name : varlog
0 commit comments