Skip to content

Commit 831c782

Browse files
authored
document "Service Discovery & Setup" (#860)
1 parent bad9719 commit 831c782

File tree

22 files changed

+556
-52
lines changed

22 files changed

+556
-52
lines changed

crowdsec-docs/docs/appsec/alerts_and_scenarios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ We can now create a scenario that will trigger when a single IPs triggers this r
115115
type: leaky
116116
format: 3.0
117117
name: crowdsecurity/foobar-enum
118-
description: "Ban IPs repeateadly triggering out of band rules"
118+
description: "Ban IPs repeatedly triggering out of band rules"
119119
filter: "evt.Meta.log_type == 'appsec-info' && evt.Meta.rule_name == 'crowdsecurity/foobar-access'"
120120
distinct: evt.Meta.target_uri
121121
leakspeed: "60s"

crowdsec-docs/docs/appsec/benchmark.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sidebar_position: 80
1515
1616
-->
1717

18-
The Application Security Component benchmarks have been run on a AWS EC2 Instance `t2.medium` (2vCPU/4Go RAM).
18+
The Application Security Component benchmarks have been run on a AWS EC2 Instance `t2.medium` (2vCPU/4GiB RAM).
1919

2020
All the benchmarks have been run with only one `routine` configured for the Application Security Component.
2121

crowdsec-docs/docs/appsec/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_position: 6
66

77
## Overview
88

9-
This page explains the interraction between various files involved in AppSec configuration and the details about the processing pipeline AppSec request processing.
9+
This page explains the interaction between various files involved in AppSec configuration and the details about the processing pipeline AppSec request processing.
1010

1111
**Prerequisites**:
1212
- Familiarity with [AppSec concepts](/appsec/intro.md)
@@ -24,7 +24,7 @@ The goals of the acquisition file are:
2424
- To specify the **address** and **port** where the AppSec-enabled Remediation Component(s) will forward the requests to.
2525
- And specify one or more [AppSec configuration files](#appsec-configuration) to use as definition of what rules to apply and how.
2626

27-
Details can be found in the [AppSec Datasource page](/log_processor/data_sources/apps).
27+
Details can be found in the [AppSec Datasource page](/log_processor/data_sources/appsec.md).
2828

2929
### Defining Multiple AppSec Configurations
3030

crowdsec-docs/docs/appsec/quickstart/traefik.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Additionally, we'll show how to monitor these alerts through the [console](https
2525
- Traefik Plugin **[Remediation Component](/u/bouncers/intro)**: Thanks to [maxlerebourg](https://github.com/maxlerebourg) and team they created a [Traefik Plugin](https://plugins.traefik.io/plugins/6335346ca4caa9ddeffda116/crowdsec-bouncer-traefik-plugin) that allows you to block requests directly from Traefik.
2626

2727
:::info
28-
Prior to starting the guide ensure you are using the [Traefik Plugin](https://plugins.traefik.io/plugins/6335346ca4caa9ddeffda116/crowdsec-bouncer-traefik-plugin) and **NOT** the older [traefik-crowdsec-bouncer](https://app.crowdsec.net/hub/author/fbonalair/remediation-components/traefik-crowdsec-bouncer) as it hasnt recieved updates to use the new AppSec Component.
28+
Prior to starting the guide ensure you are using the [Traefik Plugin](https://plugins.traefik.io/plugins/6335346ca4caa9ddeffda116/crowdsec-bouncer-traefik-plugin) and **NOT** the older [traefik-crowdsec-bouncer](https://app.crowdsec.net/hub/author/fbonalair/remediation-components/traefik-crowdsec-bouncer) as it hasnt received updates to use the new AppSec Component.
2929
:::
3030

3131
:::warning
@@ -77,7 +77,7 @@ If you have a folder in which you are persisting the configuration files, you ca
7777
There steps will change depending on how you are running the Security Engine. If you are running via `docker run` then you should launch the container within the same directory as the `appsec.yaml` file. If you are using `docker-compose` you can use a relative file mount to mount the `appsec.yaml` file.
7878

7979
Steps:
80-
1. Change to the location where you exectued the `docker run` or `docker compose` command.
80+
1. Change to the location where you executed the `docker run` or `docker compose` command.
8181
2. Create a `appsec.yaml` file at the base of the directory.
8282
3. Add the following content to the `appsec.yaml` file.
8383

@@ -96,11 +96,11 @@ Since CrowdSec is running inside a container you must set the `listen_addr` to `
9696

9797
<FormattedTabs
9898
docker={`# Note if you have a docker run already running you will need to stop it before running this command
99-
docker run -d --name crowdsec -v /path/to/orginal:/etc/crowdsec -v ./appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml crowdsecurity/crowdsec`}
99+
docker run -d --name crowdsec -v /path/to/original:/etc/crowdsec -v ./appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml crowdsecurity/crowdsec`}
100100
dockerCompose={`services:
101101
crowdsec:
102102
volumes:
103-
- /path/to/orginal:/etc/crowdsec ## or named volumes
103+
- /path/to/original:/etc/crowdsec ## or named volumes
104104
- ./appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml`}
105105
/>
106106

crowdsec-docs/docs/getting_started/crowdsec_tour.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Those metrics are a great way to know if your configuration is correct:
250250
The `Acquisition Metrics` is a great way to know if your parsers are setup correctly:
251251

252252
- If you have 0 **LINES PARSED** for a source : You are probably *missing* a parser, or you have a custom log format that prevents the parser from understanding your logs.
253-
- However, it's perfectly OK to have a lot of **LINES UNPARSED** : Crowdsec is not a SIEM, and only parses the logs that are relevant to its scenarios. For example, [ssh parser](https://hub.crowdsec.net/author/crowdsecurity/configurations/sshd-logs), only cares about failed authentication events (at the time of writting).
253+
- However, it's perfectly OK to have a lot of **LINES UNPARSED** : Crowdsec is not a SIEM, and only parses the logs that are relevant to its scenarios. For example, [ssh parser](https://hub.crowdsec.net/author/crowdsecurity/configurations/sshd-logs), only cares about failed authentication events (at the time of writing).
254254
- **LINES POURED TO BUCKET** tell you that your scenarios are matching your log sources : it means that some events from this log source made all their way to an actual scenario
255255

256256

crowdsec-docs/docs/log_processor/data_sources/introduction.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
---
22
id: intro
3-
title: Acquisition Datasources Introduction
3+
title: Acquisition Datasources
44
sidebar_position: 1
55
---
66

7-
## Datasources
7+
To monitor applications, the Security Engine needs to read logs.
8+
DataSources define where to access them (either as files, or over the network from a centralized logging service).
89

9-
To be able to monitor applications, the Security Engine needs to access logs.
10-
DataSources are configured via the [acquisition](/configuration/crowdsec_configuration.md#acquisition_path) configuration, or specified via the command-line when performing cold logs analysis.
10+
They can be defined:
1111

12+
- in [Acquisition files](/configuration/crowdsec_configuration.md#acquisition_path). Each file can contain multiple DataSource definitions. This configuration can be generated automatically, please refer to the [Service Discovery documentation](/log_processor/service-discovery-setup/intro.md)
13+
- for cold log analysis, you can also specify acquisitions via the command line.
14+
15+
16+
## Datasources modules
1217

1318
Name | Type | Stream | One-shot
1419
-----|------|--------|----------
1520
[Appsec](/log_processor/data_sources/appsec.md) | expose HTTP service for the Appsec component | yes | no
1621
[AWS cloudwatch](/log_processor/data_sources/cloudwatch.md) | single stream or log group | yes | yes
17-
[AWS kinesis](/log_processor/data_sources/kinesis.md)| read logs from a kinesis strean | yes | no
22+
[AWS kinesis](/log_processor/data_sources/kinesis.md)| read logs from a kinesis stream | yes | no
1823
[AWS S3](/log_processor/data_sources/s3.md)| read logs from a S3 bucket | yes | yes
1924
[docker](/log_processor/data_sources/docker.md) | read logs from docker containers | yes | yes
2025
[file](/log_processor/data_sources/file.md) | single files, glob expressions and .gz files | yes | yes
@@ -46,6 +51,7 @@ An expression that will run after the acquisition has read one line, and before
4651
It allows to modify an event (or generate multiple events from one line) before parsing.
4752

4853
For example, if you acquire logs from a file containing a JSON object on each line, and each object has a `Records` array with multiple events, you can use the following to generate one event per entry in the array:
54+
4955
```
5056
map(JsonExtractSlice(evt.Line.Raw, "Records"), ToJsonString(#))
5157
```
@@ -62,39 +68,47 @@ By default, when reading logs in real-time, crowdsec will use the time at which
6268

6369
Setting this option to `true` will force crowdsec to use the timestamp from the log as the time of the event.
6470

65-
It is mandatory to set this if your application buffers logs before writting them (for example, IIS when writing to a log file, or logs written to S3 from almost any AWS service).<br/>
71+
It is mandatory to set this if your application buffers logs before writing them (for example, IIS when writing to a log file, or logs written to S3 from almost any AWS service).<br/>
6672
If not set, then crowdsec will think all logs happened at once, which can lead to some false positive detections.
6773

6874
### `labels`
6975

7076
A map of labels to add to the event.
7177
The `type` label is mandatory, and used by the Security Engine to choose which parser to use.
7278

73-
## Acquisition configuration example
79+
## Acquisition configuration examples
7480

75-
```yaml title="/etc/crowdsec/acquis.yaml"
81+
```yaml title="/etc/crowdsec/acquis.d/nginx.yaml"
7682
filenames:
7783
- /var/log/nginx/*.log
7884
labels:
7985
type: nginx
80-
---
86+
```
87+
88+
```yaml title="/etc/crowdsec/acquis.d/linux.yaml"
8189
filenames:
8290
- /var/log/auth.log
8391
- /var/log/syslog
8492
labels:
8593
type: syslog
86-
---
94+
```
95+
96+
```yaml title="/etc/crowdsec/acquis.d/docker.yaml"
8797
source: docker
8898
container_name_regexp:
8999
- .*caddy*
90100
labels:
91101
type: caddy
92102
---
93-
...
103+
source: docker
104+
container_name_regexp:
105+
- .*nginx*
106+
labels:
107+
type: nginx
94108
```
95109
96110
:::warning
97111
The `labels` and `type` fields are necessary to dispatch the log lines to the right parser.
98112

99-
Also note between each datasource is `---` this is needed to separate multiple YAML documents (each datasource) in a single file.
113+
In the last example we defined multiple datasources separated by the line `---`, which is the standard YAML marker.
100114
:::

crowdsec-docs/docs/log_processor/data_sources/syslog_service.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ This module does not support command-line acquisition.
5151

5252
:::warning
5353
This syslog datasource is currently intended for small setups, and is at risk of losing messages over a few hundreds events/second.
54-
To process significant amounts of logs, rely on dedicated syslog server such as [rsyslog](https://www.rsyslog.com/), with this server writting logs to files that Security Engine will read from.
54+
To process significant amounts of logs, rely on dedicated syslog server such as [rsyslog](https://www.rsyslog.com/), with this server writing logs to files that Security Engine will read from.
5555
This page will be updated with further improvements of this data source.
56-
:::
56+
:::

crowdsec-docs/docs/log_processor/data_sources/troubleshoot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_position: 10
55
---
66

77
The [prometheus](/observability/prometheus.md) instrumentation exposes metrics about acquisition and data sources.
8-
Those can as well be view via `cscli metrics` :
8+
Those can as well be viewed via `cscli metrics` :
99

1010
```bash
1111
INFO[19-08-2021 06:33:31 PM] Acquisition Metrics:

crowdsec-docs/docs/log_processor/intro.mdx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ title: Introduction
44
sidebar_position: 1
55
---
66

7-
The Log Processor is one of the core component of the Security Engine to:
7+
The Log Processor is a core component of the Security Engine. It:
88

9-
- Read logs from [Data Sources](log_processor/data_sources/introduction.md) in the form of Acquistions.
10-
- Parse the logs and extract relevant information using [Parsers](log_processor/parsers/introduction.mdx).
11-
- Enrich the parsed information with additional context such as GEOIP, ASN using [Enrichers](log_processor/parsers/enricher.md).
12-
- Monitor the logs for patterns of interest known as [Scenarios](log_processor/scenarios/introduction.mdx).
13-
- Push alerts to the Local API (LAPI) for alert/decisions to be stored within the database.
14-
15-
!TODO: Add diagram of the log processor pipeline
9+
- Reads logs from [Data Sources](log_processor/data_sources/introduction.md) via Acquistions.
10+
- Parses logs and extract relevant information using [Parsers](log_processor/parsers/introduction.mdx).
11+
- Enriches the parsed information with additional context such as GEOIP, ASN using [Enrichers](log_processor/parsers/enricher.md).
12+
- Monitors patterns of interest via [Scenarios](log_processor/scenarios/introduction.mdx).
13+
- Pushes alerts to the Local API (LAPI), where alert/decisions are stored.
1614
- Read logs from datasources
1715
- Parse the logs
1816
- Enrich the parsed information
1917
- Monitor the logs for patterns of interest
2018

19+
<!-- !TODO: Add diagram of the log processor pipeline -->
2120

22-
## Introduction
21+
## Log Processor
2322

24-
The Log Processor is an internal core component of the Security Engine in charge of reading logs from Data Sources, parsing them, enriching them, and monitoring them for patterns of interest.
23+
The Log Processor reads logs from Data Sources, parses and enriches them, and monitors them for patterns of interest.
2524

2625
Once a pattern of interest is detected, the Log Processor will push alerts to the Local API (LAPI) for alert/decisions to be stored within the database.
2726

@@ -35,19 +34,19 @@ Data Sources are individual modules that can be loaded at runtime by the Log Pro
3534

3635
Acquisitions are the configuration files that define how the Log Processor should read logs from a Data Source. Acquisitions are defined in YAML format and are loaded by the Log Processor at runtime.
3736

38-
We have two ways to define Acquisitions within the [configuration directory](/u/troubleshooting/security_engine#where-is-configuration-stored) :
37+
We support two ways to define Acquisitions in the [configuration directory](/u/troubleshooting/security_engine#where-is-configuration-stored):
3938

40-
- `acquis.yaml` file: This used to be only place to define Acquisitions prior to `1.5.0`. This file is still supported for backward compatibility.
41-
- `acquis.d` folder: This is a directory where you can define multiple Acquisitions in separate files. This is useful when you want to auto generate files using an external application such as ansible.
39+
- `acquis.yaml` file: the legacy, single-file configuration (still supported)
40+
- `acquis.d` directory: a directory of multiple acquisition files (since v1.5.0, recommended for any non-trivial setup)
4241

4342
```yaml title="Example Acquisition Configuration"
4443
## /etc/crowdsec/acquis.d/file.yaml
4544
source: file ## The Data Source module to use
4645
filenames:
47-
- /tmp/foo/*.log
48-
- /var/log/syslog
46+
- /tmp/foo/*.log
47+
- /var/log/syslog
4948
labels:
50-
type: syslog
49+
type: syslog
5150
```
5251

5352
For more information on Data Sources and Acquisitions, see the [Data Sources](log_processor/data_sources/introduction.md) documentation.
@@ -87,3 +86,9 @@ You can see more information on Whitelists in the [documentation](log_processor/
8786
Alert Context is additional context that can sent with an alert to the LAPI. This context can be shown locally via `cscli` or within the [CrowdSec Console](https://app.crowdsec.net/signup) if you opt in to share context when you enroll your instance.
8887

8988
You can read more about Alert Context in the [documentation](log_processor/alert_context/intro.md).
89+
90+
### Service Discovery & Setup
91+
92+
On installation, CrowdSec can automatically detect existing services, download the relevant Hub collections, and generate acquisitions based on discovered log files.
93+
94+
You can [customize or override these steps](log_processor/service-discovery-setup/intro.md), for example when provisioning multiple systems or using configuration management tools.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
id: detect-yaml
3+
title: Syntax
4+
sidebar_position: 1
5+
---
6+
7+
# Syntax
8+
9+
A minimal detection file is a YAML map with a top‐level `detect:` key.
10+
11+
Under it, each entry describes one service plan:
12+
13+
```yaml
14+
# detect.yaml
15+
---
16+
detect:
17+
apache2-file-apache2:
18+
when:
19+
- Systemd.UnitInstalled("apache2.service") or len(Path.Glob("/var/log/apache2/*.log")) > 0
20+
hub_spec:
21+
collections:
22+
- crowdsecurity/apache2
23+
acquisition_spec:
24+
filename: apache2.yaml
25+
datasource:
26+
source: file
27+
filenames:
28+
- /var/log/apache2/*.log
29+
labels:
30+
type: apache2
31+
```
32+
33+
## Fields
34+
35+
### `when`
36+
37+
A list of expression that must return a boolean.
38+
39+
If multiple expressions are provided, they must all return `true` for the service to be included.
40+
41+
```yaml
42+
when:
43+
- Host.OS == "linux"
44+
- Systemd.UnitInstalled("<unit>")
45+
```
46+
47+
You can use any of the helper referenced [here](/log_processor/service-discovery-setup/expr.md).
48+
49+
### `hub_spec`
50+
51+
A map of hub items to install.
52+
53+
Specifying an invalid item type or item will log an error but will not prevent the detection to continue.
54+
55+
```yaml
56+
hub_spec:
57+
collections:
58+
- crowdsecurity/linux
59+
parsers:
60+
- crowdsecurity/nginx-logs
61+
scenarios:
62+
- crowdsecurity/http-bf
63+
```
64+
65+
### `acquisition_spec`
66+
67+
This item defines the acquisition that will be written to disk
68+
69+
```yaml
70+
acquisition_spec:
71+
filename: foobar.yaml
72+
datasource:
73+
source: docker
74+
container_name: foo
75+
labels:
76+
type: bar
77+
```
78+
79+
The `filename` attribute will be used to generate the name of file in the form of `acquis.d/setup.<filename>.yaml`.
80+
81+
The content of `datasource` will be validated (syntax, required fields depending on the datasource configured) and be written as-is to the file.
82+
83+
## Examples
84+
85+
Basic OS / Hub only:
86+
87+
```yaml
88+
detect:
89+
linux:
90+
when:
91+
- Host.OS == "linux"
92+
hub_spec:
93+
collections:
94+
- crowdsecurity/linux
95+
```
96+
97+
`journalctl` source with a filter:
98+
99+
```yaml
100+
detect:
101+
caddy-journal:
102+
when:
103+
- Systemd.UnitInstalled("caddy.service")
104+
- len(Path.Glob("/var/log/caddy/*.log")) == 0
105+
hub_spec:
106+
collections:
107+
- crowdsecurity/caddy
108+
acquisition_spec:
109+
filename: caddy.yaml
110+
datasource:
111+
source: journalctl
112+
labels:
113+
type: caddy
114+
journalctl_filter:
115+
- "_SYSTEMD_UNIT=caddy.service"
116+
```
117+
118+
Windows event log:
119+
120+
```yaml
121+
detect:
122+
windows_auth:
123+
when:
124+
- Host.OS == "windows"
125+
hub_spec:
126+
collections:
127+
- crowdsecurity/windows
128+
acquisition_spec:
129+
filename: windows_auth.yaml
130+
datasource:
131+
source: wineventlog
132+
event_channel: Security
133+
event_ids:
134+
- 4625
135+
- 4623
136+
event_level: information
137+
labels:
138+
type: eventlog
139+
```

0 commit comments

Comments
 (0)