[client] Hint at sudo when the profile config is not readable

The agent-network commands dial management directly with the profile's
WireGuard key, and the default profile config is root-owned — running
unprivileged fails reading it. Surface a clear "re-run with sudo"
message instead of a bare permission error.

Linear: NET-1399
This commit is contained in:
mlsmaycon
2026-08-04 08:48:48 +00:00
parent 9169a36658
commit ba3db38932

View File

@@ -2,7 +2,9 @@ package cmd
import (
"context"
"errors"
"fmt"
"io/fs"
"strings"
"time"
@@ -82,6 +84,13 @@ func fetchAgentNetworkSetup(ctx context.Context) (*mgmProto.AgentNetworkSetupRes
}
config, err := profilemanager.ReadConfig(configFilePath)
if err != nil {
// The default profile config (and its WireGuard key) is owned by
// root; dialing management directly therefore needs the same
// elevation the daemon has. Point at sudo instead of surfacing a
// bare permission error.
if errors.Is(err, fs.ErrPermission) {
return nil, fmt.Errorf("reading profile %s requires elevated permissions — re-run with sudo", configFilePath)
}
return nil, fmt.Errorf("read config file %s: %v (run 'netbird up' first)", configFilePath, err)
}