Skip to content

Commit 55629bc

Browse files
authored
x-pack/filebeat/input/{cel,httpjson}: add file-based authentication support for CEL and HTTP JSON inputs (#47507)
1 parent b44eee3 commit 55629bc

File tree

15 files changed

+1242
-4
lines changed

15 files changed

+1242
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: enhancement
2+
summary: Add file-based auth provider for CEL and HTTP JSON inputs.
3+
description: |
4+
The CEL and HTTP JSON inputs now support reading authentication tokens from
5+
files, enabling integration with various secret providers like Vault,
6+
Kubernetes secret projections, etc. Tokens are automatically refreshed based on
7+
a configurable interval without requiring restarts.
8+
component: filebeat
9+
issue: https://github.com/elastic/beats/issues/47506

docs/reference/filebeat/filebeat-input-cel.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This input supports:
2121

2222
* Basic
2323
* Digest
24+
* {applies_to}`stack: ga 9.3.0` File
2425
* OAuth2
2526

2627
* Retrieval at a configurable interval
@@ -271,9 +272,10 @@ Additionally, it supports authentication via:
271272
* Basic Authentication
272273
* Digest Authentication {applies_to}`stack: ga 8.12.0`
273274
* OAuth2
275+
* file-based headers {applies_to}`stack: ga 9.3.0`
274276
* token authentication {applies_to}`stack: ga 8.19.0, unavailable 9.0.0, ga 9.1.0`
275277

276-
As described in Mito's [HTTP]({{mito_docs}}@{{mito_version}}/lib#HTTP) documentation, configuration for Basic Authentication or token authentication will only affect direct HEAD, GET and POST method calls, not explicity constructed requests run with `.do_request()`. Configuration for Digest Authentication or OAuth2 will be used for all requests made from CEL.
278+
As described in Mito's [HTTP]({{mito_docs}}@{{mito_version}}/lib#HTTP) documentation, configuration for Basic Authentication or token authentication will only affect direct HEAD, GET and POST method calls, not explicity constructed requests run with `.do_request()`. Configuration for Digest Authentication, file-based headers or OAuth2 will be used for all requests made from CEL.
277279

278280
Example configurations with authentication:
279281

@@ -317,6 +319,16 @@ filebeat.inputs:
317319
resource.url: http://localhost
318320
```
319321

322+
```yaml
323+
filebeat.inputs:
324+
- type: cel
325+
auth.file:
326+
path: /etc/elastic/token
327+
prefix: "Bearer "
328+
refresh_interval: 10m
329+
resource.url: http://localhost
330+
```
331+
320332
```yaml
321333
filebeat.inputs:
322334
- type: cel
@@ -557,6 +569,74 @@ stack: ga 8.12.0
557569
When set to `true`, Digest Authentication challenges are not reused.
558570

559571

572+
### `auth.file.enabled` [_auth_file_enabled]
573+
574+
```{applies_to}
575+
stack: ga 9.3.0
576+
```
577+
578+
When set to `false`, disables the file auth configuration. Default: `true`.
579+
580+
::::{note}
581+
File auth settings are disabled if either `enabled` is set to `false` or the `auth.file` section is missing.
582+
::::
583+
584+
585+
### `auth.file.path` [_auth_file_path]
586+
587+
```{applies_to}
588+
stack: ga 9.3.0
589+
```
590+
591+
The path to the file containing the authentication value. The file contents are trimmed before use. This field is required when file auth is enabled.
592+
593+
::::{warning}
594+
By default, Filebeat requires the file to have `0600` permissions (read/write for owner only) and will fail to start if the file is more permissive. This security measure helps prevent unauthorized access to credentials. To allow files with different permissions, set [`relaxed_permissions`](#_auth_file_relaxed_permissions) to `true`.
595+
596+
On Windows, POSIX-style permission checking is not enforced. Ensure file security using NTFS file permissions or Access Control Lists (ACLs).
597+
::::
598+
599+
600+
### `auth.file.header` [_auth_file_header]
601+
602+
```{applies_to}
603+
stack: ga 9.3.0
604+
```
605+
606+
The request header that receives the value loaded from `path`. Defaults to `Authorization` when omitted or empty.
607+
608+
609+
### `auth.file.prefix` [_auth_file_prefix]
610+
611+
```{applies_to}
612+
stack: ga 9.3.0
613+
```
614+
615+
An optional prefix that is prepended to the trimmed value from `path` before it is set on the request header. This is commonly used for tokens that require a leading value such as `Bearer `.
616+
617+
618+
### `auth.file.refresh_interval` [_auth_file_refresh_interval]
619+
620+
```{applies_to}
621+
stack: ga 9.3.0
622+
```
623+
624+
How frequently Filebeat rereads the file defined by `path` to pick up changes. Defaults to `1m`. The value must be greater than zero when set.
625+
626+
627+
### `auth.file.relaxed_permissions` [_auth_file_relaxed_permissions]
628+
629+
```{applies_to}
630+
stack: ga 9.3.0
631+
```
632+
633+
When set to `true`, allows the authentication file to have permissions other than `0600`. By default (`false`), Filebeat requires the file to have `0600` permissions and will fail to start if the file is more permissive. This security measure helps prevent unauthorized access to credentials.
634+
635+
::::{warning}
636+
Setting this to `true` reduces security. Only enable this option if you understand the security implications and cannot set the file to `0600` permissions.
637+
::::
638+
639+
560640
### `auth.oauth2.enabled` [_auth_oauth2_enabled]
561641

562642
When set to `false`, disables the oauth2 configuration. Default: `true`.

docs/reference/filebeat/filebeat-input-httpjson.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ This input supports:
1717

1818
* Auth
1919

20-
* Basic
21-
* OAuth2
20+
* Basic
21+
* {applies_to}`stack: ga 9.3.0` File
22+
* OAuth2
2223

2324
* Retrieval at a configurable interval
2425
* Pagination
@@ -61,7 +62,11 @@ filebeat.inputs:
6162
value: 5m
6263
```
6364
64-
Additionally, it supports authentication via Basic auth, HTTP Headers or oauth2.
65+
Additionally, it supports authentication via:
66+
* Basic auth
67+
* {applies_to}`stack: ga 9.3.0` File-based headers (`auth.file`)
68+
* HTTP headers
69+
* OAauth2
6570

6671
Example configurations with authentication:
6772

@@ -97,6 +102,16 @@ filebeat.inputs:
97102
request.url: http://localhost
98103
```
99104

105+
```yaml
106+
filebeat.inputs:
107+
- type: httpjson
108+
auth.file:
109+
path: /etc/elastic/token
110+
prefix: "Bearer "
111+
refresh_interval: 10m
112+
request.url: http://localhost
113+
```
114+
100115
## Input state [input-state]
101116

102117
The `httpjson` input keeps a runtime state between requests. This state can be accessed by some configuration options and transforms.
@@ -261,6 +276,74 @@ The user to authenticate with.
261276
The password to use.
262277

263278

279+
### `auth.file.enabled` [_auth_file_enabled_2]
280+
281+
```{applies_to}
282+
stack: ga 9.3.0
283+
```
284+
285+
When set to `false`, disables the file auth configuration. Default: `true`.
286+
287+
::::{note}
288+
File auth settings are disabled if either `enabled` is set to `false` or the `auth.file` section is missing.
289+
::::
290+
291+
292+
### `auth.file.path` [_auth_file_path_2]
293+
294+
```{applies_to}
295+
stack: ga 9.3.0
296+
```
297+
298+
The path to the file that contains the authentication value. The file contents are trimmed before use. This field is required when file auth is enabled.
299+
300+
::::{warning}
301+
By default, Filebeat requires the file to have `0600` permissions (read/write for owner only) and will fail to start if the file is more permissive. This security measure helps prevent unauthorized access to credentials. To allow files with different permissions, set [`relaxed_permissions`](#_auth_file_relaxed_permissions_2) to `true`.
302+
303+
On Windows, POSIX-style permission checking is not enforced. Ensure file security using NTFS file permissions or Access Control Lists (ACLs).
304+
::::
305+
306+
307+
### `auth.file.header` [_auth_file_header_2]
308+
309+
```{applies_to}
310+
stack: ga 9.3.0
311+
```
312+
313+
The request header that receives the value loaded from `path`. Defaults to `Authorization` when omitted or empty.
314+
315+
316+
### `auth.file.prefix` [_auth_file_prefix_2]
317+
318+
```{applies_to}
319+
stack: ga 9.3.0
320+
```
321+
322+
An optional prefix that is prepended to the trimmed value from `path` before it is sent on the request header. This is commonly used for tokens that require a leading value such as `Bearer `.
323+
324+
325+
### `auth.file.refresh_interval` [_auth_file_refresh_interval_2]
326+
327+
```{applies_to}
328+
stack: ga 9.3.0
329+
```
330+
331+
How frequently Filebeat rereads the file defined by `path` to pick up changes. Defaults to `1m`. The value must be greater than zero when set.
332+
333+
334+
### `auth.file.relaxed_permissions` [_auth_file_relaxed_permissions_2]
335+
336+
```{applies_to}
337+
stack: ga 9.3.0
338+
```
339+
340+
When set to `true`, allows the authentication file to have permissions other than `0600`. By default (`false`), Filebeat requires the file to have `0600` permissions and will fail to start if the file is more permissive. This security measure helps prevent unauthorized access to credentials.
341+
342+
::::{warning}
343+
Setting this to `true` reduces security. Only enable this option if you understand the security implications and cannot set the file to `0600` permissions.
344+
::::
345+
346+
264347
### `auth.oauth2.enabled` [_auth_oauth2_enabled_2]
265348

266349
When set to `false`, disables the oauth2 configuration. Default: `true`.

x-pack/filebeat/input/cel/config_auth.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"net/url"
1515
"os"
1616
"strings"
17+
"time"
1718

1819
"golang.org/x/oauth2"
1920
"golang.org/x/oauth2/clientcredentials"
@@ -28,10 +29,16 @@ type authConfig struct {
2829
Basic *basicAuthConfig `config:"basic"`
2930
Token *tokenAuthConfig `config:"token"`
3031
Digest *digestAuthConfig `config:"digest"`
32+
File *fileAuthConfig `config:"file"`
3133
OAuth2 *oAuth2Config `config:"oauth2"`
3234
AWS *aws.SignerInputConfig `config:"aws"`
3335
}
3436

37+
const (
38+
defaultFileAuthHeader = "Authorization"
39+
defaultFileAuthRefreshInterval = time.Minute
40+
)
41+
3542
func (c authConfig) Validate() error {
3643
var n int
3744
if c.Basic.isEnabled() {
@@ -43,6 +50,9 @@ func (c authConfig) Validate() error {
4350
if c.Digest.isEnabled() {
4451
n++
4552
}
53+
if c.File.isEnabled() {
54+
n++
55+
}
4656
if c.OAuth2.isEnabled() {
4757
n++
4858
}
@@ -128,6 +138,52 @@ func (d *digestAuthConfig) Validate() error {
128138
return nil
129139
}
130140

141+
type fileAuthConfig struct {
142+
Enabled *bool `config:"enabled"`
143+
Path string `config:"path"`
144+
Header string `config:"header"`
145+
Prefix string `config:"prefix"`
146+
RefreshInterval *time.Duration `config:"refresh_interval"`
147+
RelaxedPermissions bool `config:"relaxed_permissions"`
148+
}
149+
150+
func (f *fileAuthConfig) isEnabled() bool {
151+
return f != nil && (f.Enabled == nil || *f.Enabled)
152+
}
153+
154+
func (f *fileAuthConfig) Validate() error {
155+
if !f.isEnabled() {
156+
return nil
157+
}
158+
if f.Path == "" {
159+
return errors.New("path must be set")
160+
}
161+
if f.RefreshInterval != nil && (*f.RefreshInterval <= 0) {
162+
return errors.New("refresh_interval must be greater than 0")
163+
}
164+
165+
// Note: File existence check is performed later during transport initialization
166+
// (in newFileAuthTransport) to allow configuration validation to complete first.
167+
// This ensures proper error precedence: configuration errors (like multiple auth
168+
// methods) are reported before runtime errors (like missing files).
169+
170+
return nil
171+
}
172+
173+
func (f *fileAuthConfig) headerName() string {
174+
if f == nil || strings.TrimSpace(f.Header) == "" {
175+
return defaultFileAuthHeader
176+
}
177+
return f.Header
178+
}
179+
180+
func (f *fileAuthConfig) refreshInterval() time.Duration {
181+
if f == nil || f.RefreshInterval == nil {
182+
return defaultFileAuthRefreshInterval
183+
}
184+
return *f.RefreshInterval
185+
}
186+
131187
// An oAuth2Provider represents a supported oauth provider.
132188
type oAuth2Provider string
133189

0 commit comments

Comments
 (0)