Skip to content

Commit 5a2889a

Browse files
committed
some more improvements
1 parent 3676b9e commit 5a2889a

2 files changed

Lines changed: 88 additions & 36 deletions

File tree

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ http:
325325
crowdsecAppsecHost: crowdsec:7422
326326
crowdsecAppsecFailureBlock: true
327327
crowdsecAppsecUnreachableBlock: true
328-
crowdsecLapiKey: privateKey-foo
328+
crowdsecLapiKey: <your-shared-traefik-bouncer-key>
329329
```
330330
331331
@@ -336,11 +336,30 @@ Instead if you define the configuration using labels on the containers you can a
336336
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.enabled=true"
337337
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecAppsecEnabled=true"
338338
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecAppsecHost=crowdsec:7422"
339-
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecLapiKey=privateKey-foo"
339+
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecLapiKey=<your-shared-traefik-bouncer-key>"
340340
```
341341
</TabItem>
342342
<TabItem value="kubernetes">
343-
Here's a Traefik Middleware ressource you can apply with
343+
For Kubernetes, keep the Traefik bouncer key in a `Secret`, mount it into the
344+
Traefik pod, and reference it with `crowdsecLapiKeyFile`.
345+
346+
Use a Traefik values file like this:
347+
348+
```yaml title="traefik-values.yaml"
349+
experimental:
350+
plugins:
351+
bouncer:
352+
moduleName: github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin
353+
version: v1.4.5
354+
volumes:
355+
- name: crowdsec-bouncer-key
356+
mountPath: /etc/traefik/crowdsec
357+
type: secret
358+
secretName: crowdsec-bouncer-key
359+
```
360+
361+
Then create a Traefik Middleware resource:
362+
344363
```bash
345364
kubectl apply -f traefik-middleware.yaml
346365
```
@@ -358,7 +377,7 @@ spec:
358377
crowdsecMode: stream
359378
crowdsecLapiScheme: http
360379
crowdsecLapiHost: crowdsec-service.crowdsec.svc.cluster.local:8080
361-
crowdsecLapiKey: <shadowed>
380+
crowdsecLapiKeyFile: /etc/traefik/crowdsec/BOUNCER_KEY_traefik
362381
htttTimeoutSeconds: 60
363382
forwardedheaderstrustedips:
364383
- 10.0.0.0/8
@@ -371,6 +390,37 @@ spec:
371390
crowdsecAppsecUnreachableBlock: true
372391
```
373392

393+
<details>
394+
<summary>Show direct <code>crowdsecLapiKey</code> example</summary>
395+
396+
```yaml values="traefik-middleware.yaml"
397+
apiVersion: traefik.io/v1alpha1
398+
kind: Middleware
399+
metadata:
400+
name: crowdsec
401+
namespace: traefik
402+
spec:
403+
plugin:
404+
crowdsec-bouncer-traefik-plugin:
405+
enabled: true
406+
crowdsecMode: stream
407+
crowdsecLapiScheme: http
408+
crowdsecLapiHost: crowdsec-service.crowdsec.svc.cluster.local:8080
409+
crowdsecLapiKey: <your-shared-traefik-bouncer-key>
410+
htttTimeoutSeconds: 60
411+
forwardedheaderstrustedips:
412+
- 10.0.0.0/8
413+
- 192.168.0.0/16
414+
- 134.209.137.94
415+
- 2a03:b0c0:2:f0::f557:a001
416+
crowdsecAppsecEnabled: false
417+
crowdsecAppsecHost: crowdsec:7422
418+
crowdsecAppsecFailureBlock: true
419+
crowdsecAppsecUnreachableBlock: true
420+
```
421+
422+
</details>
423+
374424
You can still add some route configuration through
375425
[IngressRoute](https://doc.traefik.io/traefik/reference/routing-configuration/kubernetes/crd/http/ingressroute/)
376426
and attach the middleware to those routes.

crowdsec-docs/unversioned/bouncers/traefik.mdx

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ import RemediationSupportBadges from "@site/src/components/remediation-support-b
3333

3434
<RemediationSupportBadges Prometheus MTLS />
3535

36-
# CrowdSec Remediation QuickStart for Traefik
36+
:::tip AppSec Support
37+
This bouncer supports the [AppSec Component](/docs/next/appsec/intro) for
38+
real-time WAF protection. Enable `crowdsecAppsecEnabled: true` in your
39+
middleware configuration to get virtual patching and defense against known
40+
CVEs, SQL injection, XSS, and other application-layer attacks.
41+
42+
For a full walkthrough, see the
43+
[AppSec Quickstart for Traefik](/docs/next/appsec/quickstart/traefik).
44+
:::
45+
46+
# Traefik on kubernetes
3747

3848
## Objectives
3949

@@ -49,25 +59,16 @@ At the end, you will have:
4959
- The bouncer key mounted into the Traefik pod as a file
5060
- An operational pattern that avoids committing the LAPI key in plaintext
5161

52-
:::tip AppSec Support
53-
This bouncer supports the [AppSec Component](/docs/next/appsec/intro) for
54-
real-time WAF protection. Enable `crowdsecAppsecEnabled: true` in your
55-
middleware configuration to get virtual patching and defense against known
56-
CVEs, SQL injection, XSS, and other application-layer attacks.
57-
58-
For a full walkthrough, see the
59-
[AppSec Quickstart for Traefik](/docs/next/appsec/quickstart/traefik).
60-
:::
61-
6262
## Prerequisites
6363

64-
1. It is assumed that you already have:
65-
- A working CrowdSec [Security Engine](/intro.mdx) installation. For a
66-
Kubernetes install quickstart, refer to
67-
[/u/getting_started/installation/kubernetes](/u/getting_started/installation/kubernetes).
68-
- A working Traefik installation in Kubernetes.
69-
- Existing `IngressRoute`, `Ingress`, or other Traefik-managed routes
70-
exposing your applications.
64+
It is assumed that you already have:
65+
66+
- A working CrowdSec [Security Engine](/intro.mdx) installation. For a
67+
Kubernetes install quickstart, refer to
68+
[/u/getting_started/installation/kubernetes](/u/getting_started/installation/kubernetes).
69+
- A working Traefik installation in Kubernetes.
70+
- Existing `IngressRoute`, `Ingress`, or other Traefik-managed routes
71+
exposing your applications.
7172

7273
:::warning
7374
This integration currently relies on a community Traefik plugin, not on a
@@ -76,9 +77,11 @@ first-party CrowdSec remediation component.
7677
The upstream project used in this guide is:
7778

7879
- `maxlerebourg/crowdsec-bouncer-traefik-plugin`
79-
:::
80+
:::
81+
82+
## Required traefik configuration items
8083

81-
### Source IPs
84+
### Traefik configuration's on source IPs
8285

8386
To ensure remediation works correctly, Traefik must receive the real client IP
8487
for each request. When Traefik is deployed behind a load balancer, CDN, or
@@ -127,6 +130,7 @@ consequence, the Service's `externalTrafficPolicy` must be set to `Local`, and
127130
the workload must run either as a `DaemonSet` or as a `Deployment` ensuring one
128131
pod per node. This guarantees that no traffic, and therefore no security
129132
events, is missed.
133+
130134
</details>
131135

132136
### Traefik Custom Resource Definitions
@@ -197,8 +201,8 @@ helm upgrade --install traefik traefik/traefik \
197201

198202
## Store the Traefik bouncer key in a Kubernetes secret
199203

200-
As with the Envoy guide, the practical approach is to choose a fixed key, store
201-
it in a Kubernetes secret, and force `BOUNCER_KEY_traefik` from `lapi.env` with
204+
The practical approach is to choose a fixed key, store it in a Kubernetes
205+
secret, and force `BOUNCER_KEY_traefik` from `lapi.env` with
202206
`valueFrom.secretKeyRef`.
203207

204208
Create or update the secrets used by CrowdSec LAPI and Traefik:
@@ -251,6 +255,9 @@ helm upgrade --install crowdsec crowdsec/crowdsec \
251255
-f crowdsec-values.yaml
252256
```
253257

258+
The second secret of the `crowdsec-keys.yaml` is meant for further use in the
259+
traefik configuration. It will be described later on.
260+
254261
## Verify CrowdSec LAPI access
255262

256263
The Traefik middleware only needs access to CrowdSec LAPI. Make sure the
@@ -276,13 +283,9 @@ To achieve remediation in a Traefik environment, create a `Middleware`
276283
resource.
277284

278285
:::important
279-
Unlike the Envoy bouncer deployment, the Traefik `Middleware` CRD does not have
280-
a native `secretKeyRef` field for the plugin configuration. In Kubernetes, the
281-
recommended pattern is to mount the key from a `Secret` into the Traefik pod and
282-
reference it with `crowdsecLapiKeyFile`.
283-
284-
Avoid committing a middleware manifest with `crowdsecLapiKey:
285-
<real-secret-value>` in Git.
286+
The Traefik `Middleware` CRD does not have a native `secretKeyRef` field for the
287+
plugin configuration. In Kubernetes, the key can be mounted from a `Secret` into
288+
the Traefik pod and reference it with `crowdsecLapiKeyFile`.
286289
:::
287290

288291
Mount the Traefik-side secret into the pod and let the middleware read it from a
@@ -343,8 +346,7 @@ literal key in the middleware manifest.
343346
<details>
344347
<summary>Show direct <code>crowdsecLapiKey</code> example</summary>
345348

346-
If you only need a quick functional test, you can still apply a middleware
347-
manifest with the key inline:
349+
You can apply a middleware manifest with an inline key as well:
348350

349351
```yaml title="bouncer-middleware.yaml"
350352
apiVersion: traefik.io/v1alpha1
@@ -370,7 +372,7 @@ kubectl apply -f bouncer-middleware.yaml
370372
```
371373

372374
This is useful for quick validation, but `crowdsecLapiKeyFile` with a mounted
373-
Kubernetes secret is the recommended approach for production.
375+
Kubernetes secret seems to be a more secure approach.
374376

375377
</details>
376378

0 commit comments

Comments
 (0)