Skip to content

Commit

Permalink
[Filebeat] Add Proxy config to httpjson v2 (elastic#24662)
Browse files Browse the repository at this point in the history
Adds a `proxy_url` config option to the httpjson v2 input. Updates all httpjson based modules to support proxy_url.

Fixes elastic#24615.

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
  • Loading branch information
legoguy1000 and andrewkroh authored Mar 24, 2021
1 parent 7f5a358 commit 9a5f5d0
Show file tree
Hide file tree
Showing 52 changed files with 137 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Support X-Forwarder-For in IIS logs. {pull}19142[192142]
- Updating field mappings for Cisco AMP module, fixing certain fields. {pull}24661[24661]
- Added NTP fileset to Zeek module {pull}24224[24224]
- Add `proxy_url` config for httpjson v2 input. {issue}24615[24615] {pull}24662[24662]

*Heartbeat*

Expand Down
17 changes: 17 additions & 0 deletions x-pack/filebeat/docs/inputs/input-httpjson.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This input supports:
* Pagination
* Retries
* Rate limiting
* Proxying
* Request transformations
* Response transformations

Expand Down Expand Up @@ -383,6 +384,22 @@ This specifies SSL/TLS configuration. If the ssl section is missing, the host's
CAs are used for HTTPS connections. See <<configuration-ssl>> for more
information.

[float]
==== `request.proxy_url`

This specifies proxy configuration in the form of `http[s]://<user>:<password>@<server name/ip>:<port>`

["source","yaml",subs="attributes"]
----
filebeat.inputs:
# Fetch your public IP every minute.
- type: httpjson
config_version: 2
interval: 1m
request.url: https://api.ipify.org/?format=json
request.proxy_url: http://proxy.example:8080
----

[float]
==== `request.retry.max_attempts`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type requestConfig struct {
RedirectMaxRedirects int `config:"redirect.max_redirects"`
RateLimit *rateLimitConfig `config:"rate_limit"`
Transforms transformsConfig `config:"transforms"`
ProxyURL *urlConfig `config:"proxy_url"`
}

func (c requestConfig) getTimeout() time.Duration {
Expand Down
19 changes: 12 additions & 7 deletions x-pack/filebeat/input/httpjson/internal/v2/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,22 @@ func run(

func newHTTPClient(ctx context.Context, config config, tlsConfig *tlscommon.TLSConfig, log *logp.Logger) (*httpClient, error) {
timeout := config.Request.getTimeout()
proxy_url := config.Request.ProxyURL

// Make retryable HTTP client
transport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: timeout,
}).DialContext,
TLSClientConfig: tlsConfig.ToConfig(),
DisableKeepAlives: true,
}
if proxy_url != nil && proxy_url.URL != nil {
transport.Proxy = http.ProxyURL(proxy_url.URL)
}
client := &retryablehttp.Client{
HTTPClient: &http.Client{
Transport: &http.Transport{
DialContext: (&net.Dialer{
Timeout: timeout,
}).DialContext,
TLSClientConfig: tlsConfig.ToConfig(),
DisableKeepAlives: true,
},
Transport: transport,
Timeout: timeout,
CheckRedirect: checkRedirect(config.Request, log),
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/filebeat/module/cisco/amp/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ request.timeout: {{ .request_timeout }}
{{ if .ssl }}
request.ssl: {{ .ssl | tojson }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.start_date
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/cisco/amp/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var:
default: 24h
- name: interval
default: 60m
- name: proxy_url

ingest_pipeline:
- ingest/pipeline.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ request.url: https://www.googleapis.com/admin/reports/v1/activity/users/{{ .user
{{ if .http_client_timeout }}
request.timeout: {{ .http_client_timeout }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.startTime
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/google_workspace/admin/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ request.url: https://www.googleapis.com/admin/reports/v1/activity/users/{{ .user
{{ if .http_client_timeout }}
request.timeout: {{ .http_client_timeout }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.startTime
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/google_workspace/drive/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ request.url: https://www.googleapis.com/admin/reports/v1/activity/users/{{ .user
{{ if .http_client_timeout }}
request.timeout: {{ .http_client_timeout }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.startTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ request.url: https://www.googleapis.com/admin/reports/v1/activity/users/{{ .user
{{ if .http_client_timeout }}
request.timeout: {{ .http_client_timeout }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.startTime
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/google_workspace/login/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ request.url: https://www.googleapis.com/admin/reports/v1/activity/users/{{ .user
{{ if .http_client_timeout }}
request.timeout: {{ .http_client_timeout }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.startTime
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/google_workspace/saml/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ request.url: https://www.googleapis.com/admin/reports/v1/activity/users/{{ .user
{{ if .http_client_timeout }}
request.timeout: {{ .http_client_timeout }}
{{ end }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
- set:
target: url.params.startTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/gsuite/admin/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ date_cursor.initial_interval: {{ .initial_interval }}
pagination.id_field: nextPageToken
pagination.url_field: pageToken

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

{{ else if eq .input "file" }}
type: log
paths:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gsuite/admin/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/gsuite/drive/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ date_cursor.initial_interval: {{ .initial_interval }}
pagination.id_field: nextPageToken
pagination.url_field: pageToken

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

{{ else if eq .input "file" }}
type: log
paths:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gsuite/drive/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/gsuite/groups/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ date_cursor.initial_interval: {{ .initial_interval }}
pagination.id_field: nextPageToken
pagination.url_field: pageToken

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

{{ else if eq .input "file" }}
type: log
paths:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gsuite/groups/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/gsuite/login/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ date_cursor.initial_interval: {{ .initial_interval }}
pagination.id_field: nextPageToken
pagination.url_field: pageToken

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

{{ else if eq .input "file" }}
type: log
paths:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gsuite/login/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/gsuite/saml/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ date_cursor.initial_interval: {{ .initial_interval }}
pagination.id_field: nextPageToken
pagination.url_field: pageToken

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

{{ else if eq .input "file" }}
type: log
paths:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gsuite/saml/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/gsuite/user_accounts/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ date_cursor.initial_interval: {{ .initial_interval }}
pagination.id_field: nextPageToken
pagination.url_field: pageToken

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

{{ else if eq .input "file" }}
type: log
paths:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gsuite/user_accounts/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: 2h
- name: tags
default: [forwarded]
- name: proxy_url

input: config/config.yml
ingest_pipeline: ../ingest/common.yml
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/module/microsoft/defender_atp/config/atp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ auth.oauth2: {{ .oauth2 | tojson }}
auth.oauth2.provider: azure
auth.oauth2.azure.resource: https://api.securitycenter.windows.com/

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

request.url: "https://api.securitycenter.windows.com/api/alerts"
request.method: GET
request.transforms:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/microsoft/defender_atp/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var:
- name: tags
default: [defender-atp, forwarded]
- name: oauth2
- name: proxy_url

ingest_pipeline: ingest/pipeline.yml
input: config/atp.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ auth.oauth2: {{ .oauth2 | tojson }}
auth.oauth2.provider: azure
auth.oauth2.azure.resource: https://api.securitycenter.windows.com/

{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

request.url: "https://api.security.microsoft.com/api/incidents"
request.method: GET
request.transforms:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var:
- name: tags
default: [m365-defender, forwarded]
- name: oauth2
- name: proxy_url

ingest_pipeline: ingest/pipeline.yml
input: config/defender.yml
Expand Down
3 changes: 3 additions & 0 deletions x-pack/filebeat/module/misp/threat/config/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ interval: {{ .interval }}

request.method: POST
request.ssl: {{ .ssl | tojson }}
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.url: {{ .url }}
request.timeout: {{ .http_client_timeout }}
request.body: {{ .http_request_body | tojson }}
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/misp/threat/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var:
default: "60s"
- name: url
- name: ssl
- name: proxy_url

input: config/input.yml
ingest_pipeline: ingest/pipeline.json
Expand Down
5 changes: 5 additions & 0 deletions x-pack/filebeat/module/okta/system/config/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ request.ssl: {{ .ssl | tojson }}
request.timeout: {{ .http_client_timeout }}
{{ end }}


{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}

request.method: GET
request.url: {{ .url }}
request.rate_limit:
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/okta/system/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var:
- name: tags
default: [forwarded]
- name: url
- name: proxy_url
- name: initial_interval
default: 24h

Expand Down
Loading

0 comments on commit 9a5f5d0

Please sign in to comment.