mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-08 06:29:08 +02:00
[management,client] Take the debug-bundle upload destination from management
The debug-bundle paths that upload without a human picking a destination compiled the vendor endpoint in: the mobile clients and the desktop UI hold `https://upload.debug.netbird.io/upload-url` as a constant, the CLI defaults its flag to it, and the remote job falls back to it when nothing else is set. A self-hosted deployment therefore shipped peer logs, routes, DNS and firewall state to NetBird-run infrastructure without its operator ever configuring that, and had no way to point those paths anywhere else. #7147 and #7153 gave the remote job a per-job URL and an MDM override, but neither reaches the mobile, UI or CLI paths, and both fail open when unset. Publish the destination from the management server instead, on the channel that already carries stun/turn/signal/relay/flow/metrics: - `NetbirdConfig.debug.upload_url`, sourced from the new account setting `debug_bundle_upload_url` (REST + dashboard) and falling back to the new `DebugUpload.URL` in the management server config, which a self-hosted install can set once so a fresh account is not left on the vendor default. Both are validated as https-with-host where they are written; a change fans out to connected peers rather than waiting for the next login. - One resolver on the client, `debug.ResolveUploadURL`, used by every path: MDM override > explicitly named URL > destination published by management > the NetBird service, but only for a peer enrolled with NetBird's cloud. Anything else fails closed with ErrNoUploadDestination and the bundle stays local, which is the behaviour change: a self-hosted deployment that names no upload service no longer uploads at all. - The engine keeps the published value (`Engine.DebugUploadURL`) so the bundle paths, which run off the engine loop, do not have to read it back out of the opt-in sync-response store. - The daemon request grows `upload`, so "upload to wherever this deployment says" is expressible; an empty `uploadURL` no longer has to mean "no upload". The privilege gate is unchanged and still applies only to a URL the local caller named — a destination published by management is the operator naming their own service. - The desktop UI stops carrying a vendor URL of its own and sends the intent. Reported privately as GHSA-hf99-43rj-h577.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/idp"
|
||||
"github.com/netbirdio/netbird/management/server/types"
|
||||
@@ -57,6 +60,10 @@ type Config struct {
|
||||
|
||||
AgentNetwork AgentNetwork
|
||||
|
||||
// DebugUpload configures where the peers of this deployment send their
|
||||
// debug bundles. See DebugUpload.
|
||||
DebugUpload DebugUpload
|
||||
|
||||
// disable default all-to-all policy
|
||||
DisableDefaultPolicy bool
|
||||
|
||||
@@ -206,6 +213,48 @@ type AgentNetwork struct {
|
||||
PricingDefaultsFile string
|
||||
}
|
||||
|
||||
// DebugUpload configures the debug-bundle upload service this deployment
|
||||
// publishes to its peers.
|
||||
//
|
||||
// The client paths that upload without a human picking a destination — the
|
||||
// remote debug-bundle job, the mobile clients and the desktop UI — take the
|
||||
// destination from here. It exists so a self-hosted deployment keeps its
|
||||
// bundles, which carry peer logs, routes, DNS and firewall state, inside the
|
||||
// operator's own control sphere instead of reaching the upload service NetBird
|
||||
// runs. Leaving it unset publishes no destination: a peer enrolled with
|
||||
// NetBird's cloud still uses NetBird's service, a self-hosted peer keeps the
|
||||
// bundle local.
|
||||
//
|
||||
// Set URL to the upload service's get-URL endpoint, e.g.
|
||||
// https://upload.example.com/upload-url (see the upload-server component).
|
||||
type DebugUpload struct {
|
||||
// URL is the get-URL endpoint of the upload service. Must be https: the
|
||||
// client fetches an upload URL from it and then PUTs the bundle to whatever
|
||||
// that fetch returns, so a plaintext hop is a place to intercept both.
|
||||
URL string
|
||||
}
|
||||
|
||||
// Validate rejects a destination the client would refuse anyway, so a typo in
|
||||
// management.json surfaces at startup instead of at the first bundle upload.
|
||||
func (d DebugUpload) Validate() error {
|
||||
if d.URL == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(d.URL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse debug upload URL: %w", err)
|
||||
}
|
||||
if parsed.Scheme != "https" {
|
||||
return fmt.Errorf("debug upload URL must use https, got scheme %q", parsed.Scheme)
|
||||
}
|
||||
if parsed.Host == "" {
|
||||
return errors.New("debug upload URL must have a host")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReverseProxy contains reverse proxy configuration in front of management.
|
||||
type ReverseProxy struct {
|
||||
// TrustedHTTPProxies represents a list of trusted HTTP proxies by their IP prefixes.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDebugUploadValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
wantErr string
|
||||
}{
|
||||
{name: "unset publishes no destination", url: ""},
|
||||
{name: "https accepted", url: "https://upload.example.com/upload-url"},
|
||||
{name: "https with port accepted", url: "https://upload.example.com:8443/upload-url"},
|
||||
// The client fetches an upload URL from this endpoint and then PUTs the
|
||||
// bundle to whatever comes back, so a plaintext hop intercepts both.
|
||||
{name: "http refused", url: "http://upload.example.com/upload-url", wantErr: "must use https"},
|
||||
{name: "scheme-less refused", url: "upload.example.com/upload-url", wantErr: "must use https"},
|
||||
{name: "host-less refused", url: "https:///upload-url", wantErr: "must have a host"},
|
||||
{name: "unparsable refused", url: "https://upload.example.com:port", wantErr: "parse debug upload URL"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := DebugUpload{URL: tc.url}.Validate()
|
||||
if tc.wantErr == "" {
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), tc.wantErr)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user