mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
Docker: don't re-register local agent if not needed (#2141)
This commit is contained in:
parent
d769fff1e8
commit
f39fbf07fa
5 changed files with 108 additions and 30 deletions
|
@ -185,13 +185,22 @@ elif [ -n "$USE_WAL" ] && isfalse "$USE_WAL"; then
|
|||
conf_set '.db_config.use_wal = false'
|
||||
fi
|
||||
|
||||
# regenerate local agent credentials (even if agent is disabled, cscli needs a
|
||||
# connection to the API)
|
||||
cscli machines delete "$CUSTOM_HOSTNAME" 2>/dev/null || true
|
||||
lapi_credentials_path=$(conf_get '.api.client.credentials_path')
|
||||
|
||||
|
||||
if isfalse "$DISABLE_LOCAL_API"; then
|
||||
if isfalse "$USE_TLS" || [ "$CLIENT_CERT_FILE" = "" ]; then
|
||||
echo "Regenerate local agent credentials"
|
||||
cscli machines add "$CUSTOM_HOSTNAME" --auto
|
||||
# generate local agent credentials (even if agent is disabled, cscli needs a
|
||||
# connection to the API)
|
||||
if ( isfalse "$USE_TLS" || [ "$CLIENT_CERT_FILE" = "" ] ); then
|
||||
if yq -e '.login==strenv(CUSTOM_HOSTNAME)' "$lapi_credentials_path" && ( cscli machines list -o json | yq -e 'any_c(.machineId==strenv(CUSTOM_HOSTNAME))' >/dev/null ); then
|
||||
echo "Local agent already registered"
|
||||
else
|
||||
echo "Generate local agent credentials"
|
||||
# if the db is persistent but the credentials are not, we need to
|
||||
# delete the old machine to generate new credentials
|
||||
cscli machines delete "$CUSTOM_HOSTNAME" >/dev/null 2>&1 || true
|
||||
cscli machines add "$CUSTOM_HOSTNAME" --auto
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Check if lapi needs to register an additional agent"
|
||||
|
@ -205,8 +214,6 @@ fi
|
|||
|
||||
# ----------------
|
||||
|
||||
lapi_credentials_path=$(conf_get '.api.client.credentials_path')
|
||||
|
||||
conf_set_if "$LOCAL_API_URL" '.url = strenv(LOCAL_API_URL)' "$lapi_credentials_path"
|
||||
|
||||
if istrue "$DISABLE_LOCAL_API"; then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue