Skip to content

Commit 1bafec4

Browse files
authored
custom bouncer: add stdin example + JSON object description (#771)
1 parent 376474a commit 1bafec4

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

crowdsec-docs/unversioned/bouncers/custom.mdx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ The above will ensure you get values from LAPI to the script, however, you shoul
181181

182182
## Usage
183183

184+
:::warning
185+
Remember to set execution permissions for your binary or script. If it's a script, include a shebang on the first line (e.g., `#!/bin/sh`).
186+
:::
187+
188+
### Invoke mode
189+
190+
:::warning
191+
While the default mode, it is not recommended to use it, as calling a binary for each decision can be very costly when a lot are present.
192+
:::
193+
184194
The custom binary will be called with the following arguments :
185195

186196
```text
@@ -191,21 +201,48 @@ The custom binary will be called with the following arguments :
191201
- `value` : The value will be the decision scope value (eg `192.168.1.1` for IP)
192202
- `duration`: duration of the remediation in seconds
193203
- `reason` : reason of the decision
194-
- `json_object`: the serialized decision
195-
196-
197-
:::warning
198-
Remember to set execution permissions for your binary or script. If it's a script, include a shebang on the first line (e.g., `#!/bin/sh`).
199-
:::
204+
- `json_object`: the serialized decision (see the next section for more details)
200205

201-
## Examples
206+
#### Examples
202207

203208
```text
204209
custom_binary.sh add 192.168.1.1/32 3600 "test blacklist" <json_object>
205210
custom_binary.sh del 192.168.1.1/32 3600 "test blacklist" <json_object>
206211
```
207212

208213

214+
### Stdin mode
215+
216+
In this mode, the custom binary will be executed when the bouncer starts and is expected to read data from stdin.
217+
218+
If the binary exits for any reason, it will be reinvoked up to `max_retries` times. If the maximum number of retries is exhausted, the bouncer will quit.
219+
220+
For each decision, the custom binary will be fed the serialized JSON object on stdin, one object per line.
221+
222+
The JSON object is:
223+
```json
224+
{
225+
"duration": "143h58m15s",
226+
"origin": "CAPI",
227+
"scenario": "ssh:bruteforce",
228+
"scope": "Ip",
229+
"type": "ban",
230+
"value": "160.187.109.6",
231+
"id": 83676344,
232+
"action": "add"
233+
}
234+
```
235+
236+
- `duration`: duration of the decision, in the [go time.Duration format](https://pkg.go.dev/time#Duration). Can be negative for delete decisions.
237+
- `origin`: origin the decision. Can be `crowdsec`, `cscli`, `cscli-import`, `CAPI`, `lists`.
238+
- `scenario`: scenario that triggered the decision.
239+
- `scope`: Scope of the decision. Most likely `Ip` or `Range` with the default config, but can be any value set in your scenarios.
240+
- `type`: Type of the decision. Most likely `ban` or `captcha` with the default config, but can be any value set in your profiles.
241+
- `value`: Target of the decision.
242+
- `id`: id of the decision in the crowdsec database.
243+
- `action`: Either `add` or `del`.
244+
245+
209246
## Configuration Reference
210247

211248
### `bin_path`
@@ -216,7 +253,9 @@ Absolute path to the binary that will be invoked
216253
### `bin_args`
217254
> [ ]string
218255
219-
Array of argument to give to the script that will be invoked
256+
Array of argument to give to the script that will be invoked.
257+
258+
This option is only supported if `feed_via_stdin` is set to `true`.
220259

221260
### `feed_via_stdin`
222261
> boolean

0 commit comments

Comments
 (0)