fix: enforce reserved ports in HTTP allocation and improve admin gRPC fallback
Critical fixes for port allocation safety:
1. Make findAvailablePortOnIP and ensurePortAvailableOnIP aware of reservedPorts:
- Add reservedPorts map parameter to both functions
- findAvailablePortOnIP now skips reserved ports when searching for alternatives
- ensurePortAvailableOnIP passes reservedPorts through to findAvailablePortOnIP
- This prevents HTTP ports from being allocated to ports reserved for gRPC
2. Update ensureAllPortsAvailableOnIP to pass reservedPorts:
- Pass the reservedPorts map to ensurePortAvailableOnIP calls
- Maintains the map updates (delete/add) for accuracy as ports change
3. Replace blind admin gRPC port fallback with proper availability checks:
- Previous code just calculated *miniAdminOptions.port + GrpcPortOffset
- New code checks both the calculated port and finds alternatives if needed
- Uses the same availability checking logic as initializeGrpcPortsOnIP
- Properly logs the fallback process and any port changes
- Will fail gracefully if no available ports found (consistent with other services)
These changes eliminate two critical vulnerabilities:
- HTTP port allocation can no longer accidentally claim gRPC ports
- Admin gRPC port fallback no longer blindly uses an unchecked port
glog.Errorf("Could not find available gRPC port for %s starting from %d, will use calculated %d and fail on binding",config.name,calculatedPort+1,calculatedPort)
glog.Errorf("Could not find available gRPC port for %s starting from %d, will use original %d and fail on binding",config.name,*config.grpcPort+1,*config.grpcPort)
glog.Errorf("Could not find available gRPC port for Admin starting from %d, will use calculated %d and fail on binding",calculatedPort+1,calculatedPort)
*miniAdminOptions.grpcPort=calculatedPort
}else{
glog.Infof("Fallback: using gRPC port %d for Admin",newPort)
*miniAdminOptions.grpcPort=newPort
}
}else{
*miniAdminOptions.grpcPort=calculatedPort
glog.Infof("Fallback: Admin gRPC port initialized to %d",calculatedPort)