Skip to content

DNS filter: O(n2) domain search #12432

Closed
Closed

Description

@rshriram

the DNS filter uses the standard dns resolver that the dispatcher creates. The Dispatcher creates the c-ares resolver with default options. In the case of the DNS filter whose job is to receive and resolve DNS queries from the app (on a VM or k8s pod), the following happens:

  1. app container has resolv.conf with 4 search domains ( ns1.svc.cluster.local svc.cluster.local cluster.local google.internal)
  2. envoy sidecar container also has the same resolv.conf that c-ares uses

When the application container has to resolve a DNS name such as svc1.ns2, (where ndots: 5), glibc (or whatever is responsible) will use resolv.conf to expand it to the following search queries

svc1.ns2.ns1.svc.cluster.local
svc1.ns2.svc.cluster.local
svc1.ns2.cluster.local
svc1.ns2.google.internal

When the first query hits envoy, its DNS filter will most probably not have the invalid hostname svc1.ns2.ns1.svc.cluster.local. The DNs filter will then use the system's resolvers (or user provided upstream resolvers). But here is the catch. The search for various DNS search namespaces happens again.. i.e. c-ares resolver will attempt to resolve all the following
svc1.ns2.ns1.svc.cluster.local
svc1.ns2.ns1.svc.cluster.local.ns1.svc.cluster.local
svc1.ns2.ns1.svc.cluster.local.svc.cluster.local
svc1.ns2.ns1.svc.cluster.local.cluster.local
svc1.ns2.ns1.svc.cluster.local.google.internal

This literally ends up in a lot of useless queries, and much longer time to resolve DNS queries than what should usually take. The same problem happens on VMs as well. The only time this is not a problem is when someone is running Envoy as a standalone DNS server somewhere on the network, but for the other use cases, this clearly results in suboptimal behavior.

The solution is to disable the use of search namespaces when using the c-ares resolver in the DNS filter. Specifically, the dispatcher needs to have an option for this (just like use_tcp_for_dns), that then translates to c-ares' ARES_FLAG_NOSEARCH opt flag (https://c-ares.haxx.se/ares_init_options.html).

Activity

  1. added
    investigate
    on Aug 2, 2020
  2. dio commented on Aug 3, 2020

    @dio
    Member

    It seems like this is not directly related to the DNS filter (sorry for tagging you too early, @abaptiste). And I would like to highlight: #8588 (comment) and #8084 (comment). If someone wants to work on this, seems like we need to rectify "Reconcile DNS options in a single message" e.g. to have DnsLookupOptions in api/envoy/config/core/v3/base.proto (not sure about the location). That means to "push" it earlier than the "next-major-version". WDYT @lizan @mattklein123 @envoyproxy/api-shepherds? If that is OK, I can try to tackle this. Thanks!

  3. lizan commented on Aug 3, 2020

    @lizan
    Member

    As long as we follow normal deprecation / non-breaking policy, that sounds reasonable.

  4. mattklein123 commented on Aug 3, 2020

    @mattklein123
    Member

    Yup +1

  5. added
    help wanted
    and removed
    investigate
    on Aug 3, 2020
  6. suniltheta commented on Apr 19, 2021

    @suniltheta
    Contributor

    Hi, I would like to take a stab at this issue. Can someone please assign it to me? Thanks.

    Tagging for attention @mattklein123, @dio, @lizan or @asraa

  7. suniltheta commented on Jun 2, 2021

    @suniltheta
    Contributor

    Can we close this issue, now that PR #16237 is merged? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions