netbirdio / netbird

Connect your devices into a secure WireGuard®-based overlay network with SSO, MFA and granular access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
11.25k stars 517 forks source link

configure.sh script fails to detect public IP on IPv6-only servers #2736

Open bannert1337 opened 1 month ago

bannert1337 commented 1 month ago

Describe the problem

The configure.sh script in the self-hosted setup fails to detect the server's public IP address when run on an IPv6-only VPS or a server with IPv6 preferred. This causes the script to exit with a JSON parsing error, preventing successful configuration of the NetBird infrastructure.

To Reproduce

  1. Set up a VPS with IPv6 enabled and preferred (e.g., on Hetzner)
  2. Clone the NetBird repository and navigate to the infrastructure_files directory
  3. Run ./configure.sh
  4. Observe the error message:
    discovering server's public IP
    parse error: Invalid numeric literal at line 3, column 0

Expected behavior

The script should successfully detect the server's public IPv4 address, or gracefully handle the case where only an IPv6 address is available. It should then proceed with the configuration without errors.

Are you using NetBird Cloud?

No, this issue occurs during self-hosted NetBird control plane setup.

NetBird version

N/A - This issue occurs during initial setup, before NetBird is fully installed.

NetBird status -dA output:

N/A - NetBird is not yet installed when this issue occurs.

Do you face any (non-mobile) client issues?

N/A - This issue is related to server setup, not client operation.

Screenshots

N/A

Additional context

The root cause appears to be that the script uses https://jsonip.com to detect the public IP, which returns an IPv6 address on IPv6-enabled servers. The script expects an IPv4 address, causing a parsing error.

A potential fix would be to use a service that consistently returns an IPv4 address, such as https://api.ipify.org?format=json, and ensure the -4 flag is used with curl to force IPv4. Alternatively, the script could be updated to handle both IPv4 and IPv6 addresses correctly.

mlsmaycon commented 1 month ago

@bannert1337, can you check if the following command returns an IPv4 address?

curl -4 https://jsonip.com
bannert1337 commented 1 month ago

@mlsmaycon output for the command:

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>403 Forbidden</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Forbidden</h1>
<h2>Your client does not have permission to get URL <code>/</code> from this server.</h2>
<h2></h2>
</body></html>

When run from a computer at my home network, I get the correct IPv4 address. The VPS has a public IPv4 and IPv6 address.