mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-04 20:49:06 +02:00
[management,client] Default to NetBird's upload service when nothing is configured
The previous commit made a peer with no destination — no MDM override, no URL
named by the caller, nothing published by its management server — refuse to
upload and keep the bundle local unless it was enrolled with NetBird's cloud.
That closed the reported data-boundary concern, but it broke the default for
everyone who uploads a bundle as part of their day: a self-hosted user opening
a support ticket got a refusal where the command used to work.
Product decision (NetBird's, not the reporter's): the knob to keep bundles
inside your own infrastructure is what this branch provides, and it is enough.
The default stays the service NetBird runs, self-hosted included. An admin who
needs the bundles to stay in-house configures the destination; until then the
everyday flow keeps working.
So ResolveUploadURL drops the cloud check, the sentinel error and the
managementURL argument, and never fails:
MDM > explicitly named URL > published by management > NetBird's service
Nothing observable changes for a deployment that configures nothing, which also
removes two edge cases the fail-closed default had: a peer still enrolled on the
legacy api.wiretrustee.com host would have been classified self-hosted and
refused, and an upgrade would have silently stopped uploads for self-hosted
deployments relying on them. The privilege gate is unaffected — a host other
than the default one still requires a privileged caller, so pointing the CLI
somewhere other than what management published needs root.
This commit is contained in:
@@ -1,41 +1,29 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/netbirdio/netbird/client/internal/metrics"
|
||||
"github.com/netbirdio/netbird/upload-server/types"
|
||||
)
|
||||
|
||||
// ErrNoUploadDestination reports that a bundle has nowhere to go: the
|
||||
// management server of this deployment publishes no upload service, and the
|
||||
// peer is not enrolled with NetBird's cloud either. A debug bundle carries the
|
||||
// peer's logs, routes, DNS and firewall state, so the default is to keep it
|
||||
// inside the operator's control sphere rather than fall back to the service
|
||||
// NetBird runs.
|
||||
var ErrNoUploadDestination = errors.New("this deployment publishes no debug bundle upload service; set it on the account settings or in the management server config, or pass an explicit upload URL")
|
||||
|
||||
// ResolveUploadURL decides where a debug bundle may be uploaded.
|
||||
// ResolveUploadURL decides where a debug bundle is uploaded.
|
||||
//
|
||||
// requested is a destination a caller named explicitly (a CLI flag, the daemon
|
||||
// request); it always wins, and the callers that accept one gate it separately.
|
||||
// published is what the management server of this deployment advertises, which
|
||||
// the engine holds (Engine.DebugUploadURL). With neither, only a peer enrolled
|
||||
// with NetBird's cloud falls back to the service NetBird runs — for anyone else
|
||||
// that would carry the bundle out of the deployment the operator controls, so it
|
||||
// fails closed with ErrNoUploadDestination.
|
||||
func ResolveUploadURL(requested, published, managementURL string) (string, error) {
|
||||
// requested is a destination a caller named explicitly — an MDM override, the
|
||||
// CLI's --upload-bundle-url, a remote job's upload_url; it always wins, and the
|
||||
// callers that accept one gate it separately (see requirePrivilegeForUploadURL:
|
||||
// any host other than the default needs a privileged caller). published is what
|
||||
// the management server of this deployment advertises, which the engine holds
|
||||
// (Engine.DebugUploadURL). With neither, the upload service NetBird runs is the
|
||||
// default, for a self-hosted deployment as much as for a cloud one: an operator
|
||||
// who needs the bundles to stay inside their own infrastructure points either
|
||||
// knob at their own upload service, and until they do the everyday
|
||||
// "collect a bundle and send it to support" flow keeps working.
|
||||
func ResolveUploadURL(requested, published string) string {
|
||||
if requested != "" {
|
||||
return requested, nil
|
||||
return requested
|
||||
}
|
||||
|
||||
if published != "" {
|
||||
return published, nil
|
||||
return published
|
||||
}
|
||||
|
||||
if metrics.DetermineDeploymentType(managementURL) == metrics.DeploymentTypeCloud {
|
||||
return types.DefaultBundleURL, nil
|
||||
}
|
||||
|
||||
return "", ErrNoUploadDestination
|
||||
return types.DefaultBundleURL
|
||||
}
|
||||
|
||||
@@ -4,83 +4,50 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/netbirdio/netbird/upload-server/types"
|
||||
)
|
||||
|
||||
func TestResolveUploadURL(t *testing.T) {
|
||||
const (
|
||||
cloudMgm = "https://api.netbird.io:443"
|
||||
selfHostedMgm = "https://netbird.example.com:33073"
|
||||
operatorURL = "https://upload.example.com/upload-url"
|
||||
requestedURL = "https://requested.example.com/upload-url"
|
||||
operatorURL = "https://upload.example.com/upload-url"
|
||||
requestedURL = "https://requested.example.com/upload-url"
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
requested string
|
||||
published string
|
||||
managementURL string
|
||||
want string
|
||||
wantErr bool
|
||||
name string
|
||||
requested string
|
||||
published string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "requested wins over published",
|
||||
requested: requestedURL,
|
||||
published: operatorURL,
|
||||
managementURL: selfHostedMgm,
|
||||
want: requestedURL,
|
||||
name: "requested wins over published",
|
||||
requested: requestedURL,
|
||||
published: operatorURL,
|
||||
want: requestedURL,
|
||||
},
|
||||
{
|
||||
name: "requested wins on cloud too",
|
||||
requested: requestedURL,
|
||||
managementURL: cloudMgm,
|
||||
want: requestedURL,
|
||||
name: "requested wins with nothing published",
|
||||
requested: requestedURL,
|
||||
want: requestedURL,
|
||||
},
|
||||
{
|
||||
name: "published used when nothing requested",
|
||||
published: operatorURL,
|
||||
managementURL: selfHostedMgm,
|
||||
want: operatorURL,
|
||||
name: "published used when nothing requested",
|
||||
published: operatorURL,
|
||||
want: operatorURL,
|
||||
},
|
||||
{
|
||||
// A cloud deployment publishing its own destination must not be
|
||||
// overridden by the compiled-in default.
|
||||
name: "published wins over the cloud fallback",
|
||||
published: operatorURL,
|
||||
managementURL: cloudMgm,
|
||||
want: operatorURL,
|
||||
},
|
||||
{
|
||||
name: "cloud falls back to the NetBird service",
|
||||
managementURL: cloudMgm,
|
||||
want: types.DefaultBundleURL,
|
||||
},
|
||||
{
|
||||
// The whole point of GHSA-hf99-43rj-h577: no silent hop to a
|
||||
// vendor-controlled destination.
|
||||
name: "self-hosted with no destination fails closed",
|
||||
managementURL: selfHostedMgm,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "unknown management URL fails closed",
|
||||
managementURL: "",
|
||||
wantErr: true,
|
||||
// The default stays the service NetBird runs whatever the
|
||||
// deployment: an operator who wants the bundles elsewhere says so,
|
||||
// and until then collecting one and sending it to support works.
|
||||
name: "nothing configured falls back to the NetBird service",
|
||||
want: types.DefaultBundleURL,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := ResolveUploadURL(tc.requested, tc.published, tc.managementURL)
|
||||
if tc.wantErr {
|
||||
require.ErrorIs(t, err, ErrNoUploadDestination)
|
||||
assert.Empty(t, got)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.want, got)
|
||||
assert.Equal(t, tc.want, ResolveUploadURL(tc.requested, tc.published))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,9 +230,8 @@ type Engine struct {
|
||||
// debugUploadURL is the debug-bundle upload service the management server
|
||||
// publishes for this deployment, refreshed on every NetbirdConfig update.
|
||||
// Atomic because the bundle paths (remote job, daemon RPC, mobile SDK) read
|
||||
// it off the engine loop. Empty when the deployment publishes none, which is
|
||||
// what makes a self-hosted peer keep its bundle local instead of shipping it
|
||||
// to the upload service NetBird runs.
|
||||
// it off the engine loop. Empty when the deployment publishes none, in which
|
||||
// case the callers fall back to the service NetBird runs.
|
||||
debugUploadURL atomic.Pointer[string]
|
||||
|
||||
clientCtx context.Context
|
||||
@@ -1243,8 +1242,8 @@ func (e *Engine) handleDebugUploadUpdate(config *mgmProto.DebugConfig) {
|
||||
|
||||
// DebugUploadURL returns the debug-bundle upload service the management server
|
||||
// published, or empty when it published none or the engine never synced. The
|
||||
// callers treat empty as "no destination from this deployment" and fail closed
|
||||
// unless the peer is enrolled with NetBird's cloud; see debug.ResolveUploadURL.
|
||||
// callers treat empty as "this deployment names no destination" and fall back to
|
||||
// the service NetBird runs; see debug.ResolveUploadURL.
|
||||
func (e *Engine) DebugUploadURL() string {
|
||||
if url := e.debugUploadURL.Load(); url != nil {
|
||||
return *url
|
||||
@@ -1466,10 +1465,8 @@ func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobR
|
||||
|
||||
// Resolve the upload destination: an MDM override, when set, takes
|
||||
// precedence over the job's URL. Both are validated the same way. With
|
||||
// neither, the destination this deployment publishes is used, and only a
|
||||
// peer enrolled with NetBird's cloud falls back to the service NetBird runs
|
||||
// — a self-hosted deployment that named no upload service gets no upload
|
||||
// rather than one that leaves the operator's control sphere.
|
||||
// neither, the destination this deployment publishes is used, and failing
|
||||
// that the service NetBird runs.
|
||||
uploadURL := params.GetUploadUrl()
|
||||
if override := e.config.ProfileConfig.DebugBundleUploadURL; override != "" {
|
||||
log.Infof("using MDM debug bundle upload URL override instead of the management-supplied value")
|
||||
@@ -1479,10 +1476,7 @@ func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uploadURL, err = debug.ResolveUploadURL(uploadURL, e.DebugUploadURL(), e.config.ProfileConfig.ManagementURL.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uploadURL = debug.ResolveUploadURL(uploadURL, e.DebugUploadURL())
|
||||
|
||||
bundleDeps := debug.GeneratorDependencies{
|
||||
InternalConfig: e.config.ProfileConfig,
|
||||
|
||||
Reference in New Issue
Block a user