Browse Source

docker: add enroll on startup (#1463)

* docker: add enroll on startup
he2ss 3 years ago
parent
commit
ec4e193cbb
2 changed files with 18 additions and 0 deletions
  1. 3 0
      docker/README.md
  2. 15 0
      docker/docker_start.sh

+ 3 - 0
docker/README.md

@@ -153,6 +153,9 @@ Using binds rather than named volumes ([more explanation here](https://docs.dock
 * `DISABLE_POSTOVERFLOWS`   - Postoverflows to remove from the [hub](https://hub.crowdsec.net/browse/#configurations), separated by space : `-e DISABLE_POSTOVERFLOWS="crowdsecurity/cdn-whitelist crowdsecurity/seo-bots-whitelist"`
 * `PLUGIN_DIR`              - Directory for plugins (default: `/usr/local/lib/crowdsec/plugins/`) : `-e PLUGIN_DIR="<path>"`
 * `BOUNCER_KEY_<name>`      - Register a bouncer with the name `<name>` and a key equal to the value of the environment variable.
+* `ENROLL_KEY`              - Enroll key retrieved from [the console](https://app.crowdsec.net/) to enroll the instance.
+* `ENROLL_INSTANCE_NAME`    - To set an instance name and see it on [the console](https://app.crowdsec.net/).
+* `ENROLL_TAGS`             - To set tags when enrolling an instance and use them for search and filtering on [the console](https://app.crowdsec.net/)
 
 ## Volumes
 

+ 15 - 0
docker/docker_start.sh

@@ -65,6 +65,21 @@ if [ "$DISABLE_ONLINE_API" == "" ] && [ "$CONFIG_FILE" == "" ] ; then
     fi
 fi
 
+## Enroll instance if enroll key is provided
+if [ "$DISABLE_ONLINE_API" == "" ] && [ "$ENROLL_KEY" != "" ] ; then
+    enroll_args=""
+    if [ "$ENROLL_INSTANCE_NAME"  != "" ] ; then
+        enroll_args="--name $ENROLL_INSTANCE_NAME"
+    fi
+    if [ "$ENROLL_TAGS"  != "" ] ; then
+        for tag in ${ENROLL_TAGS}
+        do
+            enroll_args="$enroll_args --tags $tag"
+        done
+    fi
+    cscli console enroll $enroll_args $ENROLL_KEY
+fi
+
 # crowdsec sqlite database permissions
 if [ "$GID" != "" ]; then
     IS_SQLITE=$(yq eval '.db_config.type == "sqlite"' "$CS_CONFIG_FILE")