mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-06 00:56:39 +00:00
Compare commits
1 Commits
mlsmaycon-
...
fix/debug-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cb25de9ea |
@@ -607,6 +607,12 @@ func (g *BundleGenerator) addCommonConfigFields(configContent *strings.Builder)
|
|||||||
if g.internalConfig.EnableSSHRemotePortForwarding != nil {
|
if g.internalConfig.EnableSSHRemotePortForwarding != nil {
|
||||||
configContent.WriteString(fmt.Sprintf("EnableSSHRemotePortForwarding: %v\n", *g.internalConfig.EnableSSHRemotePortForwarding))
|
configContent.WriteString(fmt.Sprintf("EnableSSHRemotePortForwarding: %v\n", *g.internalConfig.EnableSSHRemotePortForwarding))
|
||||||
}
|
}
|
||||||
|
if g.internalConfig.DisableSSHAuth != nil {
|
||||||
|
configContent.WriteString(fmt.Sprintf("DisableSSHAuth: %v\n", *g.internalConfig.DisableSSHAuth))
|
||||||
|
}
|
||||||
|
if g.internalConfig.SSHJWTCacheTTL != nil {
|
||||||
|
configContent.WriteString(fmt.Sprintf("SSHJWTCacheTTL: %d\n", *g.internalConfig.SSHJWTCacheTTL))
|
||||||
|
}
|
||||||
|
|
||||||
configContent.WriteString(fmt.Sprintf("DisableClientRoutes: %v\n", g.internalConfig.DisableClientRoutes))
|
configContent.WriteString(fmt.Sprintf("DisableClientRoutes: %v\n", g.internalConfig.DisableClientRoutes))
|
||||||
configContent.WriteString(fmt.Sprintf("DisableServerRoutes: %v\n", g.internalConfig.DisableServerRoutes))
|
configContent.WriteString(fmt.Sprintf("DisableServerRoutes: %v\n", g.internalConfig.DisableServerRoutes))
|
||||||
@@ -633,6 +639,7 @@ func (g *BundleGenerator) addCommonConfigFields(configContent *strings.Builder)
|
|||||||
}
|
}
|
||||||
|
|
||||||
configContent.WriteString(fmt.Sprintf("LazyConnectionEnabled: %v\n", g.internalConfig.LazyConnectionEnabled))
|
configContent.WriteString(fmt.Sprintf("LazyConnectionEnabled: %v\n", g.internalConfig.LazyConnectionEnabled))
|
||||||
|
configContent.WriteString(fmt.Sprintf("MTU: %d\n", g.internalConfig.MTU))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *BundleGenerator) addProf() (err error) {
|
func (g *BundleGenerator) addProf() (err error) {
|
||||||
|
|||||||
@@ -5,16 +5,21 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/anonymize"
|
"github.com/netbirdio/netbird/client/anonymize"
|
||||||
"github.com/netbirdio/netbird/client/configs"
|
"github.com/netbirdio/netbird/client/configs"
|
||||||
|
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||||
|
"github.com/netbirdio/netbird/shared/management/domain"
|
||||||
mgmProto "github.com/netbirdio/netbird/shared/management/proto"
|
mgmProto "github.com/netbirdio/netbird/shared/management/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -766,3 +771,127 @@ Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
|
|||||||
assert.Contains(t, anonNftables, "chain input {")
|
assert.Contains(t, anonNftables, "chain input {")
|
||||||
assert.Contains(t, anonNftables, "type filter hook input priority filter; policy accept;")
|
assert.Contains(t, anonNftables, "type filter hook input priority filter; policy accept;")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAddConfig_AllFieldsCovered uses reflection to ensure every field in
|
||||||
|
// profilemanager.Config is either rendered in the debug bundle or explicitly
|
||||||
|
// excluded. When a new field is added to Config, this test fails until the
|
||||||
|
// developer either dumps it in addConfig/addCommonConfigFields or adds it to
|
||||||
|
// the excluded set with a justification.
|
||||||
|
func TestAddConfig_AllFieldsCovered(t *testing.T) {
|
||||||
|
excluded := map[string]string{
|
||||||
|
"PrivateKey": "sensitive: WireGuard private key",
|
||||||
|
"PreSharedKey": "sensitive: WireGuard pre-shared key",
|
||||||
|
"SSHKey": "sensitive: SSH private key",
|
||||||
|
"ClientCertKeyPair": "non-config: parsed cert pair, not serialized",
|
||||||
|
}
|
||||||
|
|
||||||
|
mURL, _ := url.Parse("https://api.example.com:443")
|
||||||
|
aURL, _ := url.Parse("https://admin.example.com:443")
|
||||||
|
bTrue := true
|
||||||
|
iVal := 42
|
||||||
|
cfg := &profilemanager.Config{
|
||||||
|
PrivateKey: "priv",
|
||||||
|
PreSharedKey: "psk",
|
||||||
|
ManagementURL: mURL,
|
||||||
|
AdminURL: aURL,
|
||||||
|
WgIface: "wt0",
|
||||||
|
WgPort: 51820,
|
||||||
|
NetworkMonitor: &bTrue,
|
||||||
|
IFaceBlackList: []string{"eth0"},
|
||||||
|
DisableIPv6Discovery: true,
|
||||||
|
RosenpassEnabled: true,
|
||||||
|
RosenpassPermissive: true,
|
||||||
|
ServerSSHAllowed: &bTrue,
|
||||||
|
EnableSSHRoot: &bTrue,
|
||||||
|
EnableSSHSFTP: &bTrue,
|
||||||
|
EnableSSHLocalPortForwarding: &bTrue,
|
||||||
|
EnableSSHRemotePortForwarding: &bTrue,
|
||||||
|
DisableSSHAuth: &bTrue,
|
||||||
|
SSHJWTCacheTTL: &iVal,
|
||||||
|
DisableClientRoutes: true,
|
||||||
|
DisableServerRoutes: true,
|
||||||
|
DisableDNS: true,
|
||||||
|
DisableFirewall: true,
|
||||||
|
BlockLANAccess: true,
|
||||||
|
BlockInbound: true,
|
||||||
|
DisableNotifications: &bTrue,
|
||||||
|
DNSLabels: domain.List{},
|
||||||
|
SSHKey: "sshkey",
|
||||||
|
NATExternalIPs: []string{"1.2.3.4"},
|
||||||
|
CustomDNSAddress: "1.1.1.1:53",
|
||||||
|
DisableAutoConnect: true,
|
||||||
|
DNSRouteInterval: 5 * time.Second,
|
||||||
|
ClientCertPath: "/tmp/cert",
|
||||||
|
ClientCertKeyPath: "/tmp/key",
|
||||||
|
LazyConnectionEnabled: true,
|
||||||
|
MTU: 1280,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, anonymize := range []bool{false, true} {
|
||||||
|
t.Run("anonymize="+map[bool]string{true: "true", false: "false"}[anonymize], func(t *testing.T) {
|
||||||
|
g := &BundleGenerator{
|
||||||
|
anonymizer: newAnonymizerForTest(),
|
||||||
|
internalConfig: cfg,
|
||||||
|
anonymize: anonymize,
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
g.addCommonConfigFields(&sb)
|
||||||
|
rendered := sb.String() + renderAddConfigSpecific(g)
|
||||||
|
|
||||||
|
val := reflect.ValueOf(cfg).Elem()
|
||||||
|
typ := val.Type()
|
||||||
|
var missing []string
|
||||||
|
for i := 0; i < typ.NumField(); i++ {
|
||||||
|
name := typ.Field(i).Name
|
||||||
|
if _, ok := excluded[name]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.Contains(rendered, name+":") {
|
||||||
|
missing = append(missing, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(missing) > 0 {
|
||||||
|
t.Fatalf("Config field(s) not present in debug bundle output: %v\n"+
|
||||||
|
"Either render the field in addCommonConfigFields/addConfig, "+
|
||||||
|
"or add it to the excluded map with a justification.", missing)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderAddConfigSpecific renders the fields handled by the anonymize/non-anonymize
|
||||||
|
// branches in addConfig (ManagementURL, AdminURL, NATExternalIPs, CustomDNSAddress).
|
||||||
|
// addCommonConfigFields covers the rest. Keeping this in the test mirrors the
|
||||||
|
// production shape without needing to write an actual zip.
|
||||||
|
func renderAddConfigSpecific(g *BundleGenerator) string {
|
||||||
|
var sb strings.Builder
|
||||||
|
if g.anonymize {
|
||||||
|
if g.internalConfig.ManagementURL != nil {
|
||||||
|
sb.WriteString("ManagementURL: " + g.anonymizer.AnonymizeURI(g.internalConfig.ManagementURL.String()) + "\n")
|
||||||
|
}
|
||||||
|
if g.internalConfig.AdminURL != nil {
|
||||||
|
sb.WriteString("AdminURL: " + g.anonymizer.AnonymizeURI(g.internalConfig.AdminURL.String()) + "\n")
|
||||||
|
}
|
||||||
|
sb.WriteString("NATExternalIPs: x\n")
|
||||||
|
if g.internalConfig.CustomDNSAddress != "" {
|
||||||
|
sb.WriteString("CustomDNSAddress: " + g.anonymizer.AnonymizeString(g.internalConfig.CustomDNSAddress) + "\n")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if g.internalConfig.ManagementURL != nil {
|
||||||
|
sb.WriteString("ManagementURL: " + g.internalConfig.ManagementURL.String() + "\n")
|
||||||
|
}
|
||||||
|
if g.internalConfig.AdminURL != nil {
|
||||||
|
sb.WriteString("AdminURL: " + g.internalConfig.AdminURL.String() + "\n")
|
||||||
|
}
|
||||||
|
sb.WriteString("NATExternalIPs: x\n")
|
||||||
|
if g.internalConfig.CustomDNSAddress != "" {
|
||||||
|
sb.WriteString("CustomDNSAddress: " + g.internalConfig.CustomDNSAddress + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAnonymizerForTest() *anonymize.Anonymizer {
|
||||||
|
return anonymize.NewAnonymizer(anonymize.DefaultAddresses())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user