From 18ff3a3a306d1eca786038fb343250e43784a900 Mon Sep 17 00:00:00 2001 From: erenJag <64777133+erenJag@users.noreply.github.com> Date: Wed, 10 Feb 2021 09:29:29 +0100 Subject: [PATCH] update docker image + documentation (#602) Co-authored-by: erenJag --- Dockerfile | 4 ++-- docker/README.md | 12 ++++++------ docker/config.yaml | 2 +- docker/docker_start.sh | 10 ++++++---- docs/v1.X/docs/docker/README.md | 14 ++++++-------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index b18642f12..05686a6bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,12 @@ WORKDIR /go/src/crowdsec COPY . . RUN apk update && apk add git jq gcc libc-dev make bash gettext -RUN BUILD_VERSION="$(git describe --tags `git rev-list --tags --max-count=1`)" make release +RUN BUILD_VERSION="$(git describe --tags `git rev-list --tags --max-count=1`)-docker" make release RUN /bin/bash wizard.sh --docker-mode RUN cscli hub update && cscli collections install crowdsecurity/linux FROM alpine:latest +RUN wget https://github.com/mikefarah/yq/releases/download/v4.4.1/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq COPY --from=build /etc/crowdsec /etc/crowdsec COPY --from=build /var/lib/crowdsec /var/lib/crowdsec COPY --from=build /usr/local/bin/crowdsec /usr/local/bin/crowdsec @@ -18,5 +19,4 @@ COPY --from=build /usr/local/bin/cscli /usr/local/bin/cscli COPY --from=build /go/src/crowdsec/docker/docker_start.sh / COPY --from=build /go/src/crowdsec/docker/config.yaml /etc/crowdsec/config.yaml - ENTRYPOINT /bin/sh docker_start.sh \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index 702adda58..651c76901 100644 --- a/docker/README.md +++ b/docker/README.md @@ -31,17 +31,15 @@ The container is built with specific docker [configuration](https://github.com/c You should apply following configuration before starting it : * Specify collections|scenarios|parsers/postoverflows to install via the environment variables (by default [`crowdsecurity/linux`](https://hub.crowdsec.net/author/crowdsecurity/collections/linux) is installed) -* Mount volumes to specify your configuration * Mount volumes to specify your log files that should be ingested by crowdsec (set up in acquis.yaml) * Mount other volumes : if you want to share the database for example ```shell -docker run -d -v config.yaml:/etc/crowdsec/config.yaml \ - -v acquis.yaml:/etc/crowdsec/acquis.yaml \ +docker run -d -v acquis.yaml:/etc/crowdsec/acquis.yaml \ -e COLLECTIONS="crowdsecurity/sshd" -v /var/log/auth.log:/var/log/auth.log \ -v /path/mycustom.log:/var/log/mycustom.log \ - --name crowdsec + --name crowdsec crowdsecurity/crowdsec ``` #### Example @@ -83,9 +81,11 @@ docker run -d -v config.yaml:/etc/crowdsec/config.yaml \ -v /path/myDatabase.db:/var/lib/crowdsec/data/crowdsec.db \ -e COLLECTIONS="crowdsecurity/apache2 crowdsecurity/sshd" \ -p 8080:8080 -p 6060:6060 \ - --name crowdsec + --name crowdsec crowdsecurity/crowdsec ``` +If you want to be able to restart/stop your container and keep the same DB `-v /path/myDatabase.db:/var/lib/crowdsec/data/crowdsec.db` you need to add a volume on local_api_credentials.yaml `-v /path/local_api_credentials.yaml:/etc/crowdsec/local_api_credentials.yaml`. + ### Environment Variables * `COLLECTIONS` - Collections to install from the [hub](https://hub.crowdsec.net/browse/#collections), separated by space : `-e COLLECTIONS="crowdsecurity/linux crowdsecurity/apache2"` @@ -99,7 +99,7 @@ docker run -d -v config.yaml:/etc/crowdsec/config.yaml \ * `TEST_MODE` - Only test configs (default: `false`) : `-e TEST_MODE=""` * `DISABLE_AGENT` - Only test configs (default: `false`) : `-e DISABLE_AGENT=""` * `DISABLE_LOCAL_API` - Disable local API (default: `false`) : `-e DISABLE_API=""` -* `REGISTER_TO_ONLINE_API` - Register to Online API (default: `false`) : `-e REGISTER_TO_ONLINE_API=""` +* `DISABLE_ONLINE_API` - Disable Online API registration for signal sharing (default: `false`) : `-e DISABLE_ONLINE_API=""` * `LEVEL_TRACE` - Trace-level (VERY verbose) on stdout (default: `false`) : `-e LEVEL_TRACE=""` * `LEVEL_DEBUG` - Debug-level on stdout (default: `false`) : `-e LEVEL_DEBUG=""` * `LEVEL_INFO` - Info-level on stdout (default: `false`) : `-e LEVEL_INFO=""` diff --git a/docker/config.yaml b/docker/config.yaml index 65ea76124..6c39256f2 100644 --- a/docker/config.yaml +++ b/docker/config.yaml @@ -16,7 +16,7 @@ crowdsec_service: parser_routines: 1 cscli: output: human - hub_branch: wip_lapi + hub_branch: master db_config: log_level: info type: sqlite diff --git a/docker/docker_start.sh b/docker/docker_start.sh index ea807fb65..b9fe225d1 100644 --- a/docker/docker_start.sh +++ b/docker/docker_start.sh @@ -6,10 +6,12 @@ if [ $? == 1 ]; then cscli machines add --force --auto -f /etc/crowdsec/local_api_credentials.yaml fi -if [ "$REGISTER_TO_ONLINE_API" == "true" ] || [ "$REGISTER_TO_ONLINE_API" == "TRUE" ] && [ "$CONFIG_FILE" == "" ] ; then - cat /etc/crowdsec/config.yaml | grep online_api_credentials.yaml - if [ $? == 1 ]; then - sed -ri 's/^(\s*)(#credentials_path\s*:\s*$)/\1credentials_path: \/etc\/crowdsec\/online_api_credentials.yaml/' /etc/crowdsec/config.yaml +# registration to online API for signal push +if [ "$DISABLE_ONLINE_API" == "" ] && [ "$CONFIG_FILE" == "" ] ; then + CONFIG_EXIST=$(yq eval '.api.server.online_client | has("credentials_path")' /etc/crowdsec/config.yaml) + if [ "$CONFIG_EXIST" != "true" ]; then + yq eval '.api.server.online_client = {"credentials_path": "/etc/crowdsec/online_api_credentials.yaml"}' /etc/crowdsec/config.yaml > /etc/crowdsec/config2.yaml + mv /etc/crowdsec/config2.yaml /etc/crowdsec/config.yaml cscli capi register > /etc/crowdsec/online_api_credentials.yaml fi fi diff --git a/docs/v1.X/docs/docker/README.md b/docs/v1.X/docs/docker/README.md index 0193d8b87..651c76901 100644 --- a/docs/v1.X/docs/docker/README.md +++ b/docs/v1.X/docs/docker/README.md @@ -31,17 +31,15 @@ The container is built with specific docker [configuration](https://github.com/c You should apply following configuration before starting it : * Specify collections|scenarios|parsers/postoverflows to install via the environment variables (by default [`crowdsecurity/linux`](https://hub.crowdsec.net/author/crowdsecurity/collections/linux) is installed) -* Mount volumes to specify your configuration * Mount volumes to specify your log files that should be ingested by crowdsec (set up in acquis.yaml) * Mount other volumes : if you want to share the database for example ```shell -docker run -d -v config.yaml:/etc/crowdsec/config.yaml \ - -v acquis.yaml:/etc/crowdsec/acquis.yaml \ +docker run -d -v acquis.yaml:/etc/crowdsec/acquis.yaml \ -e COLLECTIONS="crowdsecurity/sshd" -v /var/log/auth.log:/var/log/auth.log \ -v /path/mycustom.log:/var/log/mycustom.log \ - --name crowdsec + --name crowdsec crowdsecurity/crowdsec ``` #### Example @@ -83,10 +81,10 @@ docker run -d -v config.yaml:/etc/crowdsec/config.yaml \ -v /path/myDatabase.db:/var/lib/crowdsec/data/crowdsec.db \ -e COLLECTIONS="crowdsecurity/apache2 crowdsecurity/sshd" \ -p 8080:8080 -p 6060:6060 \ - --name crowdsec + --name crowdsec crowdsecurity/crowdsec ``` -If you want to be able to restart/stop your container and keep the same DB `-v /path/myDatabase.db:/var/lib/crowdsec/data/crowdsec.db` you need to add a volume on local_api_credentials.yaml `-v /path/local_api_credentials.yaml:/etc/crowdsec/local_api_credentials.yaml` +If you want to be able to restart/stop your container and keep the same DB `-v /path/myDatabase.db:/var/lib/crowdsec/data/crowdsec.db` you need to add a volume on local_api_credentials.yaml `-v /path/local_api_credentials.yaml:/etc/crowdsec/local_api_credentials.yaml`. ### Environment Variables @@ -101,7 +99,7 @@ If you want to be able to restart/stop your container and keep the same DB `-v / * `TEST_MODE` - Only test configs (default: `false`) : `-e TEST_MODE=""` * `DISABLE_AGENT` - Only test configs (default: `false`) : `-e DISABLE_AGENT=""` * `DISABLE_LOCAL_API` - Disable local API (default: `false`) : `-e DISABLE_API=""` -* `REGISTER_TO_ONLINE_API` - Register to Online API (default: `false`) : `-e REGISTER_TO_ONLINE_API=""` +* `DISABLE_ONLINE_API` - Disable Online API registration for signal sharing (default: `false`) : `-e DISABLE_ONLINE_API=""` * `LEVEL_TRACE` - Trace-level (VERY verbose) on stdout (default: `false`) : `-e LEVEL_TRACE=""` * `LEVEL_DEBUG` - Debug-level on stdout (default: `false`) : `-e LEVEL_DEBUG=""` * `LEVEL_INFO` - Info-level on stdout (default: `false`) : `-e LEVEL_INFO=""` @@ -128,4 +126,4 @@ Please read [contributing](https://docs.crowdsec.net/Crowdsec/v1/contributing/) ## License -This project is licensed under the MIT License - see the [LICENSE](https://github.com/crowdsecurity/crowdsec/blob/master/LICENSE) file for details. +This project is licensed under the MIT License - see the [LICENSE](https://github.com/crowdsecurity/crowdsec/blob/master/LICENSE) file for details. \ No newline at end of file