-
Notifications
You must be signed in to change notification settings - Fork 683
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
Fix host resolution on Darwin, use dig wherever possible #1986
Conversation
The `host` and `dig` commands do not return non-zero if a query returns NXDOMAIN or NOERROR, but the DarwinHostProvider was expecting it when deciding whether to fall back to IPv4 if a IPv6 query failed. Therefore, the `host` resource would not function properly when resolving hostnames on Darwin. The logic has been changed to use `dig` short output and query for both v6 and v4 addresses. Additionally, the LinuxHostProvider has been modified to prefer `dig` if it's available to keep behavior similar between Darwin and Linux whenever possible. This has the added benefit of providing v6 and v4 resolution if possible where `getent hosts` only returns v6 if v6 records exist. Signed-off-by: Adam Leff <adam@leff.co>
lib/resources/host.rb
Outdated
@@ -138,6 +140,26 @@ def missing_requirements(_protocol) | |||
# be enumerated in a skip_resource message | |||
[] | |||
end | |||
|
|||
def resolve_with_dig(hostname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like we need a new UnixHostProvider
class to map those functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can totally do that. You thinking DarwinHostProvider and LinuxHostProvider would subclass from it, and we'd move both resolve_with_bind
and resolve_with_getent
into it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly, that was my thinking.
Signed-off-by: Adam Leff <adam@leff.co>
Signed-off-by: Adam Leff <adam@leff.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice addition. Awesome work @adamleff
The
host
anddig
commands do not return non-zero if a query returns NXDOMAIN or NOERROR, but the DarwinHostProvider was expecting it when deciding whether to fall back to IPv4 if a IPv6 query failed. Therefore, thehost
resource would not function properly when resolving hostnames on Darwin. The logic has been changed to usedig
short output and query for both v6 and v4 addresses.Additionally, the LinuxHostProvider has been modified to prefer
dig
if it's available to keep behavior similar between Darwin and Linux whenever possible. This has the added benefit of providing v6 and v4 resolution if possible wheregetent hosts
only returns v6 if v6 records exist.