use embedded netbird agent for tunneling

This commit is contained in:
pascal
2026-01-15 17:03:27 +01:00
parent ed5f98da5b
commit 7527e0ebdb
10 changed files with 116 additions and 186 deletions

View File

@@ -1,9 +1,17 @@
package reverseproxy
import (
"context"
"fmt"
"time"
log "github.com/sirupsen/logrus"
"github.com/netbirdio/netbird/client/embed"
)
const (
clientStartupTimeout = 30 * time.Second
)
// AddRoute adds a new route to the proxy
@@ -20,8 +28,8 @@ func (p *Proxy) AddRoute(route *RouteConfig) error {
if len(route.PathMappings) == 0 {
return fmt.Errorf("route must have at least one path mapping")
}
if route.Conn == nil {
return fmt.Errorf("route connection (Conn) is required")
if route.SetupKey == "" {
return fmt.Errorf("route setup key is required")
}
p.mu.Lock()
@@ -32,6 +40,19 @@ func (p *Proxy) AddRoute(route *RouteConfig) error {
return fmt.Errorf("route for domain %s already exists", route.Domain)
}
client, err := embed.New(embed.Options{DeviceName: fmt.Sprintf("ingress-%s", route.ID), ManagementURL: p.config.ManagementURL, SetupKey: route.SetupKey})
if err != nil {
return fmt.Errorf("failed to create embedded client for route %s: %v", route.ID, err)
}
ctx, _ := context.WithTimeout(context.Background(), clientStartupTimeout)
err = client.Start(ctx)
if err != nil {
return fmt.Errorf("failed to start embedded client for route %s: %v", route.ID, err)
}
route.nbClient = client
// Add route with domain as key
p.routes[route.Domain] = route