Skip to content

Commit 6b46b46

Browse files
committed
updating for secrets
1 parent 2231e03 commit 6b46b46

3 files changed

Lines changed: 187 additions & 38 deletions

File tree

crowdsec-docs/docs/appsec/quickstart/nginx-ingress.mdx

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ If CrowdSec is already deployed with Helm in this cluster, the repository entry
5858

5959
### Update CrowdSec configuration
6060

61+
Store the nginx bouncer key in a Kubernetes secret, following the same pattern
62+
used by the Envoy quickstart.
63+
64+
Create or update the secret used by CrowdSec LAPI:
65+
66+
```yaml title="crowdsec-keys.yaml"
67+
apiVersion: v1
68+
kind: Secret
69+
metadata:
70+
name: crowdsec-keys
71+
namespace: crowdsec
72+
type: Opaque
73+
stringData:
74+
BOUNCER_KEY_nginx_ingress_waf: "<choose-a-long-random-key>"
75+
```
76+
77+
Apply it:
78+
79+
```bash
80+
kubectl apply -f crowdsec-keys.yaml
81+
```
82+
6183
Add this to the CrowdSec `values.yaml` with the AppSec acquisition datasource (see the [AppSec datasource](/log_processor/data_sources/appsec.md)) and the default [AppSec configuration](/appsec/configuration.md):
6284

6385
```yaml title="values.yaml"
@@ -74,13 +96,20 @@ appsec:
7496
env:
7597
- name: COLLECTIONS
7698
value: crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules
99+
lapi:
100+
env:
101+
- name: BOUNCER_KEY_nginx_ingress_waf
102+
valueFrom:
103+
secretKeyRef:
104+
name: crowdsec-keys
105+
key: BOUNCER_KEY_nginx_ingress_waf
77106
```
78107
79108
This YAML configuration snippet exposes the important configuration items:
80109
* `listen_addr: 0.0.0.0:7422` exposes the AppSec API inside the cluster.
81110
* `appsec_configs` loads the [AppSec configuration(s)](/appsec/configuration.md) that define which rules are evaluated (in-band vs out-of-band).
82111
* The two collections provide virtual patching and generic rule coverage.
83-
* The chart bootstraps a bouncer named `nginx_ingress_waf` using the key you export locally.
112+
* `lapi.env` forces the `nginx_ingress_waf` bouncer key from the `crowdsec-keys` Secret.
84113

85114
And now we apply the new configuration with:
86115

@@ -98,6 +127,26 @@ You should see `crowdsec-agent` pods, the `crowdsec-lapi` pod and the `crowdsec-
98127

99128
## Enable the CrowdSec Lua plugin on NGINX Ingress
100129

130+
Create the secret holding the same CrowdSec bouncer key in the
131+
`ingress-nginx` namespace:
132+
133+
```yaml title="crowdsec-ingress-bouncer-secret.yaml"
134+
apiVersion: v1
135+
kind: Secret
136+
metadata:
137+
name: crowdsec-ingress-bouncer-secrets
138+
namespace: ingress-nginx
139+
type: Opaque
140+
stringData:
141+
api-key: "<same-value-as-BOUNCER_KEY_nginx_ingress_waf>"
142+
```
143+
144+
Apply it:
145+
146+
```bash
147+
kubectl apply -f crowdsec-ingress-bouncer-secret.yaml
148+
```
149+
101150
To extend the ingress controller with the CrowdSec plugin and point it to the
102151
AppSec API, create the file named `ingress-values.yaml`. You can read the entire
103152
file in the snippet below.
@@ -120,7 +169,10 @@ controller:
120169
- name: API_URL
121170
value: "http://crowdsec-service.crowdsec.svc.cluster.local:8080"
122171
- name: API_KEY
123-
value: privateKey-foo
172+
valueFrom:
173+
secretKeyRef:
174+
name: crowdsec-ingress-bouncer-secrets
175+
key: api-key
124176
- name: BOUNCER_CONFIG
125177
value: "/crowdsec/crowdsec-bouncer.conf"
126178
- name: APPSEC_URL
@@ -153,13 +205,13 @@ controller:
153205
plugins: "crowdsec"
154206
lua-shared-dicts: "crowdsec_cache: 50m"
155207
server-snippet: |
156-
lua_ssl_trusted_certificate "/etc/ssl/certs/ca-certificates.crt"
208+
lua_ssl_trusted_certificate "/etc/ssl/certs/ca-certificates.crt";
157209
resolver local=on ipv6=off;
158210
```
159211

160212

161213
- `API_URL` targets the Local API service exposed by the Helm chart.
162-
- `API_KEY` defines the key for the bouncer to be able to connect to CrowdSec LAPI
214+
- `API_KEY` is read from the `crowdsec-ingress-bouncer-secrets` Secret in the `ingress-nginx` namespace.
163215
- `APPSEC_URL` points to the AppSec service; keep the namespace in sync with your CrowdSec release.
164216
- The plugin copies the Lua files from the init container into an `emptyDir` that is mounted at runtime.
165217

@@ -212,7 +264,10 @@ extraInitContainers:
212264
- name: API_URL
213265
value: "http://crowdsec-service.crowdsec.svc.cluster.local:8080"
214266
- name: API_KEY
215-
value: privateKey-foo
267+
valueFrom:
268+
secretKeyRef:
269+
name: crowdsec-ingress-bouncer-secrets
270+
key: api-key
216271
- name: BOUNCER_CONFIG
217272
value: "/crowdsec/crowdsec-bouncer.conf"
218273
- name: APPSEC_URL

crowdsec-docs/unversioned/bouncers/ingress-nginx.mdx

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,59 @@ The Ingress nginx controller should be installed using the [official helm chart]
5757

5858
First you need to create new ingress-nginx chart values file (`crowdsec-ingress-values.yaml`) to upgrade the ingress controller with the crowdsec plugin.
5959

60+
Store the CrowdSec bouncer key in Kubernetes Secrets instead of embedding it
61+
directly in the Helm values.
62+
63+
Create or update the secret used by CrowdSec LAPI:
64+
65+
```yaml title="crowdsec-keys.yaml"
66+
apiVersion: v1
67+
kind: Secret
68+
metadata:
69+
name: crowdsec-keys
70+
namespace: crowdsec
71+
type: Opaque
72+
stringData:
73+
BOUNCER_KEY_nginx_ingress_waf: "<choose-a-long-random-key>"
74+
```
75+
76+
Apply it:
77+
78+
```bash
79+
kubectl apply -f crowdsec-keys.yaml
80+
```
81+
82+
Then reference it from your CrowdSec values:
83+
84+
```yaml title="crowdsec-values.yaml"
85+
lapi:
86+
env:
87+
- name: BOUNCER_KEY_nginx_ingress_waf
88+
valueFrom:
89+
secretKeyRef:
90+
name: crowdsec-keys
91+
key: BOUNCER_KEY_nginx_ingress_waf
92+
```
93+
94+
Create the secret holding the same key in the `ingress-nginx` namespace:
95+
96+
```yaml title="crowdsec-ingress-bouncer-secret.yaml"
97+
apiVersion: v1
98+
kind: Secret
99+
metadata:
100+
name: crowdsec-ingress-bouncer-secrets
101+
namespace: ingress-nginx
102+
type: Opaque
103+
stringData:
104+
api-key: "<same-value-as-BOUNCER_KEY_nginx_ingress_waf>"
105+
```
106+
107+
Apply it:
108+
109+
```bash
110+
kubectl apply -f crowdsec-ingress-bouncer-secret.yaml
111+
```
112+
60113
:::warning
61114

62115
Lua support has been removed from mainline ingress nginx in version 1.12. As
@@ -70,9 +123,9 @@ controller:
70123
PullPolicy: IfNotPresent
71124
image: crowdsecurity/controller
72125
# Crowdsec Remediation with Ingress Nginx requires to use our controller image
73-
tag: v1.13.2
126+
tag: v1.14.3
74127
# If you update the tag, the digest needs to be updated as well
75-
digest: sha256:4575be24781cad35f8e58437db6a3f492df2a3167fed2b6759a6ff0dc3488d56
128+
digest: sha256:9ab8791635f4cde9964ab2562fb8b15faf72fe0205f0fe288089a87e1455675d
76129
registry: docker.io
77130
extraVolumes:
78131
- name: crowdsec-bouncer-plugin
@@ -85,7 +138,10 @@ controller:
85138
- name: API_URL
86139
value: "http://crowdsec-service.crowdsec.svc.cluster.local:8080" # crowdsec lapi service-name
87140
- name: API_KEY
88-
value: "<API KEY>" # generated with `cscli bouncers add <bouncer_name>
141+
valueFrom:
142+
secretKeyRef:
143+
name: crowdsec-ingress-bouncer-secrets
144+
key: api-key
89145
- name: BOUNCER_CONFIG
90146
value: "/crowdsec/crowdsec-bouncer.conf"
91147
- name: CAPTCHA_PROVIDER
@@ -133,36 +189,19 @@ controller:
133189
resolver local=on ipv6=off;
134190
```
135191

136-
<details>
137-
<summary>You already have a deployed ingress nginx</summary>
138-
139-
This values.yaml upgrade your ingress deployment to add crowdsec lua lib as a
140-
plugin and run with the crowdsec maintained nginx ingress controller with lua
141-
support. It uses [this docker
192+
Use this values file to deploy or upgrade ingress-nginx with the CrowdSec Lua
193+
plugin and the CrowdSec-maintained ingress controller image with Lua support.
194+
It uses [this docker
142195
image](https://hub.docker.com/r/crowdsecurity/lua-bouncer-plugin) to copy the
143-
crowdsec lua library. You can upgrade the ingress-nginx using this `crowdsec-ingress-values.yaml`
196+
CrowdSec Lua library.
144197

145198
```bash
146-
helm -n ingress-nginx upgrade -f ingress-nginx-values.yaml -f crowdsec-ingress-values.yaml ingress-nginx/ingress-nginx
199+
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \
200+
-n ingress-nginx \
201+
--create-namespace \
202+
-f crowdsec-ingress-values.yaml
147203
```
148204

149-
</details>
150-
151-
<details>
152-
<summary>You don't have a deployed ingress nginx</summary>
153-
154-
This values.yaml install your ingress deployment to add crowdsec lua lib as a
155-
plugin and run with the crowdsec maintained nginx ingress controller with lua
156-
support. It uses [this docker
157-
image](https://hub.docker.com/r/crowdsecurity/lua-bouncer-plugin) to copy the
158-
crowdsec lua library. You can install the ingress-nginx using this `crowdsec-ingress-values.yaml`
159-
160-
```bash
161-
helm -n ingress-nginx install -f crowdsec-ingress-values.yaml ingress-nginx ingress-nginx/ingress-nginx
162-
```
163-
164-
</details>
165-
166205
And then check if the ingress controller is running well.
167206

168207
```bash

crowdsec-docs/versioned_docs/version-v1.7/appsec/quickstart/nginx-ingress.mdx

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ If CrowdSec is already deployed with Helm in this cluster, the repository entry
5858

5959
### Update CrowdSec configuration
6060

61+
Store the nginx bouncer key in a Kubernetes secret, following the same pattern
62+
used by the Envoy quickstart.
63+
64+
Create or update the secret used by CrowdSec LAPI:
65+
66+
```yaml title="crowdsec-keys.yaml"
67+
apiVersion: v1
68+
kind: Secret
69+
metadata:
70+
name: crowdsec-keys
71+
namespace: crowdsec
72+
type: Opaque
73+
stringData:
74+
BOUNCER_KEY_nginx_ingress_waf: "<choose-a-long-random-key>"
75+
```
76+
77+
Apply it:
78+
79+
```bash
80+
kubectl apply -f crowdsec-keys.yaml
81+
```
82+
6183
Add this to the CrowdSec `values.yaml` with the AppSec acquisition datasource (see the [AppSec datasource](/log_processor/data_sources/appsec.md)) and the default [AppSec configuration](/appsec/configuration.md):
6284

6385
```yaml title="values.yaml"
@@ -74,13 +96,20 @@ appsec:
7496
env:
7597
- name: COLLECTIONS
7698
value: crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules
99+
lapi:
100+
env:
101+
- name: BOUNCER_KEY_nginx_ingress_waf
102+
valueFrom:
103+
secretKeyRef:
104+
name: crowdsec-keys
105+
key: BOUNCER_KEY_nginx_ingress_waf
77106
```
78107
79108
This YAML configuration snippet exposes the important configuration items:
80109
* `listen_addr: 0.0.0.0:7422` exposes the AppSec API inside the cluster.
81110
* `appsec_configs` loads the [AppSec configuration(s)](/appsec/configuration.md) that define which rules are evaluated (in-band vs out-of-band).
82111
* The two collections provide virtual patching and generic rule coverage.
83-
* The chart bootstraps a bouncer named `nginx_ingress_waf` using the key you export locally.
112+
* `lapi.env` forces the `nginx_ingress_waf` bouncer key from the `crowdsec-keys` Secret.
84113

85114
And now we apply the new configuration with:
86115

@@ -98,6 +127,26 @@ You should see `crowdsec-agent` pods, the `crowdsec-lapi` pod and the `crowdsec-
98127

99128
## Enable the CrowdSec Lua plugin on NGINX Ingress
100129

130+
Create the secret holding the same CrowdSec bouncer key in the
131+
`ingress-nginx` namespace:
132+
133+
```yaml title="crowdsec-ingress-bouncer-secret.yaml"
134+
apiVersion: v1
135+
kind: Secret
136+
metadata:
137+
name: crowdsec-ingress-bouncer-secrets
138+
namespace: ingress-nginx
139+
type: Opaque
140+
stringData:
141+
api-key: "<same-value-as-BOUNCER_KEY_nginx_ingress_waf>"
142+
```
143+
144+
Apply it:
145+
146+
```bash
147+
kubectl apply -f crowdsec-ingress-bouncer-secret.yaml
148+
```
149+
101150
To extend the ingress controller with the CrowdSec plugin and point it to the
102151
AppSec API, create the file named `ingress-values.yaml`. You can read the entire
103152
file in the snippet below.
@@ -120,7 +169,10 @@ controller:
120169
- name: API_URL
121170
value: "http://crowdsec-service.crowdsec.svc.cluster.local:8080"
122171
- name: API_KEY
123-
value: privateKey-foo
172+
valueFrom:
173+
secretKeyRef:
174+
name: crowdsec-ingress-bouncer-secrets
175+
key: api-key
124176
- name: BOUNCER_CONFIG
125177
value: "/crowdsec/crowdsec-bouncer.conf"
126178
- name: APPSEC_URL
@@ -153,13 +205,13 @@ controller:
153205
plugins: "crowdsec"
154206
lua-shared-dicts: "crowdsec_cache: 50m"
155207
server-snippet: |
156-
lua_ssl_trusted_certificate "/etc/ssl/certs/ca-certificates.crt"
208+
lua_ssl_trusted_certificate "/etc/ssl/certs/ca-certificates.crt";
157209
resolver local=on ipv6=off;
158210
```
159211

160212

161213
- `API_URL` targets the Local API service exposed by the Helm chart.
162-
- `API_KEY` defines the key for the bouncer to be able to connect to CrowdSec LAPI
214+
- `API_KEY` is read from the `crowdsec-ingress-bouncer-secrets` Secret in the `ingress-nginx` namespace.
163215
- `APPSEC_URL` points to the AppSec service; keep the namespace in sync with your CrowdSec release.
164216
- The plugin copies the Lua files from the init container into an `emptyDir` that is mounted at runtime.
165217

@@ -212,7 +264,10 @@ extraInitContainers:
212264
- name: API_URL
213265
value: "http://crowdsec-service.crowdsec.svc.cluster.local:8080"
214266
- name: API_KEY
215-
value: privateKey-foo
267+
valueFrom:
268+
secretKeyRef:
269+
name: crowdsec-ingress-bouncer-secrets
270+
key: api-key
216271
- name: BOUNCER_CONFIG
217272
value: "/crowdsec/crowdsec-bouncer.conf"
218273
- name: APPSEC_URL

0 commit comments

Comments
 (0)