Skip to content

Commit 867a1fb

Browse files
committed
in_http: add_remote_addr
Signed-off-by: Alexandre Létourneau <[email protected]>
1 parent 65148d9 commit 867a1fb

File tree

1 file changed

+77
-10
lines changed

1 file changed

+77
-10
lines changed

pipeline/inputs/http.md

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ 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-
| `listen` | The address to listen on. | `0.0.0.0` |
11-
| `port` | The port for Fluent Bit to listen on. | `9880` |
12-
| `tag_key` | Specify the key name to overwrite a tag. If set, the tag will be overwritten by a value of the key. | _none_ |
13-
| `buffer_max_size` | Specify the maximum buffer size in KB to receive a JSON message. | `4M` |
14-
| `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` |
15-
| `successful_response_code` | Allows setting successful response code. Supported values: `200`, `201`, and `204` | `201` |
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-
| `threaded` | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). | `false` |
8+
| Key | Description | Default |
9+
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
10+
| `listen` | The address to listen on. | `0.0.0.0` |
11+
| `port` | The port for Fluent Bit to listen on. | `9880` |
12+
| `tag_key` | Specify the key name to overwrite a tag. If set, the tag will be overwritten by a value of the key. | _none_ |
13+
| `buffer_max_size` | Specify the maximum buffer size in KB to receive a JSON message. | `4M` |
14+
| `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` |
15+
| `successful_response_code` | Allows setting successful response code. Supported values: `200`, `201`, and `204` | `201` |
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+
| `threaded` | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). | `false` |
18+
| `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` |
1819

1920
### TLS / SSL
2021

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

44+
### Add remote addr
45+
46+
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.
47+
48+
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`:
49+
50+
```shell
51+
curl -d '{"key1":"value1"}' -XPOST -H 'Content-Type: application/json' -H 'X-Forwarded-For: host1, host2' http://localhost:8888
52+
```
53+
54+
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:
55+
56+
Assuming the following X-Forwarded-For headers are in the request:
57+
58+
```text
59+
X-Forwarded-For: host1, host2
60+
X-Forwarded-For: host3, host4
61+
```
62+
63+
The value of REMOTE_ADDR will be:
64+
65+
| http2 config | value of REMOTE_ADDR |
66+
|------------------|----------------------|
67+
| `true` (default) | host3 |
68+
| `false` | host1 |
69+
4370
### Configuration file
4471

4572
{% tabs %}
@@ -160,6 +187,46 @@ pipeline:
160187
{% endtab %}
161188
{% endtabs %}
162189

190+
#### Set `add_remote_addr`
191+
192+
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:
193+
194+
{% tabs %}
195+
{% tab title="fluent-bit.yaml" %}
196+
197+
```yaml
198+
pipeline:
199+
inputs:
200+
- name: http
201+
listen: 0.0.0.0
202+
port: 8888
203+
add_remote_addr: true
204+
outputs:
205+
- name: stdout
206+
```
207+
208+
{% endtab %}
209+
{% tab title="fluent-bit.conf" %}
210+
211+
```text
212+
[INPUT]
213+
name http
214+
listen 0.0.0.0
215+
port 8888
216+
add_remote_addr true
217+
[OUTPUT]
218+
name stdout
219+
```
220+
221+
{% endtab %}
222+
{% endtabs %}
223+
224+
#### Example curl to test this feature
225+
226+
```shell
227+
curl -d '{"key1":"value1"}' -XPOST -H 'Content-Type: application/json' -H 'X-Forwarded-For: host1, host2' http://localhost:8888
228+
```
229+
163230
#### Set multiple custom HTTP headers on success
164231

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

0 commit comments

Comments
 (0)