From d7fa38b7e192b8bc8e72e88010c96fdd927d0561 Mon Sep 17 00:00:00 2001 From: Maxime Mouchet Date: Tue, 28 Sep 2021 19:41:53 +0200 Subject: [PATCH] node: always get the public IPv4 from an external service to handle NATed cloud nodes --- main.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e5ea3dd..669b0a7 100644 --- a/main.go +++ b/main.go @@ -124,23 +124,21 @@ func getHostnameRoot(platform string) string { func getIPv4(platform string) (net.IP, net.IP) { switch platform { case platforms.Azure: - // The NIC public IP is not available through Azure metadata... - // https://docs.microsoft.com/en-us/answers/questions/7932/public-ip-not-available-via-metadata.html localIP := net.ParseIP(platforms.AzureGetMetadata("network/interface/0/ipv4/ipAddress/0/privateIpAddress")) publicIP := network.PublicIPv4() return localIP, publicIP case platforms.EC2: localIP := net.ParseIP(platforms.EC2GetMetadata("local-ipv4")) - publicIP := net.ParseIP(platforms.EC2GetMetadata("public-ipv4")) + publicIP := network.PublicIPv4() return localIP, publicIP case platforms.GCP: localIP := net.ParseIP(platforms.GCPGetMetadata("instance/network-interfaces/0/ip")) - publicIP := net.ParseIP(platforms.GCPGetMetadata("instance/network-interfaces/0/access-configs/0/external-ip")) + publicIP := network.PublicIPv4() return localIP, publicIP case platforms.SCW: meta := platforms.SCWGetMetadata() localIP := net.ParseIP(meta.PrivateIP) - publicIP := net.ParseIP(meta.PublicIP.Address) + publicIP := network.PublicIPv4() return localIP, publicIP default: localIP := network.LocalIPv4()