Skip to content

Commit 17a433a

Browse files
committed
fix traefik doc
1 parent 182e094 commit 17a433a

File tree

1 file changed

+58
-132
lines changed

1 file changed

+58
-132
lines changed

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

Lines changed: 58 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import TabItem from '@theme/TabItem';
1111

1212
## Objectives
1313

14-
This quickstart walks you through pairing the CrowdSec [AppSec
15-
Component](/appsec/intro.md#introduction) with the Traefik reverse proxy across
16-
three deployment models: a single Docker container, a Docker Compose stack, and
17-
the official Helm chart on Kubernetes. You'll install the required AppSec
18-
collections, configure the acquisition endpoint that exposes the inspection
19-
service, and wire the Traefik plugin so requests are evaluated before reaching
20-
your applications. We'll finish by pointing you to the Stack health check so you
21-
can validate the bouncer and AppSec stack end to end.
14+
The goal of this quickstart is to set up the [AppSec
15+
Component](/appsec/intro.md#introduction) to safeguard web applications running
16+
on [Traefik](https://doc.traefik.io/traefik/) reverse proxy. We'll deploy a [set
17+
of
18+
rules](https://app.crowdsec.net/hub/author/crowdsecurity/collections/appsec-virtual-patching)
19+
designed to block [well-known
20+
attacks](https://app.crowdsec.net/hub/author/crowdsecurity/collections/appsec-generic-rules)
21+
and [currently exploited
22+
vulnerabilities](https://app.crowdsec.net/hub/author/crowdsecurity/collections/appsec-virtual-patching).
23+
Additionally, we'll show how to monitor these alerts through the
24+
[console](https://app.crowdsec.net/).
2225

2326
## Pre-requisites
2427

@@ -178,51 +181,9 @@ In the directory where you persist configuration files, create an `appsec.yaml`
178181

179182
**Steps**
180183

181-
<<<<<<< HEAD
182-
Create a file named `appsec.yaml` with the following content
183-
184-
```yaml title="appsec.yaml"
185-
appsec_config: crowdsecurity/appsec-desfault
186-
labels:
187-
type: appsec
188-
listen_addr: 0.0.0.0:7422
189-
source: appsec
190-
```
191-
192-
You can either create the file under /etc/crowdsec/acquis.d, following [the
193-
existing directory structure](/u/getting_started/installation/docker#docker) in
194-
which case the run command remains unchanged, or you can create the file
195-
elsewhere and mount it using the following method:
196-
197-
198-
```bash
199-
docker run -d --name crowdsec \
200-
-v /etc/crowdsec:/etc/crowdsec \
201-
-v /elsewhere/appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml \
202-
crowdsecurity/crowdsec
203-
```
204-
205-
206-
Because CrowdSec runs inside a container, set listen_addr to 0.0.0.0 instead of
207-
127.0.0.1 so it can accept connections from outside the container.
208-
209-
If a crowdsec container is already running, stop/remove it before re-running
210-
with the updated acquisition.
211-
212-
213-
</TabItem>
214-
215-
<TabItem value="dockerCompose">
216-
217-
In the directory where you store CrowdSec configuration files (for example,
218-
`./crowdsec/acquis.d`, if you’re following the [recommended directory
219-
structure](/u/getting_started/installation/docker#compose), create a file named
220-
appsec.yaml and mount it into the container.
221-
=======
222184
1. Change to the directory where you ran the `docker run` or `docker compose` command.
223185
2. Create a file named `appsec.yaml` in this directory.
224186
3. Add the following content:
225-
>>>>>>> 24c582de (add traefik for kubernetes)
226187

227188
```yaml title="appsec.yaml"
228189
appsec_config: crowdsecurity/appsec-desfault
@@ -232,12 +193,6 @@ listen_addr: 0.0.0.0:7422
232193
source: appsec
233194
```
234195

235-
<<<<<<< HEAD
236-
Since CrowdSec runs inside a container, make sure to set listen_addr to 0.0.0.0
237-
(instead of 127.0.0.1) so it listens on the container’s network interface.
238-
239-
Then, update your Docker Compose service to mount the file:
240-
=======
241196
Because CrowdSec runs inside a container, set listen_addr to 0.0.0.0 instead of
242197
127.0.0.1 so it can accept connections from outside the container.
243198

@@ -273,21 +228,12 @@ source: appsec
273228
Because CrowdSec runs in a container, set listen_addr to 0.0.0.0 (not 127.0.0.1) so it listens on the container’s network interface.
274229

275230
Mount the file in your Compose service:
276-
>>>>>>> 24c582de (add traefik for kubernetes)
277231
```
278232
services:
279233
crowdsec:
280234
volumes:
281-
<<<<<<< HEAD
282-
- ./crowdsec/acquis.yaml:/etc/crowdsec/acquis.yaml
283-
- logs:/var/log/nginx
284-
- crowdsec-db:/var/lib/crowdsec/data/
285-
- crowdsec-config:/etc/crowdsec/
286-
- ./crowdsec/acquis.d/appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml
287-
=======
288235
- /path/to/original:/etc/crowdsec # or a named volume
289236
- ./appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml
290-
>>>>>>> 24c582de (add traefik for kubernetes)
291237
```
292238

293239
Once you have updated the compose file to include the volume mount and the updated environment variable, you can restart the container.
@@ -408,21 +354,16 @@ spec:
408354
crowdsecLapiHost: crowdsec-service.crowdsec.svc.cluster.local:8080
409355
crowdsecLapiKey: <shadowed>
410356
htttTimeoutSeconds: 60
411-
<<<<<<< HEAD
412-
=======
413357
forwardedheaderstrustedips:
414358
- 10.0.0.0/8
415359
- 192.168.0.0/16
416360
- 134.209.137.94
417361
- 2a03:b0c0:2:f0::f557:a001
418-
>>>>>>> 24c582de (add traefik for kubernetes)
419362
crowdsecAppsecEnabled: false
420363
crowdsecAppsecHost: crowdsec:7422
421364
crowdsecAppsecFailureBlock: true
422365
crowdsecAppsecUnreachableBlock: true
423366
```
424-
<<<<<<< HEAD
425-
=======
426367
427368
You can still add some route configuration through
428369
[IngressRoute](https://doc.traefik.io/traefik/reference/routing-configuration/kubernetes/crd/http/ingressroute/?utm_source=chatgpt.com)
@@ -433,64 +374,8 @@ and attach the middleware to those routes.
433374
For more comprehensive documentation on the Traefik Plugin configuration, please
434375
refer to the [official
435376
documentation](https://plugins.traefik.io/plugins/6335346ca4caa9ddeffda116/crowdsec-bouncer-traefik-plugin).
436-
>>>>>>> 24c582de (add traefik for kubernetes)
437377
438-
You can still add some route configuration through
439-
[IngressRoute](https://doc.traefik.io/traefik/reference/routing-configuration/kubernetes/crd/http/ingressroute)
440-
and attach the middleware to those routes.
441-
442-
</TabItem>
443-
</Tabs>
444-
445-
For more comprehensive documentation on the Traefik Plugin configuration, please
446-
refer to the [official
447-
documentation](https://plugins.traefik.io/plugins/6335346ca4caa9ddeffda116/crowdsec-bouncer-traefik-plugin).
448-
449-
<details>
450-
<summary>The traefik configuration for testing this quickstart guide has been done with the following values.yaml</summary>
451-
```yaml title="values.yaml"
452-
deployment:
453-
kind: DaemonSet # run on each node so a sidecar crowdsec can tail Traefik logs
454-
455-
service:
456-
type: LoadBalancer # expose Traefik entrypoints through your cloud LB
457-
annotations:
458-
service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true" # forward client IPs via DigitalOcean proxy protocol
459-
spec:
460-
externalTrafficPolicy: Local # keep original source IPs for CrowdSec decisions
461-
462-
# Make Traefik actually write a file that can be parsed
463-
logs:
464-
access:
465-
enabled: true # ensure access logs are produced
466-
format: json # structured logs expected by the bouncer parser
467-
fields:
468-
defaultMode: keep
469-
names:
470-
ServiceName: keep # keep service name for troubleshooting
471-
general:
472-
level: INFO # avoid noisy debug output in production
473-
format: json # align general logs with access log format
474-
475-
# Proxy Protocol needs “enabled”, not only trustedIPs
476-
additionalArguments:
477-
- --accesslog=true # double-check logging stays on even if values drift
478-
- --accesslog.format=json # enforce JSON formatting at the CLI level
479-
- --entrypoints.web.proxyProtocol=true # enable Proxy Protocol on the HTTP entrypoint
480-
- --entrypoints.websecure.proxyProtocol=true # enable Proxy Protocol on the HTTPS entrypoint
481-
- --entrypoints.web.proxyProtocol.trustedIPs=10.0.0.0/8,192.168.0.0/16 # trust proxy headers from your internal ranges
482-
- --entrypoints.websecure.proxyProtocol.trustedIPs=10.0.0.0/8,192.168.0.0/16 # same trust list for HTTPS
483-
- --providers.kubernetesingress # watch standard Ingress resources
484-
- --providers.kubernetescrd # watch Traefik CRD resources
485-
486-
# Traefik middleware configuration
487-
experimental:
488-
plugins:
489-
crowdsec-bouncer-traefik-plugin:
490-
moduleName: "github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
491-
version: "v1.4.5" # pin plugin release for deterministic behaviour
492-
```
493-
</details>
378+
We can't cover all the possible configurations for Traefik in this guide, so please refer to the [official documentation](https://doc.traefik.io/traefik/) for more information.
494379
495380
### Directives
496381
@@ -516,11 +401,51 @@ If the AppSec Component returns `500` status code should the request be blocked.
516401

517402
If the AppSec Component is unreachable should the request be blocked.
518403

519-
## Validate the stack
404+
## Testing the AppSec Component + Remediation Component
405+
406+
:::note
407+
We're assuming the web server is installed on the same machine and is listening on port 80. Please adjust your testing accordingly if this is not the case.
408+
:::
409+
410+
if you try to access `http://localhost/.env` from a browser, your request will be blocked, resulting in the display of the following HTML page:
411+
412+
![appsec-denied](/img/appsec_denied.png)
413+
414+
We can also look at the metrics from `cscli metrics show appsec` it will display:
415+
- the number of requests processed by the AppSec Component
416+
- Individual rule matches
417+
418+
<details>
419+
<summary>Example Output</summary>
420+
421+
```bash title="sudo cscli metrics show appsec"
422+
Appsec Metrics:
423+
╭─────────────────┬───────────┬─────────╮
424+
│ Appsec Engine │ Processed │ Blocked │
425+
├─────────────────┼───────────┼─────────┤
426+
│ 127.0.0.1:7422/ │ 2 │ 1 │
427+
╰─────────────────┴───────────┴─────────╯
428+
429+
Appsec '127.0.0.1:7422/' Rules Metrics:
430+
╭─────────────────────────────────┬───────────╮
431+
│ Rule ID │ Triggered │
432+
├─────────────────────────────────┼───────────┤
433+
│ crowdsecurity/vpatch-env-access │ 1 │
434+
╰─────────────────────────────────┴───────────╯
435+
```
436+
437+
</details>
438+
439+
### Explanation
440+
441+
What happened in the test that we just did is:
520442

521-
Follow the [Stack health check](/u/getting_started/health_check) to confirm the
522-
CrowdSec engine, AppSec Component, and Traefik bouncer are working together as
523-
expected.
443+
1. We did a request (`localhost/.env`) to our local webserver
444+
2. Thanks to the Remediation Component configuration, forwarded the request to `http://127.0.0.1:7422`
445+
3. Our AppSec Component, listening on `http://127.0.0.1:7422` analyzed the request
446+
4. The request matches the [AppSec rule to detect .env access](https://app.crowdsec.net/hub/author/crowdsecurity/appsec-rules/vpatch-env-access)
447+
5. The AppSec Component thus answered with [HTTP 403](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403) to the Remediation Component, indicating that the request must be blocked
448+
6. The web server then presented us with the default "request blocked" page.
524449

525450
## Integration with the console
526451

@@ -535,5 +460,6 @@ Once done, all your alerts, including the ones generated by the AppSec Component
535460
You are now running the AppSec Component on your Crowdsec Security Engine, congrats!
536461

537462
As the next steps, you can:
463+
- [Explore the hub](https://hub.crowdsec.net) to find more rules for your use case
538464
- Look at the [Rules syntax](/appsec/rules_syntax.md) and [creation process](/appsec/create_rules.md) to create your own and contribute
539-
- Learn more about AppSec’s advanced capabilities in [Advanced WAF Deployments](/docs/next/appsec/advanced_deployments/)
465+
- Take a look at [the benchmarks](/appsec/benchmark.md)

0 commit comments

Comments
 (0)