Skip to content

Commit 55e9682

Browse files
committed
in_http: add_remote_addr
Signed-off-by: Alexandre Létourneau <[email protected]>
1 parent 4e21b77 commit 55e9682

File tree

1 file changed

+79
-11
lines changed

1 file changed

+79
-11
lines changed

pipeline/inputs/http.md

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ The _HTTP_ input plugin lets Fluent Bit open an HTTP port that you can then rout
55

66
## Configuration parameters
77

8-
| Key | Description | Default |
9-
|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|-----------|
10-
| `buffer_chunk_size` | This sets the chunk size for incoming JSON messages. These chunks are then stored and managed in the space available by `buffer_max_size`. | `512K` |
11-
| `buffer_max_size` | Specify the maximum buffer size to receive a JSON message. | `4M` |
12-
| `http2` | Enable HTTP/2 support. | `true` |
13-
| `listen` | The address to listen on. | `0.0.0.0` |
14-
| `port` | The port for Fluent Bit to listen on. | `9880` |
15-
| `success_header` | Add an HTTP header key/value pair on success. Multiple headers can be set. For example, `X-Custom custom-answer`. | _none_ |
16-
| `successful_response_code` | Allows setting successful response code. Supported values: `200`, `201`, and `204`. | `201` |
17-
| `tag_key` | Specify the key name to overwrite a tag. If set, the tag will be overwritten by a value of the key. | _none_ |
18-
| `threaded` | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). | `false` |
8+
| Key | Description | Default |
9+
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
10+
| `add_remote_addr` | Adds a `REMOTE_ADDR` field to the record. The value of `REMOTE_ADDR` is the client's address, which is extracted from the `X-Forwarded-For` header. | `false` |
11+
| `buffer_chunk_size` | This sets the chunk size for incoming JSON messages. These chunks are then stored and managed in the space available by `buffer_max_size`. | `512K` |
12+
| `buffer_max_size` | Specify the maximum buffer size to receive a JSON message. | `4M` |
13+
| `http2` | Enable HTTP/2 support. | `true` |
14+
| `listen` | The address to listen on. | `0.0.0.0` |
15+
| `port` | The port for Fluent Bit to listen on. | `9880` |
16+
| `success_header` | Add an HTTP header key/value pair on success. Multiple headers can be set. For example, `X-Custom custom-answer`. | _none_ |
17+
| `successful_response_code` | Allows setting successful response code. Supported values: `200`, `201`, and `204`. | `201` |
18+
| `tag_key` | Specify the key name to overwrite a tag. If set, the tag will be overwritten by a value of the key. | _none_ |
19+
| `threaded` | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). | `false` |
1920

2021
### TLS / SSL
2122

@@ -41,6 +42,32 @@ For example, in the following curl message the tag set is `app.log` because the
4142
curl -d '{"key1":"value1","key2":"value2"}' -XPOST -H "content-type: application/json" http://localhost:8888/app.log
4243
```
4344

45+
### Add remote addr
46+
47+
The `add_remote_addr` configuration option, when activated, adds a `REMOTE_ADDR` field to the records. The value of `REMOTE_ADDR` is the client's address, which is extracted from the `X-Forwarded-For` header.
48+
49+
In most cases, only a single `X-Forwarded-For` header is in the request, so the following curl would add a `REMOTE_ADDR` field which would be set to `host1`:
50+
51+
```shell
52+
curl -d '{"key1":"value1"}' -XPOST -H 'Content-Type: application/json' -H 'X-Forwarded-For: host1, host2' http://localhost:8888
53+
```
54+
55+
However, if your system sets multiple `X-Forwarded-For` headers in the request, the one used (first, or last) depends on the value of the `http2` config. For example:
56+
57+
Assuming the following X-Forwarded-For headers are in the request:
58+
59+
```text
60+
X-Forwarded-For: host1, host2
61+
X-Forwarded-For: host3, host4
62+
```
63+
64+
The value of REMOTE_ADDR will be:
65+
66+
| http2 config | value of REMOTE_ADDR |
67+
|------------------|----------------------|
68+
| `true` (default) | host3 |
69+
| `false` | host1 |
70+
4471
### Configuration file
4572

4673
{% tabs %}
@@ -161,6 +188,47 @@ pipeline:
161188
{% endtab %}
162189
{% endtabs %}
163190

191+
#### Set `add_remote_addr`
192+
193+
The `add_remote_addr` configuration option lets you activate a feature that systematically adds the `REMOTE_ADDR` field to events, and set its value to the client's address. The address will be extracted from the `X-Forwarded-For` header of the request. The format is:
194+
195+
{% tabs %}
196+
{% tab title="fluent-bit.yaml" %}
197+
198+
```yaml
199+
pipeline:
200+
inputs:
201+
- name: http
202+
listen: 0.0.0.0
203+
port: 8888
204+
add_remote_addr: true
205+
outputs:
206+
- name: stdout
207+
```
208+
209+
{% endtab %}
210+
{% tab title="fluent-bit.conf" %}
211+
212+
```text
213+
[INPUT]
214+
Name http
215+
Listen 0.0.0.0
216+
Port 8888
217+
Add_remote_addr true
218+
219+
[OUTPUT]
220+
Name stdout
221+
```
222+
223+
{% endtab %}
224+
{% endtabs %}
225+
226+
#### Example curl to test this feature
227+
228+
```shell
229+
curl -d '{"key1":"value1"}' -XPOST -H 'Content-Type: application/json' -H 'X-Forwarded-For: host1, host2' http://localhost:8888
230+
```
231+
164232
#### Set multiple custom HTTP headers on success
165233

166234
The `success_header` parameter lets you set multiple HTTP headers on success. The format is:

0 commit comments

Comments
 (0)