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

Cherry-pick #19321 to 7.x: DNS over TLS support for DNS processor #20090

Merged
merged 2 commits into from
Aug 11, 2020

Conversation

marc-gr
Copy link
Contributor

@marc-gr marc-gr commented Jul 21, 2020

Cherry-pick of PR #19321 to 7.x branch. Original message:

Label: Enhancement

What does this PR do?

Implement DNS over TLS (DoT) handler for the DNS Processor. #16663

Why is it important?

Now you can securely query for reverseDNS lookups across the internet. E.g. cloudflare 1.1.1.1 supports DNS over TLS

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
    I would need a bit of help here. Do I have to touch every beat config, or is the DNS processor page in the docs rendered from the libbeat ascii doc file?
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

  1. go to filebeat
  2. make
  3. edit filebeat config to include the at least the DNS processor
Minimum filebeat config

  - dns:
      type: reverse
      transport: tls
      fields:
        source.ip: source.hostname
        destination.ip: destination.hostname
      nameservers: ["1.1.1.1"]

Full filebeat config

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /Users/e_pkah/Documents/GitHub/pkahr/demodata/*
  json.keys_under_root: true
  json.add_error_key: true
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
setup.template.settings:
  index.number_of_shards: 1
output.elasticsearch:
  hosts: ["localhost:9200"]
processors:
  - decode_json_fields:
      fields: log
      overwrite_keys: true
  - dns:
      type: reverse
      transport: tls
      fields:
        source.ip: source.hostname
        destination.ip: destination.hostname
      nameservers: ["1.1.1.1"]

Example doc

{"source.ip": "1.1.1.1","destination.ip": "8.8.8.8"}

  1. replace transport: either with tls, udp. If left empty it will revert to default udp
  2. Ingest some file that has a source.ip or destination.ip (e.g. use example doc above)

Related issues

Use cases

  • Allow for secure reverse DNS lookups across the entire Internet and locally

Logs

TLS

./filebeat -e -d "*"
2020-06-22T19:56:00.082+0200    DEBUG   [processor.dns] dns/dns.go:67   DNS processor config: {CacheConfig:{SuccessCache:{TTL:0s InitialCapacity:1000 MaxCapacity:10000} FailureCache:{TTL:1m0s InitialCapacity:1000 MaxCapacity:10000}} Nameservers:[1.1.1.1] Timeout:500ms Type:reverse Action:append TagOnFailure:[] Fields:{"destination":{"ip":"destination.hostname"},"source":{"ip":"source.hostname"}} transport:tls reverseFlat:map[destination.ip:destination.hostname source.ip:source.hostname]}      {"instance_id": 1}
2020-06-22T20:28:31.155+0200    DEBUG   [processors]    processing/processors.go:187    Publish event: {
  "@timestamp": "2020-06-22T18:28:30.854Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "8.0.0"
  },
  "log": {
    "offset": 0,
    "file": {
      "path": "/Users/e_pkah/Documents/GitHub/pkahr/demodata/apache.json"
    }
  },
  "ecs": {
    "version": "1.5.0"
  },
  "destination": {
    "hostname": "dns.google"
  },
  "agent": {
    "id": "6bc4fd89-5e9e-4382-a2fb-5068f5782406",
    "name": "N1890002",
    "type": "filebeat",
    "version": "8.0.0",
    "ephemeral_id": "b8d53727-48f5-4a6a-9c84-735b7d4d0905"
  },
  "source": {
    "hostname": "one.one.one.one"
  },
  "source.ip": "1.1.1.1",
  "destination.ip": "8.8.8.8",
  "input": {
    "type": "log"
  },
  "host": {
    "name": "N1890002"
  }
}

UDP / no config

./filebeat -e -d "*"
2020-06-22T20:13:33.150+0200    DEBUG   [processor.dns] dns/dns.go:67   DNS processor config: {CacheConfig:{SuccessCache:{TTL:0s InitialCapacity:1000 MaxCapacity:10000} FailureCache:{TTL:1m0s InitialCapacity:1000 MaxCapacity:10000}} Nameservers:[1.1.1.1] Timeout:500ms Type:reverse Action:append TagOnFailure:[] Fields:{"destination":{"ip":"destination.hostname"},"source":{"ip":"source.hostname"}} transport:udp reverseFlat:map[destination.ip:destination.hostname source.ip:source.hostname]}      {"instance_id": 1}
2020-06-22T20:28:31.155+0200    DEBUG   [processors]    processing/processors.go:187    Publish event: {
  "@timestamp": "2020-06-22T18:28:30.854Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "8.0.0"
  },
  "log": {
    "offset": 0,
    "file": {
      "path": "/Users/e_pkah/Documents/GitHub/pkahr/demodata/apache.json"
    }
  },
  "ecs": {
    "version": "1.5.0"
  },
  "destination": {
    "hostname": "dns.google"
  },
  "agent": {
    "id": "6bc4fd89-5e9e-4382-a2fb-5068f5782406",
    "name": "N1890002",
    "type": "filebeat",
    "version": "8.0.0",
    "ephemeral_id": "b8d53727-48f5-4a6a-9c84-735b7d4d0905"
  },
  "source": {
    "hostname": "one.one.one.one"
  },
  "source.ip": "1.1.1.1",
  "destination.ip": "8.8.8.8",
  "input": {
    "type": "log"
  },
  "host": {
    "name": "N1890002"
  }
}

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 21, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/siem (Team:SIEM)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 21, 2020
@@ -410,6 +410,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Add the `overwrite_keys` configuration option to the dissect processor. {pull}19464[19464]
- Add support to trim captured values in the dissect processor. {pull}19464[19464]
- Added the `max_cached_sessions` option to the script processor. {pull}19562[19562]
- Add support for DNS over TLS for the dns_processor. {pull}19321[19321]
Copy link
Member

@andrewkroh andrewkroh Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add support for DNS over TLS for the dns_processor. {pull}19321[19321]
- Add support for DNS over TLS for the `dns` processor. {pull}19321[19321]

The processor name is just dns.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 21, 2020

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #20090 updated]

  • Start Time: 2020-08-11T12:05:45.282+0000

  • Duration: 83 min 57 sec

Test stats 🧪

Test Results
Failed 0
Passed 17782
Skipped 1838
Total 19620

@marc-gr marc-gr force-pushed the backport_19321_7.x branch 4 times, most recently from 0bdde4e to 3ed8368 Compare July 28, 2020 06:52
    * DNS over TLS DoT support elastic#16663

    * added changelog elastic#19321

    * Update dns.asciidoc

    * added testsuite for elastic#19321

    * Fix CHANGELOG entries and lint fixes

    * Apply suggestions from code review

    Co-authored-by: Marc Guasch <marc.guasch@elastic.co>
    Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
    (cherry picked from commit 89bfb6c)
@andrewkroh andrewkroh merged commit 1673d55 into elastic:7.x Aug 11, 2020
@zube zube bot removed the [zube]: Done label Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants