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

Packer 1.5.6+ does not use macOS system DNS resolver and cannot connect to host #9710

Closed
VladRassokhin opened this issue Aug 5, 2020 · 10 comments · Fixed by #11564
Closed
Labels
bug core Core components of Packer crt common release tooling issue

Comments

@VladRassokhin
Copy link
Contributor

VladRassokhin commented Aug 5, 2020

Overview of the Issue

Got "Timeout waiting for SSH" due to Packer's inability to correctly resolve host name, details and logs below.
Had to rollback to 1.5.5.

ping -c1 ssh_host correctly resolves DNS and works.

Reproduction Steps

packer-1.5.6 build -var ssh_host=HOST.DOMAIN config.json

Packer version

Packer v1.5.6
Packer v1.6.1

Simplified Packer Buildfile

{
  "builders": [
    {
      "type": "null",
      "communicator": "ssh",
      "ssh_host": "{{user `ssh_host`}}",
      "ssh_username": "Administrator",
      "ssh_timeout": "15s",
      "ssh_agent_auth": true
    }
  ]
}

Operating system and Environment details

Mac OS X 10.14.6 18G6020
Env:

  • GODEBUG="netdns=1"
  • PACKER_LOG=1

Computer is connected to corporate network using VPN.
192.168.0.1 is IP address of WiFi router.

`/etc/resolv.conf` content
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver 192.168.0.1
`scutil --dns`
DNS configuration

resolver #1
  search domain[0] : DOMAIN
  search domain[1] : consul
  search domain[2] : test
  search domain[3] : DOMAIN_2
  nameserver[0] : 192.168.0.1
  if_index : 10 (en0)
  flags    : Request A records
  reach    : 0x00020002 (Reachable,Directly Reachable Address)

resolver #2
  domain   : consul
  nameserver[0] : CORPORATE_NAMESERVER_1
  nameserver[1] : CORPORATE_NAMESERVER_2
  if_index : 19 (ipsec0)
  flags    : Supplemental, Request A records
  reach    : 0x00000003 (Reachable,Transient Connection)
  order    : 101001

resolver #3
  domain   : DOMAIN_2
  nameserver[0] : CORPORATE_NAMESERVER_1
  nameserver[1] : CORPORATE_NAMESERVER_2
  if_index : 19 (ipsec0)
  flags    : Supplemental, Request A records
  reach    : 0x00000003 (Reachable,Transient Connection)
  order    : 101003

resolver #4
  domain   : local
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300000

resolver #5
  domain   : DOMAIN
  nameserver[0] : CORPORATE_NAMESERVER_1
  nameserver[1] : CORPORATE_NAMESERVER_2
  if_index : 19 (ipsec0)
  flags    : Supplemental, Request A records
  reach    : 0x00000003 (Reachable,Transient Connection)
  order    : 101000

resolver #6
  domain   : test
  nameserver[0] : CORPORATE_NAMESERVER_1
  nameserver[1] : CORPORATE_NAMESERVER_2
  if_index : 19 (ipsec0)
  flags    : Supplemental, Request A records
  reach    : 0x00000003 (Reachable,Transient Connection)
  order    : 101002

resolver #7
  domain   : 254.169.in-addr.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300200

resolver #8
  domain   : 8.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300400

resolver #9
  domain   : 9.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300600

resolver #10
  domain   : a.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300800

resolver #11
  domain   : b.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 301000

DNS configuration (for scoped queries)

resolver #1
  nameserver[0] : 192.168.0.1
  if_index : 10 (en0)
  flags    : Scoped, Request A records
  reach    : 0x00020002 (Reachable,Directly Reachable Address)

resolver #2
  search domain[0] : DOMAIN
  search domain[1] : DOMAIN_2
  nameserver[0] : CORPORATE_NAMESERVER_1
  nameserver[1] : CORPORATE_NAMESERVER_2
  if_index : 19 (ipsec0)
  flags    : Scoped, Request A records
  reach    : 0x00000003 (Reachable,Transient Connection)

Log Fragments and crash.log files

Packer 1.5.5 log
==> null: Waiting for SSH to become available...
2020/08/05 12:36:28 packer-1.5.5 plugin: go package net: using cgo DNS resolver
2020/08/05 12:36:31 packer-1.5.5 plugin: [INFO] Attempting SSH connection to HOST.DOMAIN:22...
2020/08/05 12:36:31 packer-1.5.5 plugin: [DEBUG] reconnecting to TCP connection for SSH
Packer 1.5.6 log
==> null: Waiting for SSH to become available...
2020/08/05 12:38:52 packer-1.5.6 plugin: go package net: built with netgo build tag; using Go's DNS resolver
2020/08/05 12:36:52 packer-1.5.6 plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp: lookup HOST.DOMAIN on 192.168.0.1:53: no such host
2020/08/05 12:36:57 packer-1.5.6 plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp: lookup HOST.DOMAIN on 192.168.0.1:53: no such host
@sylviamoss sylviamoss added the core Core components of Packer label Aug 5, 2020
@SwampDragons
Copy link
Contributor

Hi thanks for reaching out. Based on timing and on those debug lines from the net library, I'm going to guess this was caused by f12269f

We disabled cgo compilation because it started messing up static linking once we started building our release builds on linux; we didn't realize it was going to break this but it sounds like the golang net library isn't quite up to par with how cgo was for darwin.

For now, the workaround is to rebuild packer yourself without the cgo disabling. You can do this by cloning the repo, making sure

const VersionPrerelease = "dev"
has the "dev" tag set rather than an empty string, and calling make dev from Packer's root directory. This will add a new packer binary to bin/packer inside your packer root.

I'll try to figure out how to change this for future releases.

@TheRedBull
Copy link

@VladRassokhin I can confirm that building packer (latest (1.6.2)) from the repo fixes this as I attempted it last night. Incidentally, the 1.6.2 build seems to have also fixed a like hanging Ubuntu install issue I was having in my Windows lab

@VladRassokhin
Copy link
Contributor Author

Personally I'm happy with 1.5.5 for now, though I'd like to see that somehow fixed in newest official releases. I do understand that test for such case is quite complicated.

@marco-m
Copy link
Contributor

marco-m commented Aug 21, 2020

@TheRedBull for my understanding, when you say:

I can confirm that building packer (latest (1.6.2)) from the repo fixes this as I attempted it last night.

are you building from macOS ? If yes, with what command-line?

For me, macOS build, at least using make, is broken, since scripts/build.sh wants realpath that doesn't exist on macoS. Or did you brew install coreutils to get realpath ?

@azr
Copy link
Contributor

azr commented Aug 21, 2020

@marco-m, you can try with the Nightly build: https://github.com/hashicorp/packer/releases/tag/nightly

@nywilken
Copy link
Contributor

nywilken commented Aug 21, 2020

@marco-m the default make target is setup to use the Packer build script which is meant for releasing. I'll see about changing that for the future. In the meantime, the correct command to run is make dev which should compile using the standard Go build tools.

@azr I think the latest nightly releases are also using Linux with CGO disabled so DNS may still be an issue. But @marco-m you can give it a try. Otherwise the path forward, for now, is to build locally on your Mac using make dev.

@marco-m
Copy link
Contributor

marco-m commented Aug 21, 2020

Thanks both @azr and @nywilken, I will try the suggestions. I don't want to hijack this thread, I might open another ticket: .github/CONTRIBUTING.md is severely out of date and gives the impression that you can build on macOS (or Windows for that matter) with a plain make, while it is not the case.

@SwampDragons
Copy link
Contributor

@marco-m no need for another issue. I'll make a Pr to change the default make target to not require that script; we don't release using that command anyway.

@VladRassokhin
Copy link
Contributor Author

VladRassokhin commented Feb 9, 2022

So, any updates over 1.5 years?
Still not working in latest release (1.7.10)

@nywilken
Copy link
Contributor

So, any updates over 1.5 years? Still not working in latest release (1.7.10)

We are working on updating our release processes, which will help in addressing this issue.

@azr azr added the crt common release tooling issue label Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core Core components of Packer crt common release tooling issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants