From 133eb1d45049132d380a575b044115d34939bc8f Mon Sep 17 00:00:00 2001 From: Chris Friesen Date: Wed, 22 Jul 2020 18:01:07 -0400 Subject: [PATCH] Fix run_docker_login DNS lookup to handle misconfigured nameservers A customer added a non-existant nameserver and it resulted in an edge case that broke the previous code. (dig returned 9 even though it found an AAAA record for the name.) It looks like we're going to need to bite the bullet and explicitly issue separate requests for IPv4 and IPv6. Partial-Bug: 1886121 Change-Id: I8d653a82a2aee0a86af587f6392277974c9f1fef Signed-off-by: Chris Friesen --- sysinv/sysinv-fpga-agent/run_docker_login | 29 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/sysinv/sysinv-fpga-agent/run_docker_login b/sysinv/sysinv-fpga-agent/run_docker_login index 4824f44a8d..08a828a151 100644 --- a/sysinv/sysinv-fpga-agent/run_docker_login +++ b/sysinv/sysinv-fpga-agent/run_docker_login @@ -21,10 +21,14 @@ function LOG { LOG "Waiting for registry.local to resolve" while true do - # This will ask for both A and AAAA records to handle IPv4 and IPv6. - # We don't want to do an ANY request because some DNS servers reject - # them and they can return way more data than we actually want. - ADDR=`dig +short registry.local A registry.local AAAA` + # We can't easily ask for both A and AAAA records in the same request + # because if the customer mis-configures things with a "good" nameserver + # and a non-existant nameserver dig will return "9" even though it finds + # an AAAA record on the "good" server. So we need to ask for A and AAAA + # records separately. Once we have either type of record we can proceed. + + # First check for A records for IPv4 + ADDR=`dig +short registry.local A` if [ $? -eq 0 ] then # We got a response back from the server, but we need to check @@ -32,10 +36,25 @@ do # be an empty string. if [ -n "$ADDR" ] then - echo LOG "registry.local resolved, continuing with docker login" + echo LOG "registry.local resolved IPv4, continuing with docker login" break fi fi + + # Then check for AAAA records for IPv6 + ADDR=`dig +short registry.local AAAA` + if [ $? -eq 0 ] + then + # We got a response back from the server, but we need to check + # if we got an address or not. If there is no address, ADDR will + # be an empty string. + if [ -n "$ADDR" ] + then + echo LOG "registry.local resolved IPv6, continuing with docker login" + break + fi + fi + sleep 1 done