github.com/crowdsecurity/crowdsec@v1.6.1/docker/README.md (about)

     1  # Quick reference
     2  
     3  * Documentation and help: https://docs.crowdsec.net/
     4  * Crowdsec concepts: https://docs.crowdsec.net/docs/concepts
     5  * Where to file issues: https://github.com/crowdsecurity/crowdsec
     6  
     7  # What is Crowdsec
     8  
     9  Crowdsec - An open-source, lightweight agent to detect and respond to bad behaviors. It also automatically benefits from our global community-wide IP reputation database.
    10  
    11  # How to use this image
    12  
    13  ## Image flavors
    14  
    15  All the following images are available on Docker Hub for the architectures
    16  386, amd64, arm/v6, arm/v7, arm64.
    17  
    18  ### Alpine
    19  
    20   - `crowdsecurity/crowdsec:{version}`
    21  
    22  Latest stable release recommended for production usage. Also available on GitHub (ghcr.io).
    23  
    24   - `crowdsecurity/crowdsec:dev`
    25  
    26  For development and testing, from the master branch.
    27  
    28  since v1.4.2:
    29  
    30   - `crowdsecurity/crowdsec:slim`
    31  
    32  Reduced size by 60%, it does not include the notifier plugins nor the GeoIP database.
    33  If you need these details on decisions, run `cscli hub upgrade` inside the
    34  container to download the GeoIP database at runtime.
    35  
    36  
    37  ### Debian (since v1.3.3)
    38  
    39   - `crowdsecurity/crowdsec:{version}-debian`
    40   - `crowdsecurity/crowdsec:latest-debian`
    41  
    42  The debian version includes support for systemd and journalctl.
    43  
    44  ### Custom
    45  
    46  You can build your custom images with Dockerfile and Dockerfile-debian.
    47  
    48  For example, if you need a Debian version without plugin notifiers:
    49  
    50  ```console
    51  $ docker build -f Dockerfile.debian --target slim .
    52  ```
    53  
    54  The supported values for target are: full, geoip, plugins, slim.
    55  
    56  Note: for crowdsec versions < 1.5.0, the syntax is
    57  
    58  ```console
    59  $ docker build -f Dockerfile.debian --build-arg=BUILD_ENV=slim .
    60  ```
    61  
    62  
    63  ## Required configuration
    64  
    65  ### Journalctl (only for debian image)
    66  
    67  To use journalctl as a log stream, with or without the `DSN` environment variable, you need to mount the journal log from the host to the container itself.
    68  This can be done by adding the following volume mount to the docker command:
    69  
    70  ```
    71  -v /var/log/journal:/run/log/journal
    72  ```
    73  
    74  ### Logs ingestion and processing
    75  
    76  Collections are a good place to start: https://docs.crowdsec.net/docs/collections/intro
    77  
    78  Find collections, scenarios, parsers and postoverflows in the hub: https://hub.crowdsec.net
    79  
    80  * 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)
    81  * Mount volumes to specify which log files should be ingested by crowdsec
    82  
    83  
    84  ### Acquisition (one file per datasource - recommended)
    85  
    86  The files in `/etc/crowdsec/acquis.d/` map the logs to the provided parsers. Find out more here: https://docs.crowdsec.net/docs/concepts/#acquisition
    87  
    88  The directory might contain for example
    89  
    90  `ssh.yaml`:
    91  
    92  ```yaml
    93  filenames:
    94   - /logs/auth.log
    95   - /logs/syslog
    96  labels:
    97    type: syslog
    98  ```
    99  
   100  `apache.yaml`:
   101  
   102  ``` yaml
   103  filename: /logs/apache2/*.log
   104  labels:
   105    type: apache2
   106  ```
   107  
   108  `labels.type`: use `syslog` if the logs come from syslog, otherwise check the collection's documentation for the relevant type.
   109  
   110  You can bind the directory from the host or have it in a Docker volume, the former is easier to update as you add more applications.
   111  
   112  Note: In versions < 1.5, the acquisition directory is not configured by default. You can add it by mounting the `/etc/crowdsec/config.yaml.local` file:
   113  
   114  ```yaml
   115  crowdsec_service:
   116    acquisition_dir: /etc/crowdsec/acquis.d
   117  ```
   118  
   119  
   120  ### Acquisition (single file - deprecated)
   121  
   122  Before 1.5.0, it was recommended to put your acquisition configuration in /etc/crowdsec/acquis.yaml. You can still do it
   123  if you prefer but it's more effective to have one file per datasource.
   124  
   125  ```yaml title="/etc/crowdsec/acquis.yaml"
   126  filenames:
   127   - /logs/auth.log
   128   - /logs/syslog
   129  labels:
   130    type: syslog
   131  ---
   132  filename: /logs/apache2/*.log
   133  labels:
   134    type: apache2
   135  ```
   136  
   137  ## Recommended configuration
   138  
   139  ### Volumes
   140  
   141  We strongly suggest persisting the Crowdsec configuration and database in **named volumes**, or bind-mount them from the host,
   142  to avoid losing credentials and decision data in case of container destruction and recreation, version update, etc.
   143  
   144  * Credentials and configuration: `/etc/crowdsec`
   145  * Acquisition: `/etc/crowdsec/acquis.d` and/or `/etc/crowdsec.acquis.yaml` (yes, they can be nested in `/etc/crowdsec`)
   146  * Database when using SQLite (default): `/var/lib/crowdsec/data`
   147  
   148  ### Hub updates
   149  
   150  To ensure you have the latest version of the collections, scenarios, parsers, etc., you can set the variable `DO_HUB_UPGRADE` to true.
   151  This will perform an update/upgrade of the hub every time the container is started.
   152  
   153  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
   154  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
   155  correctly and make sure you have some monitoring in place.
   156  
   157  ## Start a Crowdsec instance
   158  
   159  ```shell
   160  docker run -d \
   161      -v crowdsec_config:/etc/crowdsec \
   162      -v local_path_to_crowdsec_config/acquis.d:/etc/crowdsec/acquis.d \
   163      -v local_path_to_crowdsec_config/acquis.yaml:/etc/crowdsec/acquis.yaml \
   164      -v crowdsec_data:/var/lib/crowdsec/data \
   165      -v /var/log/auth.log:/logs/auth.log:ro \
   166      -v /var/log/syslog.log:/logs/syslog.log:ro \
   167      -v /var/log/apache:/logs/apache:ro \
   168      -e COLLECTIONS="crowdsecurity/apache2 crowdsecurity/sshd" \
   169      -p 8080:8080 -p 6060:6060 \
   170      --name crowdsec crowdsecurity/crowdsec
   171  ```
   172  
   173  
   174  ## ... or docker-compose
   175  
   176  Check this full-stack example using docker-compose: https://github.com/crowdsecurity/example-docker-compose
   177  
   178  
   179  # How to extend this image
   180  
   181  ## Full configuration
   182  
   183  The container is built with a specific docker
   184  [configuration](https://github.com/crowdsecurity/crowdsec/blob/master/docker/config.yaml).
   185  If you need to change it and the docker variables (see below) are not enough,
   186  you can mount `/etc/crowdsec/config.yaml.local` from the host.
   187  The file should contain only the options from `config.yaml` that you want to change,
   188  as documented in [`Overriding values`](https://docs.crowdsec.net/docs/configuration/crowdsec_configuration#overriding-values).
   189  
   190  It is not recommended anymore to bind-mount the full config.yaml file and you should not need to do it.
   191  
   192  ## Notifications
   193  
   194  If you want to use the [notification system](https://docs.crowdsec.net/docs/notification_plugins/intro), you have to use the full image (not slim) and mount at least a custom `profiles.yaml` and a notification configuration to `/etc/crowdsec/notifications`
   195  
   196  ```shell
   197  docker run -d \
   198      -v ./profiles.yaml:/etc/crowdsec/profiles.yaml \
   199      -v ./http_notification.yaml:/etc/crowdsec/notifications/http_notification.yaml \
   200      -p 8080:8080 -p 6060:6060 \
   201      --name crowdsec crowdsecurity/crowdsec
   202  ```
   203  
   204  # Deployment use cases
   205  
   206  Crowdsec is composed of an `agent` that parses logs and creates `alerts`, and a
   207  `local API (LAPI)` that transforms these alerts into decisions. Both functions
   208  are provided by the same executables, so the agent and the LAPI can run in the
   209  same or separate containers. In complex configurations, it makes sense to have
   210  agents on each machine that runs the protected applications, and a LAPI that
   211  gathers all signals from agents and communicates with the `central API`.
   212  
   213  ## Register a new agent with LAPI
   214  
   215  Without TLS authentication:
   216  
   217  ```shell
   218  docker exec -it crowdsec_lapi_container_name cscli machines add agent_user_name --password agent_password
   219  ```
   220  
   221  With TLS authentication:
   222  
   223  Agents are automatically registered and don't need a username or password. The
   224  agents' names are derived from the IP address from which they connect.
   225  
   226  ## Run an agent connected to LAPI
   227  
   228  Add the following environment variables to the docker run command:
   229  
   230  * `DISABLE_LOCAL_API=true`
   231  * `AGENT_USERNAME="agent_user_name"` - agent_user_name previously registered with LAPI
   232  * `AGENT_PASSWORD="agent_password"` - agent_password previously registered with LAPI
   233  * `LOCAL_API_URL="http://LAPI_host:LAPI_port"`
   234  
   235  # Next steps
   236  
   237  ## Bouncers
   238  
   239  Crowdsec being a detection component, the remediation is implemented using `bouncers`. Each bouncer protects a specific component. Find out more:
   240  
   241  https://hub.crowdsec.net/browse/#bouncers
   242  
   243  https://docs.crowdsec.net/docs/user_guides/bouncers_configuration/
   244  
   245  ### Automatic Bouncer Registration
   246  
   247  Without TLS authentication:
   248  
   249  You can register bouncers with the crowdsec container at startup, using environment variables or Docker secrets. You cannot use this process to update an existing bouncer without first deleting it.
   250  
   251  To use environment variables, they should be in the format `BOUNCER_KEY_<name>=<key>`. e.g. `BOUNCER_KEY_nginx=mysecretkey12345`.
   252  
   253  To use Docker secrets, the secret should be named `bouncer_key_<name>` with a content of `<key>`. e.g. `bouncer_key_nginx` with content `mysecretkey12345`.
   254  
   255  A bouncer key can be any string but we recommend an alphanumeric value for consistency with the keys generated by crowdsec and to avoid problems with escaping special characters.
   256  
   257  With TLS authentication:
   258  
   259  Bouncers are automatically registered and don't need an API key. The
   260  bouncers' names are derived from the IP address from which they connect.
   261  
   262  ## Console
   263  We provide a web-based interface to get more from Crowdsec: https://docs.crowdsec.net/docs/console
   264  
   265  Subscribe here: https://app.crowdsec.net
   266  
   267  # Caveats
   268  
   269  Using binds rather than named volumes ([complete explanation here](https://docs.docker.com/storage/volumes/)) results in more complexity as you'll have to bind the relevant files one by one whereas with named volumes you can mount full configuration and data folders. On the other hand, named volumes are less straightforward to navigate.
   270  
   271  # Reference
   272  ## Environment Variables
   273  
   274  Note for persistent configurations (i.e. bind mount or volumes): when a
   275  variable is set, its value may be written to the appropriate file (usually
   276  config.yaml) each time the container is run.
   277  
   278  
   279  | Variable                | Default                   | Description |
   280  | ----------------------- | ------------------------- | ----------- |
   281  | `CONFIG_FILE`           | `/etc/crowdsec/config.yaml` | Configuration file location |
   282  | `DISABLE_AGENT`         | false | Disable the agent, run a LAPI-only container |
   283  | `DISABLE_LOCAL_API`     | false | Disable LAPI, run an agent-only container |
   284  | `DISABLE_ONLINE_API`    | false | Disable online API registration for signal sharing |
   285  | `TEST_MODE`             | false | Don't run the service, only test the configuration: `-e TEST_MODE=true` |
   286  | `TZ`                    | | Set the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to ensure the logs have a local timestamp. |
   287  | `LOCAL_API_URL`         | `http://0.0.0.0:8080` | The LAPI URL, you need to change this when `DISABLE_LOCAL_API` is true: `-e LOCAL_API_URL="http://lapi-address:8080"` |
   288  | `PLUGIN_DIR`            | `/usr/local/lib/crowdsec/plugins/` | Directory for plugins: `-e PLUGIN_DIR="<path>"` |
   289  | `METRICS_PORT`          | 6060 | Port to expose Prometheus metrics |
   290  |                         | | |
   291  | __LAPI__                | | (useless with DISABLE_LOCAL_API) |
   292  | `USE_WAL`               | false | Enable Write-Ahead Logging with SQLite |
   293  | `CUSTOM_HOSTNAME`       | localhost | Name for the local agent (running in the container with LAPI) |
   294  | `CAPI_WHITELISTS_PATH`  | | Path for capi_whitelists.yaml |
   295  |                         | | |
   296  | __Agent__               | | (these don't work with DISABLE_AGENT) |
   297  | `TYPE`                  | | [`Labels.type`](https://docs.crowdsec.net/Crowdsec/v1/references/acquisition/) for file in time-machine: `-e TYPE="<type>"` |
   298  | `DSN`                   | | Process a single source in time-machine: `-e DSN="file:///var/log/toto.log"` or `-e DSN="cloudwatch:///your/group/path:stream_name?profile=dev&backlog=16h"` or `-e DSN="journalctl://filters=_SYSTEMD_UNIT=ssh.service"` |
   299  |                         | | |
   300  | __Bouncers__            | | |
   301  | `BOUNCER_KEY_<name>`    | | Register a bouncer with the name `<name>` and a key equal to the value of the environment variable. |
   302  |                         | | |
   303  | __Console__             | | |
   304  | `ENROLL_KEY`            | | Enroll key retrieved from [the console](https://app.crowdsec.net/) to enroll the instance. |
   305  | `ENROLL_INSTANCE_NAME`  | | To set an instance name and see it on [the console](https://app.crowdsec.net/) |
   306  | `ENROLL_TAGS`           | | Tags of the enrolled instance, for search and filter |
   307  |                         | | |
   308  | __Password Auth__       | | |
   309  | `AGENT_USERNAME`        | | Agent username (to register if is LAPI or to use if it's an agent): `-e AGENT_USERNAME="machine_id"` |
   310  | `AGENT_PASSWORD`        | | Agent password (to register if is LAPI or to use if it's an agent): `-e AGENT_PASSWORD="machine_password"` |
   311  |                         | | |
   312  | __TLS Encryption__      | | |
   313  | `USE_TLS`               | false | Enable TLS encryption (either as a LAPI or agent) |
   314  | `CACERT_FILE`           | | CA certificate bundle (for self-signed certificates) |
   315  | `INSECURE_SKIP_VERIFY`  | | Skip LAPI certificate validation |
   316  | `LAPI_CERT_FILE`        | | LAPI TLS Certificate path |
   317  | `LAPI_KEY_FILE`         | | LAPI TLS Key path |
   318  |                         | | |
   319  | __TLS Authentication__  | | (these require USE_TLS=true) |
   320  | `CLIENT_CERT_FILE`      | | Client TLS Certificate path (enable TLS authentication) |
   321  | `CLIENT_KEY_FILE`       | | Client TLS Key path |
   322  | `AGENTS_ALLOWED_OU`     | agent-ou | OU values allowed for agents, separated by comma |
   323  | `BOUNCERS_ALLOWED_OU`   | bouncer-ou | OU values allowed for bouncers, separated by comma |
   324  |                         | | |
   325  | __Hub management__      | | |
   326  | `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. |
   327  | `COLLECTIONS`           | | Collections to install, separated by space: `-e COLLECTIONS="crowdsecurity/linux crowdsecurity/apache2"` |
   328  | `PARSERS`               | | Parsers to install, separated by space |
   329  | `SCENARIOS`             | | Scenarios to install, separated by space |
   330  | `POSTOVERFLOWS`         | | Postoverflows to install, separated by space |
   331  | `CONTEXTS`              | | Context files to install, separated by space |
   332  | `APPSEC_CONFIGS`        | | Appsec configs files to install, separated by space |
   333  | `APPSEC_RULES`          | | Appsec rules files to install, separated by space |
   334  | `DISABLE_COLLECTIONS`   | | Collections to remove, separated by space: `-e DISABLE_COLLECTIONS="crowdsecurity/linux crowdsecurity/nginx"` |
   335  | `DISABLE_PARSERS`       | | Parsers to remove, separated by space |
   336  | `DISABLE_SCENARIOS`     | | Scenarios to remove, separated by space |
   337  | `DISABLE_POSTOVERFLOWS` | | Postoverflows to remove, separated by space |
   338  | `DISABLE_CONTEXTS`      | | Context files to remove, separated by space |
   339  | `DISABLE_APPSEC_CONFIGS`| | Appsec configs files to remove, separated by space |
   340  | `DISABLE_APPSEC_RULES`  | | Appsec rules files to remove, separated by space |
   341  |                         | | |
   342  | __Log verbosity__       | | |
   343  | `LEVEL_INFO`            | false | Force INFO level for the container log |
   344  | `LEVEL_DEBUG`           | false | Force DEBUG level for the container log |
   345  | `LEVEL_TRACE`           | false | Force TRACE level (VERY verbose) for the container log |
   346  |                         | | |
   347  | __Developer options__   | | |
   348  | `CI_TESTING`            | false | Used during functional tests |
   349  | `DEBUG`                 | false | Trace the entrypoint |
   350  
   351  ## File Locations
   352  
   353  * `/usr/local/bin/crowdsec` - Crowdsec binary
   354  
   355  * `/usr/local/bin/cscli` - Crowdsec CLI binary to interact with crowdsec
   356  
   357  # Find Us
   358  
   359  * [GitHub](https://github.com/crowdsecurity/crowdsec)
   360  
   361  # Contributing
   362  
   363  Please read [contributing](https://docs.crowdsec.net/Crowdsec/v1/contributing/) for details on our code of conduct, and the process for submitting pull requests to us.
   364  
   365  # License
   366  
   367  This project is licensed under the MIT License - see the [LICENSE](https://github.com/crowdsecurity/crowdsec/blob/master/LICENSE) file for details.