octodns / octodns-bind

RFC compliant (Bind9) provider for octoDNS
MIT License
7 stars 10 forks source link

Unable to Perform Zone Transfer: The DNS query name does not exist: localhost #24

Closed ross closed 1 year ago

ross commented 1 year ago

While looking into a test failure related to https://github.com/octodns/octodns/pull/1004 I pulled the lasted code and tried to run tests, but got a failure to resolve localhost?

tests/test_provider_octodns_bind.py:28: in <module>
    class TestAxfrSource(TestCase):
tests/test_provider_octodns_bind.py:29: in TestAxfrSource
    source = AxfrSource('test', 'localhost')
octodns_bind/__init__.py:165: in __init__
    self.host = self._host(host)
octodns_bind/__init__.py:180: in _host
    raise AxfrSourceZoneTransferFailed(err) from None
E   octodns_bind.AxfrSourceZoneTransferFailed: Unable to Perform Zone Transfer: The DNS query name does not exist: localhost.

Guessing this is related to https://github.com/octodns/octodns-bind/pull/22 and localhost isn't resolving when looked up on my computer/network. My first thought is to change the name there to an IP address...

yzguy commented 1 year ago

Interesting.

If you do this below and see if it resolves.

>>> import dns.resolver
>>> dns.resolver.resolve('localhost')[0].address
'127.0.0.1'
ross commented 1 year ago
>>> import dns.resolver
>>> dns.resolver.resolve('localhost')[0].address
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ross/octodns/octodns-bind/env/lib/python3.10/site-packages/dns/resolver.py", line 1368, in resolve
    return get_default_resolver().resolve(
  File "/Users/ross/octodns/octodns-bind/env/lib/python3.10/site-packages/dns/resolver.py", line 1190, in resolve
    (request, answer) = resolution.next_request()
  File "/Users/ross/octodns/octodns-bind/env/lib/python3.10/site-packages/dns/resolver.py", line 691, in next_request
    raise NXDOMAIN(qnames=self.qnames_to_try, responses=self.nxdomain_responses)
dns.resolver.NXDOMAIN: The DNS query name does not exist: localhost.
ross commented 1 year ago

Fix over in https://github.com/octodns/octodns-bind/pull/25

yzguy commented 1 year ago

Oh this probably happens because dns.resolver does actually query a resolver immediately and doesn't go through the normal chain of things (host file, etc.) before making it. So in some cases you have like systemd-resolved dealing with that or whatever resolver may be running locally on the machine and then going to a real resolver, but if your resolver is 1.1.1.1 or something and it queries it, you won't get anything.

Interesting, may need to change that so it does the actual looking into host file, etc or just handle the localhost -> 127.0.0.1 in the code (which I don't love). Probably need to use socket.gethostbyname