Skip to content

Commit 68bb57a

Browse files
committed
Support re-using LAPI credentials in Agent and AppSec
1 parent c24668e commit 68bb57a

3 files changed

Lines changed: 90 additions & 3 deletions

File tree

charts/crowdsec/templates/agent-daemonSet.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,36 @@ spec:
5353
- name: wait-for-lapi-and-register
5454
image: "{{ .Values.image.repository | default "crowdsecurity/crowdsec" }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
5555
imagePullPolicy: {{ .Values.image.pullPolicy }}
56-
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']
56+
command:
57+
- sh
58+
- "-c"
59+
- |
60+
until nc "$LAPI_HOST" "$LAPI_PORT" -z; do
61+
echo waiting for lapi to start
62+
sleep 5
63+
done
64+
65+
ln -s /staging/etc/crowdsec /etc/crowdsec
66+
67+
if test -f /tmp_config/local_api_credentials.yaml
68+
then
69+
cp /tmp_config/local_api_credentials.yaml /etc/crowdsec/local_api_credentials.yaml
70+
71+
cscli lapi status &>/dev/null
72+
val=$?
73+
74+
if test $val -eq 0
75+
then
76+
echo "Credentials found and valid"
77+
exit 0
78+
else
79+
echo "Credentials found but not valid, trying re-register"
80+
fi
81+
fi
82+
83+
set -e
84+
cscli lapi register --machine "$USERNAME" -u "$LAPI_URL" --token "$REGISTRATION_TOKEN"
85+
cp /etc/crowdsec/local_api_credentials.yaml /tmp_config/local_api_credentials.yaml
5786
{{- else }}
5887
- name: wait-for-lapi
5988
image: "{{ .Values.agent.wait_for_lapi.image.repository }}:{{ .Values.agent.wait_for_lapi.image.tag }}"

charts/crowdsec/templates/agent-deployment.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,36 @@ spec:
5555
- name: wait-for-lapi-and-register
5656
image: "{{ .Values.image.repository | default "crowdsecurity/crowdsec" }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
5757
imagePullPolicy: {{ .Values.image.pullPolicy }}
58-
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']
58+
command:
59+
- sh
60+
- "-c"
61+
- |
62+
until nc "$LAPI_HOST" "$LAPI_PORT" -z; do
63+
echo waiting for lapi to start
64+
sleep 5
65+
done
66+
67+
ln -s /staging/etc/crowdsec /etc/crowdsec
68+
69+
if test -f /tmp_config/local_api_credentials.yaml
70+
then
71+
cp /tmp_config/local_api_credentials.yaml /etc/crowdsec/local_api_credentials.yaml
72+
73+
cscli lapi status &>/dev/null
74+
val=$?
75+
76+
if test $val -eq 0
77+
then
78+
echo "Credentials found and valid"
79+
exit 0
80+
else
81+
echo "Credentials found but not valid, trying re-register"
82+
fi
83+
fi
84+
85+
set -e
86+
cscli lapi register --machine "$USERNAME" -u "$LAPI_URL" --token "$REGISTRATION_TOKEN"
87+
cp /etc/crowdsec/local_api_credentials.yaml /tmp_config/local_api_credentials.yaml
5988
{{- else }}
6089
- name: wait-for-lapi
6190
image: "{{ .Values.agent.wait_for_lapi.image.repository }}:{{ .Values.agent.wait_for_lapi.image.tag }}"

charts/crowdsec/templates/appsec-deployment.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,36 @@ spec:
5555
- name: wait-for-lapi-and-register
5656
image: "{{ .Values.image.repository | default "crowdsecurity/crowdsec" }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
5757
imagePullPolicy: {{ .Values.image.pullPolicy }}
58-
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']
58+
command:
59+
- sh
60+
- "-c"
61+
- |
62+
until nc "$LAPI_HOST" "$LAPI_PORT" -z; do
63+
echo waiting for lapi to start
64+
sleep 5
65+
done
66+
67+
ln -s /staging/etc/crowdsec /etc/crowdsec
68+
69+
if test -f /tmp_config/local_api_credentials.yaml
70+
then
71+
cp /tmp_config/local_api_credentials.yaml /etc/crowdsec/local_api_credentials.yaml
72+
73+
cscli lapi status &>/dev/null
74+
val=$?
75+
76+
if test $val -eq 0
77+
then
78+
echo "Credentials found and valid"
79+
exit 0
80+
else
81+
echo "Credentials found but not valid, trying re-register"
82+
fi
83+
fi
84+
85+
set -e
86+
cscli lapi register --machine "$USERNAME" -u "$LAPI_URL" --token "$REGISTRATION_TOKEN"
87+
cp /etc/crowdsec/local_api_credentials.yaml /tmp_config/local_api_credentials.yaml
5988
{{- else }}
6089
- name: wait-for-lapi
6190
image: "{{ .Values.appsec.wait_for_lapi.image.repository }}:{{ .Values.appsec.wait_for_lapi.image.tag }}"

0 commit comments

Comments
 (0)