Compare commits
6 commits
master
...
docker_hub
Author | SHA1 | Date | |
---|---|---|---|
|
5870b9fca8 | ||
|
6cc1e5fc64 | ||
|
6d60362fdd | ||
|
f8d75db913 | ||
|
5980810fd8 | ||
|
6a5da6dfae |
5 changed files with 48 additions and 20 deletions
14
.github/workflows/docker-tests.yml
vendored
14
.github/workflows/docker-tests.yml
vendored
|
@ -59,15 +59,15 @@ jobs:
|
|||
cd docker/test
|
||||
python -m pip install --upgrade pipenv wheel
|
||||
|
||||
- name: "Cache virtualenvs"
|
||||
id: cache-pipenv
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.local/share/virtualenvs
|
||||
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
|
||||
#- name: "Cache virtualenvs"
|
||||
# id: cache-pipenv
|
||||
# uses: actions/cache@v4
|
||||
# with:
|
||||
# path: ~/.local/share/virtualenvs
|
||||
# key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
|
||||
|
||||
- name: "Install dependencies"
|
||||
if: steps.cache-pipenv.outputs.cache-hit != 'true'
|
||||
#if: steps.cache-pipenv.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
cd docker/test
|
||||
pipenv install --deploy
|
||||
|
|
|
@ -134,6 +134,7 @@ labels:
|
|||
type: apache2
|
||||
```
|
||||
|
||||
|
||||
## Recommended configuration
|
||||
|
||||
### Volumes
|
||||
|
@ -145,14 +146,6 @@ to avoid losing credentials and decision data in case of container destruction a
|
|||
* Acquisition: `/etc/crowdsec/acquis.d` and/or `/etc/crowdsec.acquis.yaml` (yes, they can be nested in `/etc/crowdsec`)
|
||||
* Database when using SQLite (default): `/var/lib/crowdsec/data`
|
||||
|
||||
### Hub updates
|
||||
|
||||
To ensure you have the latest version of the collections, scenarios, parsers, etc., you can set the variable `DO_HUB_UPGRADE` to true.
|
||||
This will perform an update/upgrade of the hub every time the container is started.
|
||||
|
||||
Be aware that if your container is misbehaving and caught in a restart loop, the CrowdSec hub may ban your IP for some time and your containers
|
||||
will run with the version of the hub that is cached in the container's image. If you enable `DO_HUB_UPGRADE`, do it when your infrastructure is running
|
||||
correctly and make sure you have some monitoring in place.
|
||||
|
||||
## Start a Crowdsec instance
|
||||
|
||||
|
@ -323,7 +316,7 @@ config.yaml) each time the container is run.
|
|||
| `BOUNCERS_ALLOWED_OU` | bouncer-ou | OU values allowed for bouncers, separated by comma |
|
||||
| | | |
|
||||
| __Hub management__ | | |
|
||||
| `DO_HUB_UPGRADE` | false | Force hub update / upgrade when the container starts. If for some reason the container restarts too often, it may lead to a temporary ban from hub updates. |
|
||||
| `NO_HUB_UPGRADE` | false | Skip hub update / upgrade when the container starts |
|
||||
| `COLLECTIONS` | | Collections to install, separated by space: `-e COLLECTIONS="crowdsecurity/linux crowdsecurity/apache2"` |
|
||||
| `PARSERS` | | Parsers to install, separated by space |
|
||||
| `SCENARIOS` | | Scenarios to install, separated by space |
|
||||
|
|
|
@ -50,6 +50,34 @@ cscli() {
|
|||
command cscli -c "$CONFIG_FILE" "$@"
|
||||
}
|
||||
|
||||
run_hub_update() {
|
||||
index_modification_time=$(stat -c %Y /etc/crowdsec/hub/.index.json 2>/dev/null)
|
||||
#Run cscli hub update if no date or if the index file is older than 24h
|
||||
if [ -z "$index_modification_time" ] || [ $(( $(date +%s) - $index_modification_time )) -gt 86400 ]; then
|
||||
cscli hub update
|
||||
else
|
||||
echo "Skipping hub update, index file is recent"
|
||||
fi
|
||||
}
|
||||
|
||||
run_hub_update_if_from_volume() {
|
||||
path=$(readlink -f "/etc/crowdsec/hub/.index.json") # even though it's unlikely, resolve symlink
|
||||
mounts=$(awk '{print $2}' /proc/mounts)
|
||||
while true; do
|
||||
if grep -qE ^"$path"$ <<< "$mounts"; then
|
||||
echo "$path was found in a volume, running hub update"
|
||||
run_hub_update
|
||||
return 0
|
||||
fi
|
||||
path=$(dirname "$path")
|
||||
if [ "$path" = "/" ]; then
|
||||
echo "It looks like the hub index is not in a volume, skipping update"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 1 #unreachable
|
||||
}
|
||||
|
||||
# conf_get <key> [file_path]
|
||||
# retrieve a value from a file (by default $CONFIG_FILE)
|
||||
conf_get() {
|
||||
|
@ -120,6 +148,12 @@ cscli_if_clean() {
|
|||
echo "Running: cscli $error_only $itemtype $action \"$obj\" $*"
|
||||
# shellcheck disable=SC2086
|
||||
cscli $error_only "$itemtype" "$action" "$obj" "$@"
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "Failed to $action $itemtype/$obj, running hub update before retrying"
|
||||
run_hub_update
|
||||
# shellcheck disable=SC2086
|
||||
cscli $error_only "$itemtype" "$action" "$obj" "$@"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -304,8 +338,9 @@ conf_set_if "$PLUGIN_DIR" '.config_paths.plugin_dir = strenv(PLUGIN_DIR)'
|
|||
|
||||
## Install hub items
|
||||
|
||||
if istrue "$DO_HUB_UPGRADE"; then
|
||||
cscli hub update || true
|
||||
run_hub_update_if_from_volume || true
|
||||
|
||||
if isfalse "$NO_HUB_UPGRADE"; then
|
||||
cscli hub upgrade || true
|
||||
fi
|
||||
|
||||
|
|
0
docker/preload-hub-items
Executable file → Normal file
0
docker/preload-hub-items
Executable file → Normal file
Loading…
Reference in a new issue