fix(engine): compute default WireGuard hub IP from the CIDR network

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/portal-design
nexxo 2026-07-25 10:49:43 +02:00
parent 8a392bfd06
commit 00b8897b9d
1 changed files with 4 additions and 2 deletions

View File

@ -1,9 +1,11 @@
<?php <?php
use App\Provisioning\Steps\Host; use App\Provisioning\Steps\Host;
use Illuminate\Support\Str;
$wgSubnet = env('CLUPILOT_WG_SUBNET', '10.66.0.0/24'); $wgSubnet = env('CLUPILOT_WG_SUBNET', '10.66.0.0/24');
[$wgNetwork, $wgBits] = array_pad(explode('/', $wgSubnet), 2, '24');
$wgBase = ip2long($wgNetwork) & (0xFFFFFFFF << (32 - (int) $wgBits)) & 0xFFFFFFFF;
$wgHubDefault = long2ip($wgBase + 1); // first usable address in the CIDR
return [ return [
/* /*
@ -29,7 +31,7 @@ return [
// CluPilot VM acts as the WireGuard hub; hosts join it during onboarding. // CluPilot VM acts as the WireGuard hub; hosts join it during onboarding.
'wireguard' => [ 'wireguard' => [
'subnet' => $wgSubnet, 'subnet' => $wgSubnet,
'hub_ip' => env('CLUPILOT_WG_HUB_IP', Str::beforeLast($wgSubnet, '.').'.1'), // handshake target 'hub_ip' => env('CLUPILOT_WG_HUB_IP', $wgHubDefault), // handshake target
'endpoint' => env('CLUPILOT_WG_ENDPOINT', ''), // host:port reachable by peers 'endpoint' => env('CLUPILOT_WG_ENDPOINT', ''), // host:port reachable by peers
'hub_public_key' => env('CLUPILOT_WG_HUB_PUBKEY', ''), 'hub_public_key' => env('CLUPILOT_WG_HUB_PUBKEY', ''),
'config_path' => env('CLUPILOT_WG_CONFIG_PATH', '/etc/wireguard/wg0.conf'), 'config_path' => env('CLUPILOT_WG_CONFIG_PATH', '/etc/wireguard/wg0.conf'),