mr-karan / doggo

:dog: Command-line DNS Client for Humans. Written in Golang
https://doggo.mrkaran.dev/
GNU General Public License v3.0
2.91k stars 100 forks source link

clarification needed, or maybe bug - ndot ignored #13

Closed anapsix closed 3 years ago

anapsix commented 3 years ago

First of all, thank you for doggo ๐Ÿถ

While running some tests on effect of NDOTS option in K8s pods, I've noticed a weirdness with doggo (v0.2.0 (4e5b074 2020-12-24T16:33:29Z))

The debug output suggested the ndots cli settings was ignored

# doggo --search --ndots=15 --debug -q qa-app-api.corp-qa.svc.cluster.local
DEBUG[2021-02-05T12:50:28Z] initiating UDP resolver
DEBUG[2021-02-05T12:50:28Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-05T12:50:28Z] Attempting to resolve  domain=qa-app-api.corp-qa.svc.cluster.local. nameserver="10.96.0.10:53" ndots=0
NAME                                    TYPE    CLASS   TTL ADDRESS         NAMESERVER
qa-app-api.corp-qa.svc.cluster.local.   A       IN      30s 10.108.49.117   10.96.0.10:53

I've expected to see doggo use the query as is, without adding a dot (what dig does). And then how it iterates over search domains from /etc/resolv.conf until it exhausts all possibilities and returns NXDOMAIN or succeeds.

Something like this

dig +noall +showsearch +question +answer +search +ndots=15 @10.96.0.10 qa-app-api.corp-qa.svc.cluster.local
;qa-app-api.corp-qa.svc.cluster.local.corp-qa.svc.cluster.local. IN A
;qa-app-api.corp-qa.svc.cluster.local.svc.cluster.local. IN A
;qa-app-api.corp-qa.svc.cluster.local.cluster.local. IN A
;qa-app-api.corp-qa.svc.cluster.local.dev.example.com.  IN A
;qa-app-api.corp-qa.svc.cluster.local.prod.example.com. IN A
;qa-app-api.corp-qa.svc.cluster.local. IN A
qa-app-api.corp-qa.svc.cluster.local. 30 IN A   10.108.49.117

Perhaps I'm using it wrong? Please clarify.

mr-karan commented 3 years ago

ndots=0 in that debug logs seems to be a bug. Will investigate this.

mr-karan commented 3 years ago

@anapsix Still Investigating this, looks like the ndots param isn't unmarshalled properly. Will fix this soon :)

mr-karan commented 3 years ago

Fixed this https://github.com/mr-karan/doggo/releases/tag/v0.2.3

anapsix commented 3 years ago

thanks @mr-karan

shouldn't --ndots=0 be possible and behave as if a dot was added to the query as last character? for example

$ docker run -it --rm --entrypoint /bin/sh  ghcr.io/mr-karan/doggo:latest
$ echo "search 10.0.0.1.xip.io" >> /etc/resolv.conf
$ cat /etc/resolv.conf
# This file is fetched from the host via vpnkit-bridge
nameserver 192.168.65.1
search 10.0.0.1.xip.io

$ doggo | grep VERSION -A1
VERSION:
  v0.2.3 (a8769e1 2021-02-15T04:43:12Z) - unknown

$ doggo --search --debug -q localhost.
DEBUG[2021-02-15T12:53:41Z] initiating UDP resolver
DEBUG[2021-02-15T12:53:41Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-15T12:53:41Z] Attempting to resolve                         domain=localhost. nameserver="192.168.65.1:53" ndots=1
NAME        TYPE    CLASS   TTL ADDRESS     NAMESERVER
localhost.  A       IN      1s  127.0.0.1   192.168.65.1:53

$ doggo --search --ndots=0 --debug -q localhost
DEBUG[2021-02-15T12:50:17Z] initiating UDP resolver
DEBUG[2021-02-15T12:50:17Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-15T12:50:17Z] Attempting to resolve                         domain=localhost.10.0.0.1.xip.io. nameserver="192.168.65.1:53" ndots=1
NAME                        TYPE    CLASS   TTL     ADDRESS     NAMESERVER
localhost.10.0.0.1.xip.io.  A       IN      375s    10.0.0.1    192.168.65.1:53

compare to dig

$ docker run -it --rm --entrypoint /bin/sh  ghcr.io/mr-karan/doggo:latest
$ echo "search 10.0.0.1.xip.io" >> /etc/resolv.conf
$ cat /etc/resolv.conf
# This file is fetched from the host via vpnkit-bridge
nameserver 192.168.65.1
search 10.0.0.1.xip.io

$ apk add -q bind-tools

$ dig +noall +showsearch +question +answer +search +ndots=0 localhost
;localhost.         IN  A
localhost.      1   IN  A   127.0.0.1

$ dig +noall +showsearch +question +answer +search +ndots=3 localhost
;localhost.10.0.0.1.xip.io. IN  A
localhost.10.0.0.1.xip.io. 377  IN  A   10.0.0.1
mr-karan commented 3 years ago

@anapsix I agree. ndots=0 should be valid. Can you try once more with the latest version please? :)

anapsix commented 3 years ago

ndots=0 looks good now

$ docker run -it --rm golang:alpine
$ go get github.com/mr-karan/doggo/cmd/doggo
$ echo "search 10.0.0.1.xip.io" >> /etc/resolv.conf
$ cat /etc/resolv.conf
# This file is fetched from the host via vpnkit-bridge
nameserver 192.168.65.1
search 10.0.0.1.xip.io

$ doggo --search --ndots=0 --debug -q localhost
DEBUG[2021-02-17T10:26:54Z] initiating UDP resolver
DEBUG[2021-02-17T10:26:54Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-17T10:26:54Z] Attempting to resolve                         domain=localhost. nameserver="192.168.65.1:53" ndots=0
NAME        TYPE  CLASS TTL ADDRESS   NAMESERVER
localhost.  A     IN    1s  127.0.0.1 192.168.65.1:53

$ doggo --search --ndots=1 --debug -q localhost
DEBUG[2021-02-17T10:27:00Z] initiating UDP resolver
DEBUG[2021-02-17T10:27:00Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-17T10:27:00Z] Attempting to resolve                         domain=localhost.10.0.0.1.xip.io. nameserver="192.168.65.1:53" ndots=1
NAME                        TYPE  CLASS TTL   ADDRESS   NAMESERVER
localhost.10.0.0.1.xip.io.  A     IN    377s  10.0.0.1  192.168.65.1:53

$ doggo --search --ndots=3 --debug -q localhost
DEBUG[2021-02-17T10:28:32Z] initiating UDP resolver
DEBUG[2021-02-17T10:28:32Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-17T10:28:32Z] Attempting to resolve                         domain=localhost.10.0.0.1.xip.io. nameserver="192.168.65.1:53" ndots=3
NAME                        TYPE  CLASS TTL   ADDRESS   NAMESERVER
localhost.10.0.0.1.xip.io.  A     IN    377s  10.0.0.1  192.168.65.1:53

$ doggo --search --ndots=3 --debug -q localhost.
DEBUG[2021-02-17T10:28:17Z] initiating UDP resolver
DEBUG[2021-02-17T10:28:17Z] Starting doggo ๐Ÿถ
DEBUG[2021-02-17T10:28:17Z] Attempting to resolve                         domain=localhost. nameserver="192.168.65.1:53" ndots=3
NAME        TYPE  CLASS TTL ADDRESS   NAMESERVER
localhost.  A     IN    1s  127.0.0.1 192.168.65.1:53
mr-karan commented 3 years ago

Thanks!