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

Azure/personal/dns warning #78

Merged
merged 17 commits into from
Sep 8, 2023
20 changes: 20 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ is_ip_port_reachable()
nc -w 3 -z $ip $port > /dev/null 2>&1
}

#
# Check if the desired entry is present in /etc/hosts
#
is_present_in_etc_hosts() {
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
local ip="$1"
local hostname="$2"

while IFS= read -r entry; do
# Check if the line is not commented
if ! [[ "$entry" =~ ^[[:space:]]*# ]]; then
# Check if corresponding entry for IP and hostname is present
if echo "$entry" | grep -qE "^[[:space:]]*$ip[[:space:]]*$hostname"; then
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
return 0
fi
fi
done < /etc/hosts

return 1
}

#
# Blob fqdn to IPv4 adddress.
# Caller must make sure that it is called only for hostname and not IP address.
Expand Down
8 changes: 8 additions & 0 deletions src/aznfswatchdog
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ while :; do
continue
fi

#
# Warn if the desired resolution entry is added in /etc/hosts after mount is success
#
if is_present_in_etc_hosts "$new_ip" "$l_host"; then
wecho "[WARNING] Detected static resolution entry for "$l_host" in /etc/hosts."
wecho "[Action Required]: Remove the entry for "$l_host" in /etc/hosts to ensure correctly handling endpoint IP address changes by AZNFS"
fi

#
# If the IP changed for the Blob endpoint, we need to update the DNAT rule.
# This will take care of migration/failover causing the Blob endpoint IP to change.
Expand Down
12 changes: 12 additions & 0 deletions src/mountscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,25 @@ if ! is_valid_blob_fqdn "$nfs_host"; then
exit 1
fi

# Resolve the IP address for the NFS host
nfs_ip=$(resolve_ipv4 "$nfs_host")
if [ $? -ne 0 ]; then
echo "$nfs_ip"
eecho "Cannot resolve IP address for ${nfs_host}!"
exit 1
fi

#
# Check if the IP-FQDN pair is present in /etc/hosts
# Fail mount if the hostname entry is present in /etc/hosts
#
if is_present_in_etc_hosts "$nfs_ip" "$nfs_host"; then
eecho "Mount failed!"
eecho "Detected entry $nfs_ip $nfs_host in /etc/hosts."
eecho "[Action Required]: Remove or comment out the entry $nfs_ip $nfs_host in /etc/hosts for MOUNT to work."
exit 1
fi

nfs_dir=$(get_dir_from_share "$1")
if [ $? -ne 0 ]; then
echo "$nfs_dir"
Expand Down