Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Packetbeat] HTTP: Improve support for 100-continue #15830

Closed
adriansr opened this issue Jan 24, 2020 · 6 comments
Closed

[Packetbeat] HTTP: Improve support for 100-continue #15830

adriansr opened this issue Jan 24, 2020 · 6 comments
Labels
enhancement good first issue Indicates a good issue for first-time contributors Packetbeat

Comments

@adriansr
Copy link
Contributor

adriansr commented Jan 24, 2020

Packetbeat lacks support for 100-continue request/response, which looks like:

  1. Client: sends request headers including Expect: 100-continue.
  2. Server: responds with 100 status code (or an error, which terminates the request).
  3. Client: sends the request body.
  4. Server: Answers with a full response.

Currently this is causing Packetbeat to:

  1. Output an error document with "unmatched response" for the 100-continue response(2).
  2. Output a correct document for the rest (1,3,4).

Example with Packetbeat monitoring port 9200 for http:

curl -H 'Expect: 100-continue' -H 'Content-Type: application/json' -XPOST 'http://localhost:9200/filebeat/_doc/mydoc' --data '{}'

Produces:

{
  "error": {
    "message": "Unmatched response"
  },
  "status": "Error",
  "type": "http",
  "http": {
    "response": {
      "status_code": 100,
      "bytes": 25,
      "headers": {
        "content-length": 0
      },
      "status_phrase": "continue"
    }
  },
  [...]
}

and

{
  "type": "http",
  "query": "POST /filebeat/_doc/mydoc",
  "status": "OK",
  "user_agent": {
    "original": "curl/7.54.0"
  },
  "method": "post",
  "http": {
    "version": "1.1",
    "request": {
      "method": "post",
      "bytes": 173,
      "body": {
        "bytes": 2
      },
      "headers": {
        "content-type": "application/json",
        "content-length": 2
      }
    },
    "response": {
      "headers": {
        "content-type": "application/json; charset=UTF-8",
        "content-length": 160
      },
      "status_phrase": "ok",
      "status_code": 200,
      "bytes": 247,
      "body": {
        "bytes": 160
      }
    }
  },
  "url": {
    "port": 9200,
    "path": "/filebeat/_doc/mydoc",
    "full": "http://localhost:9200/filebeat/_doc/mydoc",
    "scheme": "http",
    "domain": "localhost"
  }
  [...]
}

A simple workaround is to drop the events which contain this error:

processors:
  - drop_event.when:
     and:
     - equals.http.response.status_code: 100
     - equals.error.message: 'Unmatched response'
@adriansr adriansr added enhancement good first issue Indicates a good issue for first-time contributors Packetbeat labels Jan 24, 2020
@OhBonsai
Copy link
Contributor

OhBonsai commented May 4, 2020

Hi, I would like to do some work on this. Could you @adriansr get me up to speed quickly on this? :)

@adriansr
Copy link
Contributor Author

adriansr commented May 5, 2020

Hi @OhBonsai, sure.

So I take it you know more or less how it works, but let me summarize:

Packetbeat expects a normal HTTP request/response transaction:

client --> request(headers, body)  --> server
client <-- response(headers, body) <-- server

From this Packetbeat generates a document for the request/response transaction.

but when the client request includes a Expect: 100-continue header, the transaction is a bit different:

client --> request(headers)        --> server
client <-- response(100-continue)  <-- server
client --> request(body)           --> server
client <-- response(headers, body) <-- server

From this currently Packetbeat generates two documents:

  • one with the 100-continue response and an error.message: "Unmatched response"
  • one with the client request and the final response from the server.

We want just the last document, while making sure that configuration options like send_headers/include_body_for/etc still work and return data from the client request and final response from the server, and not from the intermediate 100-continue response from the server.

Code for this is in packetbeat/protos/http.

Thanks for contributing!

@OhBonsai
Copy link
Contributor

@adriansr PTAL

marc-gr added a commit that referenced this issue Jul 27, 2020
* refactor(packet beat): Improve support for 100-continue

* test(packetbeat): 100-continue only generate one event without error

* test(packetbeat): 100-continue only generate one event without error

* Update packetbeat/protos/http/http.go

Co-authored-by: Adrian Serrano <adrisr83@gmail.com>

* delete unused string

* Fix format issue

Co-authored-by: Marc Guasch <marc.guasch@elastic.co>
Co-authored-by: Adrian Serrano <adrisr83@gmail.com>
marc-gr pushed a commit to marc-gr/beats that referenced this issue Jul 27, 2020
…astic#19349)

* refactor(packet beat): Improve support for 100-continue

* test(packetbeat): 100-continue only generate one event without error

* test(packetbeat): 100-continue only generate one event without error

* Update packetbeat/protos/http/http.go

Co-authored-by: Adrian Serrano <adrisr83@gmail.com>

* delete unused string

* Fix format issue

Co-authored-by: Marc Guasch <marc.guasch@elastic.co>
Co-authored-by: Adrian Serrano <adrisr83@gmail.com>
(cherry picked from commit 41bc8c6)
v1v added a commit to v1v/beats that referenced this issue Jul 27, 2020
…ne-2.0

* upstream/master: (41 commits)
  adding possibility to override content-type checks, it was breaking certain webhooks that is not able to set content-headers at all. Still defaults to application/json (elastic#20232)
  fix: use a fixed worker type for tests (elastic#20130)
  [Ingest Manager] Prepare packaging for endpoint and asc files (elastic#20186)
  [Packetbeat] HTTP: Improve support for 100-continue elastic#15830 (elastic#19349)
  Increase index.max_docvalue_fields_search to 200 (elastic#20218)
  [Ingest Manager] Prevent closing closed reader (elastic#20214)
  [Metricbeat] Use MySQL Host Parser in Query metricset (elastic#20191)
  Testing: Ignore timestamp from cylance/protect dataset (elastic#20211)
  [Filebeat] Ignore cylance.protect timestamps while testing (elastic#20207)
  [CI] remove codecov step (elastic#20102)
  [docs] Indicate that SYSTEM user is required on Windows to use Endpoint (elastic#20172)
  Remove f5/firepass rsa2elk fileset (elastic#20160)
  [Elastic Agent] Improve GRPC stop to be more relaxed. (elastic#20118)
  Fix fileset field prefixing (elastic#20170)
  Fix terminating pod autodiscover issue (elastic#20084)
  Call host parser only once when building light metricsets (elastic#20149)
  [CI] fix null string with contains (elastic#20182)
  [Ingest Manager] Fix failing unit tests on windows (elastic#20127)
  [Filebeat] Update crowdstrike module (elastic#20138)
  [docs] Add x-pack role to relevant metricsets (elastic#20167)
  ...
marc-gr added a commit that referenced this issue Jul 28, 2020
…20234)

* refactor(packet beat): Improve support for 100-continue

* test(packetbeat): 100-continue only generate one event without error

* test(packetbeat): 100-continue only generate one event without error

* Update packetbeat/protos/http/http.go

Co-authored-by: Adrian Serrano <adrisr83@gmail.com>

* delete unused string

* Fix format issue

Co-authored-by: Marc Guasch <marc.guasch@elastic.co>
Co-authored-by: Adrian Serrano <adrisr83@gmail.com>
(cherry picked from commit 41bc8c6)

Co-authored-by: Bonsai <LetBonsaiBe@gmail.com>
melchiormoulin pushed a commit to melchiormoulin/beats that referenced this issue Oct 14, 2020
…astic#19349)

* refactor(packet beat): Improve support for 100-continue

* test(packetbeat): 100-continue only generate one event without error

* test(packetbeat): 100-continue only generate one event without error

* Update packetbeat/protos/http/http.go

Co-authored-by: Adrian Serrano <adrisr83@gmail.com>

* delete unused string

* Fix format issue

Co-authored-by: Marc Guasch <marc.guasch@elastic.co>
Co-authored-by: Adrian Serrano <adrisr83@gmail.com>
@botelastic
Copy link

botelastic bot commented May 25, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@botelastic botelastic bot added Stalled needs_team Indicates that the issue/PR needs a Team:* label labels May 25, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed needs_team Indicates that the issue/PR needs a Team:* label Stalled labels Jun 23, 2021
@marc-gr
Copy link
Contributor

marc-gr commented Oct 22, 2021

Closed in #19349

@marc-gr marc-gr closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Indicates a good issue for first-time contributors Packetbeat
Projects
None yet
Development

No branches or pull requests

5 participants