2022-02-15 16:10:15 +00:00
|
|
|
#!/bin/bash
|
2020-11-30 09:37:17 +00:00
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2292 # allow [ test ] syntax
|
|
|
|
# shellcheck disable=SC2310 # allow "if function..." syntax with -e
|
|
|
|
|
|
|
|
set -e
|
|
|
|
shopt -s inherit_errexit
|
|
|
|
|
2022-12-10 21:09:25 +00:00
|
|
|
# match true, TRUE, True, tRuE, etc.
|
2022-11-28 09:35:12 +00:00
|
|
|
istrue() {
|
|
|
|
case "$(echo "$1" | tr '[:upper:]' '[:lower:]')" in
|
|
|
|
true) return 0 ;;
|
|
|
|
*) return 1 ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
isfalse() {
|
|
|
|
if istrue "$1"; then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
if istrue "$DEBUG"; then
|
|
|
|
set -x
|
|
|
|
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if istrue "$CI_TESTING"; then
|
|
|
|
echo "githubciXXXXXXXXXXXXXXXXXXXXXXXX" >/etc/machine-id
|
|
|
|
fi
|
|
|
|
|
|
|
|
#- DEFAULTS -----------------------#
|
|
|
|
|
|
|
|
export CONFIG_FILE="${CONFIG_FILE:=/etc/crowdsec/config.yaml}"
|
|
|
|
export CUSTOM_HOSTNAME="${CUSTOM_HOSTNAME:=localhost}"
|
|
|
|
|
|
|
|
#- HELPER FUNCTIONS ----------------#
|
|
|
|
|
2022-12-10 21:09:25 +00:00
|
|
|
# csv2yaml <string>
|
2022-11-28 09:35:12 +00:00
|
|
|
# generate a yaml list from a comma-separated string of values
|
|
|
|
csv2yaml() {
|
|
|
|
[ -z "$1" ] && return
|
|
|
|
echo "$1" | sed 's/,/\n- /g;s/^/- /g'
|
|
|
|
}
|
2021-10-14 15:02:38 +00:00
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
# wrap cscli with the correct config file location
|
|
|
|
cscli() {
|
|
|
|
command cscli -c "$CONFIG_FILE" "$@"
|
|
|
|
}
|
2022-02-02 12:20:12 +00:00
|
|
|
|
2022-12-10 21:09:25 +00:00
|
|
|
# conf_get <key> [file_path]
|
|
|
|
# retrieve a value from a file (by default $CONFIG_FILE)
|
2022-11-28 09:35:12 +00:00
|
|
|
conf_get() {
|
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
yq e "$1" "$2"
|
|
|
|
else
|
2023-06-23 13:49:09 +00:00
|
|
|
cscli config show-yaml | yq e "$1"
|
2022-11-28 09:35:12 +00:00
|
|
|
fi
|
|
|
|
}
|
2022-02-15 16:10:15 +00:00
|
|
|
|
2022-12-10 21:09:25 +00:00
|
|
|
# conf_set <yq_expression> [file_path]
|
|
|
|
# evaluate a yq command (by default on $CONFIG_FILE),
|
|
|
|
# create the file if it doesn't exist
|
2022-11-28 09:35:12 +00:00
|
|
|
conf_set() {
|
|
|
|
if [ $# -ge 2 ]; then
|
2022-12-10 21:09:25 +00:00
|
|
|
YAML_FILE="$2"
|
2022-11-28 09:35:12 +00:00
|
|
|
else
|
2022-12-10 21:09:25 +00:00
|
|
|
YAML_FILE="$CONFIG_FILE"
|
2022-11-28 09:35:12 +00:00
|
|
|
fi
|
2023-01-09 20:47:25 +00:00
|
|
|
if [ ! -f "$YAML_FILE" ]; then
|
|
|
|
install -m 0600 /dev/null "$YAML_FILE"
|
|
|
|
fi
|
|
|
|
yq e "$1" -i "$YAML_FILE"
|
2023-01-04 15:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# conf_set_if(): used to update the configuration
|
|
|
|
# only if a given variable is provided
|
|
|
|
# conf_set_if "$VAR" <yq_expression> [file_path]
|
|
|
|
conf_set_if() {
|
|
|
|
if [ "$1" != "" ]; then
|
|
|
|
shift
|
|
|
|
conf_set "$@"
|
|
|
|
fi
|
2022-12-10 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# register_bouncer <bouncer_name> <bouncer_key>
|
|
|
|
register_bouncer() {
|
|
|
|
if ! cscli bouncers list -o json | sed '/^ *"name"/!d;s/^ *"name": "\(.*\)",/\1/' | grep -q "^${1}$"; then
|
|
|
|
if cscli bouncers add "$1" -k "$2" > /dev/null; then
|
|
|
|
echo "Registered bouncer for $1"
|
|
|
|
else
|
|
|
|
echo "Failed to register bouncer for $1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call cscli to manage objects ignoring taint errors
|
|
|
|
# $1 can be collections, parsers, etc.
|
|
|
|
# $2 can be install, remove, upgrade
|
|
|
|
# $3 is a list of object names separated by space
|
|
|
|
cscli_if_clean() {
|
2023-11-24 14:57:32 +00:00
|
|
|
local itemtype="$1"
|
|
|
|
local action="$2"
|
|
|
|
local objs=$3
|
|
|
|
shift 3
|
2022-12-10 21:09:25 +00:00
|
|
|
# loop over all objects
|
2023-11-24 14:57:32 +00:00
|
|
|
for obj in $objs; do
|
|
|
|
if cscli "$itemtype" inspect "$obj" -o json | yq -e '.tainted // false' >/dev/null 2>&1; then
|
|
|
|
echo "Object $itemtype/$obj is tainted, skipping"
|
2022-12-10 21:09:25 +00:00
|
|
|
else
|
2023-01-26 16:13:57 +00:00
|
|
|
# # Too verbose? Only show errors if not in debug mode
|
|
|
|
# if [ "$DEBUG" != "true" ]; then
|
|
|
|
# error_only=--error
|
|
|
|
# fi
|
|
|
|
error_only=""
|
2023-11-24 14:57:32 +00:00
|
|
|
echo "Running: cscli $error_only $itemtype $action \"$obj\" $*"
|
2023-01-26 16:13:57 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-11-24 14:57:32 +00:00
|
|
|
cscli $error_only "$itemtype" "$action" "$obj" "$@"
|
2022-12-10 21:09:25 +00:00
|
|
|
fi
|
|
|
|
done
|
2022-11-28 09:35:12 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 16:13:57 +00:00
|
|
|
# Output the difference between two lists
|
|
|
|
# of items separated by spaces
|
|
|
|
difference() {
|
|
|
|
list1="$1"
|
|
|
|
list2="$2"
|
|
|
|
|
|
|
|
# split into words
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
set -- $list1
|
|
|
|
for item in "$@"; do
|
|
|
|
found=false
|
|
|
|
for i in $list2; do
|
|
|
|
if [ "$item" = "$i" ]; then
|
|
|
|
found=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$found" = false ]; then
|
|
|
|
echo "$item"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
#-----------------------------------#
|
|
|
|
|
2022-12-29 21:00:11 +00:00
|
|
|
if [ -n "$CERT_FILE" ] || [ -n "$KEY_FILE" ] ; then
|
2022-12-16 19:41:39 +00:00
|
|
|
printf '%b' '\033[0;33m'
|
2022-12-29 21:00:11 +00:00
|
|
|
echo "Warning: the variables CERT_FILE and KEY_FILE have been deprecated." >&2
|
|
|
|
echo "Please use LAPI_CERT_FILE and LAPI_KEY_FILE insted." >&2
|
2022-12-16 19:41:39 +00:00
|
|
|
echo "The old variables will be removed in a future release." >&2
|
|
|
|
printf '%b' '\033[0m'
|
2023-01-26 16:12:40 +00:00
|
|
|
export LAPI_CERT_FILE=${LAPI_CERT_FILE:-$CERT_FILE}
|
|
|
|
export LAPI_KEY_FILE=${LAPI_KEY_FILE:-$KEY_FILE}
|
2022-12-16 19:41:39 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
# Check and prestage databases
|
2022-11-08 11:28:57 +00:00
|
|
|
for geodb in GeoLite2-ASN.mmdb GeoLite2-City.mmdb; do
|
2022-11-28 09:35:12 +00:00
|
|
|
# We keep the pre-populated geoip databases in /staging instead of /var,
|
2022-11-08 11:28:57 +00:00
|
|
|
# because if the data directory is bind-mounted from the host, it will be
|
|
|
|
# empty and the files will be out of reach, requiring a runtime download.
|
|
|
|
# We link to them to save about 80Mb compared to cp/mv.
|
|
|
|
if [ ! -e "/var/lib/crowdsec/data/$geodb" ] && [ -e "/staging/var/lib/crowdsec/data/$geodb" ]; then
|
|
|
|
mkdir -p /var/lib/crowdsec/data
|
|
|
|
ln -s "/staging/var/lib/crowdsec/data/$geodb" /var/lib/crowdsec/data/
|
|
|
|
fi
|
|
|
|
done
|
2022-02-01 11:35:57 +00:00
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
# Check and prestage /etc/crowdsec
|
2022-02-01 11:35:57 +00:00
|
|
|
if [ ! -e "/etc/crowdsec/local_api_credentials.yaml" ] && [ ! -e "/etc/crowdsec/config.yaml" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
echo "Populating configuration directory..."
|
|
|
|
# don't overwrite existing configuration files, which may come
|
|
|
|
# from bind-mount or even be read-only (configmaps)
|
|
|
|
if [ -e /staging/etc/crowdsec ]; then
|
|
|
|
mkdir -p /etc/crowdsec/
|
|
|
|
# if you change this, check that it still works
|
|
|
|
# under alpine and k8s, with and without tls
|
2023-11-23 10:08:14 +00:00
|
|
|
rsync -av --ignore-existing /staging/etc/crowdsec/* /etc/crowdsec
|
2022-11-28 09:35:12 +00:00
|
|
|
fi
|
2022-02-01 11:35:57 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-30 13:28:33 +00:00
|
|
|
# do this as soon as we have a config.yaml, to avoid useless warnings
|
|
|
|
if istrue "$USE_WAL"; then
|
|
|
|
conf_set '.db_config.use_wal = true'
|
|
|
|
elif [ -n "$USE_WAL" ] && isfalse "$USE_WAL"; then
|
|
|
|
conf_set '.db_config.use_wal = false'
|
|
|
|
fi
|
|
|
|
|
2023-03-27 13:38:38 +00:00
|
|
|
lapi_credentials_path=$(conf_get '.api.client.credentials_path')
|
|
|
|
|
2022-12-29 21:00:11 +00:00
|
|
|
if isfalse "$DISABLE_LOCAL_API"; then
|
2023-03-27 13:38:38 +00:00
|
|
|
# generate local agent credentials (even if agent is disabled, cscli needs a
|
|
|
|
# connection to the API)
|
|
|
|
if ( isfalse "$USE_TLS" || [ "$CLIENT_CERT_FILE" = "" ] ); then
|
2023-04-12 14:57:38 +00:00
|
|
|
if yq -e '.login==strenv(CUSTOM_HOSTNAME)' "$lapi_credentials_path" >/dev/null && ( cscli machines list -o json | yq -e 'any_c(.machineId==strenv(CUSTOM_HOSTNAME))' >/dev/null ); then
|
2023-03-27 13:38:38 +00:00
|
|
|
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
|
2023-01-04 15:43:35 +00:00
|
|
|
fi
|
2022-12-29 21:00:11 +00:00
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
echo "Check if lapi needs to register an additional agent"
|
2022-12-29 21:00:11 +00:00
|
|
|
# pre-registration is not needed with TLS authentication, but we can have TLS transport with user/pw
|
|
|
|
if [ "$AGENT_USERNAME" != "" ] && [ "$AGENT_PASSWORD" != "" ] ; then
|
|
|
|
# re-register because pw may have been changed
|
2023-01-04 15:43:35 +00:00
|
|
|
cscli machines add "$AGENT_USERNAME" --password "$AGENT_PASSWORD" -f /dev/null --force
|
2022-12-29 21:00:11 +00:00
|
|
|
echo "Agent registered to lapi"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
# ----------------
|
|
|
|
|
|
|
|
conf_set_if "$LOCAL_API_URL" '.url = strenv(LOCAL_API_URL)' "$lapi_credentials_path"
|
2022-12-29 21:00:11 +00:00
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
if istrue "$DISABLE_LOCAL_API"; then
|
|
|
|
# we only use the envvars that are actually defined
|
|
|
|
# in case of persistent configuration
|
|
|
|
conf_set_if "$AGENT_USERNAME" '.login = strenv(AGENT_USERNAME)' "$lapi_credentials_path"
|
|
|
|
conf_set_if "$AGENT_PASSWORD" '.password = strenv(AGENT_PASSWORD)' "$lapi_credentials_path"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
conf_set_if "$INSECURE_SKIP_VERIFY" '.api.client.insecure_skip_verify = env(INSECURE_SKIP_VERIFY)'
|
|
|
|
|
|
|
|
# agent-only containers still require USE_TLS
|
2022-12-16 19:41:39 +00:00
|
|
|
if istrue "$USE_TLS"; then
|
2023-01-04 15:43:35 +00:00
|
|
|
# shellcheck disable=SC2153
|
|
|
|
conf_set_if "$CACERT_FILE" '.ca_cert_path = strenv(CACERT_FILE)' "$lapi_credentials_path"
|
|
|
|
conf_set_if "$CLIENT_KEY_FILE" '.key_path = strenv(CLIENT_KEY_FILE)' "$lapi_credentials_path"
|
|
|
|
conf_set_if "$CLIENT_CERT_FILE" '.cert_path = strenv(CLIENT_CERT_FILE)' "$lapi_credentials_path"
|
2022-12-16 19:41:39 +00:00
|
|
|
else
|
|
|
|
conf_set '
|
|
|
|
del(.ca_cert_path) |
|
|
|
|
del(.key_path) |
|
|
|
|
del(.cert_path)
|
|
|
|
' "$lapi_credentials_path"
|
2021-09-10 12:59:22 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
if istrue "$DISABLE_ONLINE_API"; then
|
|
|
|
conf_set 'del(.api.server.online_client)'
|
|
|
|
fi
|
|
|
|
|
2021-02-10 08:29:29 +00:00
|
|
|
# registration to online API for signal push
|
2023-07-27 15:02:20 +00:00
|
|
|
if isfalse "$DISABLE_LOCAL_API" && isfalse "$DISABLE_ONLINE_API" ; then
|
2023-01-04 15:43:35 +00:00
|
|
|
CONFIG_DIR=$(conf_get '.config_paths.config_dir')
|
2023-01-26 16:12:40 +00:00
|
|
|
export CONFIG_DIR
|
2022-11-28 09:35:12 +00:00
|
|
|
config_exists=$(conf_get '.api.server.online_client | has("credentials_path")')
|
|
|
|
if isfalse "$config_exists"; then
|
2023-01-04 15:43:35 +00:00
|
|
|
conf_set '.api.server.online_client = {"credentials_path": strenv(CONFIG_DIR) + "/online_api_credentials.yaml"}'
|
|
|
|
cscli capi register > "$CONFIG_DIR/online_api_credentials.yaml"
|
2022-11-28 09:35:12 +00:00
|
|
|
echo "Registration to online API done"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
# Enroll instance if enroll key is provided
|
2023-07-27 15:02:20 +00:00
|
|
|
if isfalse "$DISABLE_LOCAL_API" && isfalse "$DISABLE_ONLINE_API" && [ "$ENROLL_KEY" != "" ]; then
|
2022-04-20 11:35:22 +00:00
|
|
|
enroll_args=""
|
2022-11-28 09:35:12 +00:00
|
|
|
if [ "$ENROLL_INSTANCE_NAME" != "" ]; then
|
2022-04-20 11:35:22 +00:00
|
|
|
enroll_args="--name $ENROLL_INSTANCE_NAME"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
if [ "$ENROLL_TAGS" != "" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
for tag in ${ENROLL_TAGS}; do
|
2022-04-20 11:35:22 +00:00
|
|
|
enroll_args="$enroll_args --tags $tag"
|
|
|
|
done
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2022-11-08 11:28:57 +00:00
|
|
|
cscli console enroll $enroll_args "$ENROLL_KEY"
|
2022-04-20 11:35:22 +00:00
|
|
|
fi
|
|
|
|
|
2021-02-25 10:29:39 +00:00
|
|
|
# crowdsec sqlite database permissions
|
|
|
|
if [ "$GID" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
if istrue "$(conf_get '.db_config.type == "sqlite"')"; then
|
2023-07-28 14:01:50 +00:00
|
|
|
# don't fail if the db is not there yet
|
|
|
|
chown -f ":$GID" "$(conf_get '.db_config.db_path')" 2>/dev/null \
|
|
|
|
&& echo "sqlite database permissions updated" \
|
|
|
|
|| true
|
2021-02-25 10:29:39 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-07-27 15:02:20 +00:00
|
|
|
if isfalse "$DISABLE_LOCAL_API" && istrue "$USE_TLS"; then
|
2023-03-24 10:23:04 +00:00
|
|
|
agents_allowed_yaml=$(csv2yaml "$AGENTS_ALLOWED_OU")
|
|
|
|
export agents_allowed_yaml
|
|
|
|
bouncers_allowed_yaml=$(csv2yaml "$BOUNCERS_ALLOWED_OU")
|
|
|
|
export bouncers_allowed_yaml
|
2023-01-04 15:43:35 +00:00
|
|
|
conf_set_if "$CACERT_FILE" '.api.server.tls.ca_cert_path = strenv(CACERT_FILE)'
|
|
|
|
conf_set_if "$LAPI_CERT_FILE" '.api.server.tls.cert_file = strenv(LAPI_CERT_FILE)'
|
|
|
|
conf_set_if "$LAPI_KEY_FILE" '.api.server.tls.key_file = strenv(LAPI_KEY_FILE)'
|
|
|
|
conf_set_if "$BOUNCERS_ALLOWED_OU" '.api.server.tls.bouncers_allowed_ou = env(bouncers_allowed_yaml)'
|
|
|
|
conf_set_if "$AGENTS_ALLOWED_OU" '.api.server.tls.agents_allowed_ou = env(agents_allowed_yaml)'
|
2022-12-10 21:09:25 +00:00
|
|
|
else
|
|
|
|
conf_set 'del(.api.server.tls)'
|
2022-02-02 12:20:12 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-04 15:43:35 +00:00
|
|
|
conf_set_if "$PLUGIN_DIR" '.config_paths.plugin_dir = strenv(PLUGIN_DIR)'
|
2022-02-15 16:10:15 +00:00
|
|
|
|
|
|
|
## Install collections, parsers, scenarios & postoverflows
|
2022-11-28 09:35:12 +00:00
|
|
|
cscli hub update
|
2022-12-10 21:09:25 +00:00
|
|
|
|
|
|
|
cscli_if_clean collections upgrade crowdsecurity/linux
|
|
|
|
cscli_if_clean parsers upgrade crowdsecurity/whitelists
|
|
|
|
cscli_if_clean parsers install crowdsecurity/docker-logs
|
2023-01-20 16:02:04 +00:00
|
|
|
cscli_if_clean parsers install crowdsecurity/cri-logs
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$COLLECTIONS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-01-26 16:13:57 +00:00
|
|
|
cscli_if_clean collections install "$(difference "$COLLECTIONS" "$DISABLE_COLLECTIONS")"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$PARSERS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-01-26 16:13:57 +00:00
|
|
|
cscli_if_clean parsers install "$(difference "$PARSERS" "$DISABLE_PARSERS")"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$SCENARIOS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-01-26 16:13:57 +00:00
|
|
|
cscli_if_clean scenarios install "$(difference "$SCENARIOS" "$DISABLE_SCENARIOS")"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$POSTOVERFLOWS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-01-26 16:13:57 +00:00
|
|
|
cscli_if_clean postoverflows install "$(difference "$POSTOVERFLOWS" "$DISABLE_POSTOVERFLOWS")"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-15 16:10:15 +00:00
|
|
|
## Remove collections, parsers, scenarios & postoverflows
|
|
|
|
if [ "$DISABLE_COLLECTIONS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-11-24 14:57:32 +00:00
|
|
|
cscli_if_clean collections remove "$DISABLE_COLLECTIONS" --force
|
2022-02-15 16:10:15 +00:00
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2022-02-15 16:10:15 +00:00
|
|
|
if [ "$DISABLE_PARSERS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-11-24 14:57:32 +00:00
|
|
|
cscli_if_clean parsers remove "$DISABLE_PARSERS" --force
|
2022-02-15 16:10:15 +00:00
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2022-02-15 16:10:15 +00:00
|
|
|
if [ "$DISABLE_SCENARIOS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-11-24 14:57:32 +00:00
|
|
|
cscli_if_clean scenarios remove "$DISABLE_SCENARIOS" --force
|
2022-02-15 16:10:15 +00:00
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2022-02-15 16:10:15 +00:00
|
|
|
if [ "$DISABLE_POSTOVERFLOWS" != "" ]; then
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2023-11-24 14:57:32 +00:00
|
|
|
cscli_if_clean postoverflows remove "$DISABLE_POSTOVERFLOWS" --force
|
2022-02-15 16:10:15 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-04 08:18:44 +00:00
|
|
|
## Register bouncers via env
|
|
|
|
for BOUNCER in $(compgen -A variable | grep -i BOUNCER_KEY); do
|
|
|
|
KEY=$(printf '%s' "${!BOUNCER}")
|
2022-12-06 15:03:28 +00:00
|
|
|
NAME=$(printf '%s' "$BOUNCER" | cut -d_ -f3-)
|
2022-04-04 08:18:44 +00:00
|
|
|
if [[ -n $KEY ]] && [[ -n $NAME ]]; then
|
2022-12-10 21:09:25 +00:00
|
|
|
register_bouncer "$NAME" "$KEY"
|
2022-04-04 08:18:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-01-26 16:12:40 +00:00
|
|
|
## Register bouncers via secrets (Swarm only)
|
2022-04-04 08:18:44 +00:00
|
|
|
shopt -s nullglob extglob
|
|
|
|
for BOUNCER in /run/secrets/@(bouncer_key|BOUNCER_KEY)* ; do
|
|
|
|
KEY=$(cat "${BOUNCER}")
|
|
|
|
NAME=$(echo "${BOUNCER}" | awk -F "/" '{printf $NF}' | cut -d_ -f2-)
|
2023-07-27 15:02:20 +00:00
|
|
|
if [[ -n $KEY ]] && [[ -n $NAME ]]; then
|
2022-12-10 21:09:25 +00:00
|
|
|
register_bouncer "$NAME" "$KEY"
|
2022-04-04 08:18:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
shopt -u nullglob extglob
|
|
|
|
|
2023-05-25 08:02:33 +00:00
|
|
|
# set all options before validating the configuration
|
|
|
|
|
|
|
|
conf_set_if "$CAPI_WHITELISTS_PATH" '.api.server.capi_whitelists_path = strenv(CAPI_WHITELISTS_PATH)'
|
|
|
|
conf_set_if "$METRICS_PORT" '.prometheus.listen_port=env(METRICS_PORT)'
|
|
|
|
|
2023-07-27 15:02:20 +00:00
|
|
|
if istrue "$DISABLE_LOCAL_API"; then
|
|
|
|
conf_set '.api.server.enable=false'
|
|
|
|
else
|
|
|
|
conf_set '.api.server.enable=true'
|
|
|
|
fi
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS=""
|
|
|
|
if [ "$CONFIG_FILE" != "" ]; then
|
|
|
|
ARGS="-c $CONFIG_FILE"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
2021-06-29 16:03:45 +00:00
|
|
|
if [ "$DSN" != "" ]; then
|
|
|
|
ARGS="$ARGS -dsn ${DSN}"
|
2020-11-30 09:37:17 +00:00
|
|
|
fi
|
2021-06-29 16:03:45 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
if [ "$TYPE" != "" ]; then
|
|
|
|
ARGS="$ARGS -type $TYPE"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
|
|
|
if istrue "$TEST_MODE"; then
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS="$ARGS -t"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
|
|
|
if istrue "$DISABLE_AGENT"; then
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS="$ARGS -no-cs"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
|
|
|
if istrue "$LEVEL_TRACE"; then
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS="$ARGS -trace"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
|
|
|
if istrue "$LEVEL_DEBUG"; then
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS="$ARGS -debug"
|
|
|
|
fi
|
2022-11-28 09:35:12 +00:00
|
|
|
|
|
|
|
if istrue "$LEVEL_INFO"; then
|
2020-11-30 09:37:17 +00:00
|
|
|
ARGS="$ARGS -info"
|
|
|
|
fi
|
|
|
|
|
2022-11-28 09:35:12 +00:00
|
|
|
# shellcheck disable=SC2086
|
2021-11-02 08:19:22 +00:00
|
|
|
exec crowdsec $ARGS
|