Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: authenticate dashboard/orchestrator calls to child instances

Jamil Zakirov048dd05ac611
diff --git a/internal/dashboard/dashboard.go b/internal/dashboard/dashboard.go
index 088b9910..ff73a183 100644
--- a/internal/dashboard/dashboard.go
+++ b/internal/dashboard/dashboard.go
@@ -8,6 +8,7 @@ import (
"fmt"
"io/fs"
"net/http"
+ "os"
"strings"
"sync"
"time"
@@ -55,12 +56,13 @@ type InstanceLister interface {
}
type Dashboard struct {
- cfg DashboardConfig
- agents map[string]*AgentActivity
- sseConns map[chan AgentEvent]struct{}
- cancel context.CancelFunc
- instances InstanceLister
- mu sync.RWMutex
+ cfg DashboardConfig
+ agents map[string]*AgentActivity
+ sseConns map[chan AgentEvent]struct{}
+ cancel context.CancelFunc
+ instances InstanceLister
+ childAuthToken string
+ mu sync.RWMutex
}
// SetInstanceLister sets the orchestrator for aggregating agents from child instances.
@@ -116,6 +118,9 @@ func (d *Dashboard) subscribeChildSSE(ctx context.Context, port, profileName str
if err != nil {
return
}
+ if d.childAuthToken != "" {
+ req.Header.Set("Authorization", "Bearer "+d.childAuthToken)
+ }
client := &http.Client{Timeout: 0} // no timeout for SSE
resp, err := client.Do(req)
if err != nil {
@@ -184,10 +189,11 @@ func NewDashboard(cfg *DashboardConfig) *Dashboard {
ctx, cancel := context.WithCancel(context.Background())
d := &Dashboard{
- cfg: c,
- agents: make(map[string]*AgentActivity),
- sseConns: make(map[chan AgentEvent]struct{}),
- cancel: cancel,
+ cfg: c,
+ agents: make(map[string]*AgentActivity),
+ sseConns: make(map[chan AgentEvent]struct{}),
+ cancel: cancel,
+ childAuthToken: os.Getenv("BRIDGE_TOKEN"),
}
go d.reaper(ctx)
return d
diff --git a/internal/orchestrator/health.go b/internal/orchestrator/health.go
index 1e07472e..a64d02d8 100644
--- a/internal/orchestrator/health.go
+++ b/internal/orchestrator/health.go
@@ -36,7 +36,15 @@ func (o *Orchestrator) monitor(inst *InstanceInternal) {
time.Sleep(instanceHealthPollInterval)
for _, baseURL := range instanceBaseURLs(inst.Port) {
- resp, err := o.client.Get(baseURL + "/health")
+ req, reqErr := http.NewRequest(http.MethodGet, baseURL+"/health", nil)
+ if reqErr != nil {
+ lastProbe = fmt.Sprintf("%s -> %s", baseURL, reqErr.Error())
+ continue
+ }
+ if o.childAuthToken != "" {
+ req.Header.Set("Authorization", "Bearer "+o.childAuthToken)
+ }
+ resp, err := o.client.Do(req)
if err == nil {
_ = resp.Body.Close()
lastProbe = fmt.Sprintf("%s -> HTTP %d", baseURL, resp.StatusCode)
@@ -103,7 +111,15 @@ type remoteTab struct {
}
func (o *Orchestrator) fetchTabs(baseURL string) ([]remoteTab, error) {
- resp, err := o.client.Get(baseURL + "/screencast/tabs")
+ req, err := http.NewRequest(http.MethodGet, baseURL+"/screencast/tabs", nil)
+ if err != nil {
+ return nil, err
+ }
+ if o.childAuthToken != "" {
+ req.Header.Set("Authorization", "Bearer "+o.childAuthToken)
+ }
+
+ resp, err := o.client.Do(req)
if err != nil {
return nil, err
}
diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go
index f4bac1e3..b47ad0ad 100644
--- a/internal/orchestrator/orchestrator.go
+++ b/internal/orchestrator/orchestrator.go
@@ -17,13 +17,14 @@ import (
)
type Orchestrator struct {
- instances map[string]*InstanceInternal
- baseDir string
- binary string
- profiles *profiles.ProfileManager
- runner HostRunner
- mu sync.RWMutex
- client *http.Client
+ instances map[string]*InstanceInternal
+ baseDir string
+ binary string
+ profiles *profiles.ProfileManager
+ runner HostRunner
+ mu sync.RWMutex
+ client *http.Client
+ childAuthToken string
}
type InstanceInternal struct {
@@ -67,11 +68,12 @@ func NewOrchestratorWithRunner(baseDir string, runner HostRunner) *Orchestrator
}
return &Orchestrator{
- instances: make(map[string]*InstanceInternal),
- baseDir: baseDir,
- binary: binary,
- runner: runner,
- client: &http.Client{Timeout: 3 * time.Second},
+ instances: make(map[string]*InstanceInternal),
+ baseDir: baseDir,
+ binary: binary,
+ runner: runner,
+ client: &http.Client{Timeout: 3 * time.Second},
+ childAuthToken: os.Getenv("BRIDGE_TOKEN"),
}
}