mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 09:16:40 +00:00
Merge branch 'main' into ssh-rewrite
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -24,10 +25,10 @@ import (
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
|
||||
"github.com/netbirdio/netbird/client/anonymize"
|
||||
"github.com/netbirdio/netbird/client/internal"
|
||||
"github.com/netbirdio/netbird/client/internal/peer"
|
||||
"github.com/netbirdio/netbird/client/internal/statemanager"
|
||||
mgmProto "github.com/netbirdio/netbird/management/proto"
|
||||
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||
mgmProto "github.com/netbirdio/netbird/shared/management/proto"
|
||||
"github.com/netbirdio/netbird/util"
|
||||
)
|
||||
|
||||
const readmeContent = `Netbird debug bundle
|
||||
@@ -38,12 +39,14 @@ status.txt: Anonymized status information of the NetBird client.
|
||||
client.log: Most recent, anonymized client log file of the NetBird client.
|
||||
netbird.err: Most recent, anonymized stderr log file of the NetBird client.
|
||||
netbird.out: Most recent, anonymized stdout log file of the NetBird client.
|
||||
routes.txt: Anonymized system routes, if --system-info flag was provided.
|
||||
routes.txt: Detailed system routing table in tabular format including destination, gateway, interface, metrics, and protocol information, if --system-info flag was provided.
|
||||
interfaces.txt: Anonymized network interface information, if --system-info flag was provided.
|
||||
ip_rules.txt: Detailed IP routing rules in tabular format including priority, source, destination, interfaces, table, and action information (Linux only), if --system-info flag was provided.
|
||||
iptables.txt: Anonymized iptables rules with packet counters, if --system-info flag was provided.
|
||||
nftables.txt: Anonymized nftables rules with packet counters, if --system-info flag was provided.
|
||||
resolved_domains.txt: Anonymized resolved domain IP addresses from the status recorder.
|
||||
config.txt: Anonymized configuration information of the NetBird client.
|
||||
network_map.json: Anonymized network map containing peer configurations, routes, DNS settings, and firewall rules.
|
||||
network_map.json: Anonymized sync response containing peer configurations, routes, DNS settings, and firewall rules.
|
||||
state.json: Anonymized client state dump containing netbird states.
|
||||
mutex.prof: Mutex profiling information.
|
||||
goroutine.prof: Goroutine profiling information.
|
||||
@@ -70,7 +73,7 @@ Domains
|
||||
All domain names (except for the netbird domains) are replaced with randomly generated strings ending in ".domain". Anonymized domains are consistent across all files in the bundle.
|
||||
Reoccuring domain names are replaced with the same anonymized domain.
|
||||
|
||||
Network Map
|
||||
Sync Response
|
||||
The network_map.json file contains the following anonymized information:
|
||||
- Peer configurations (addresses, FQDNs, DNS settings)
|
||||
- Remote and offline peer information (allowed IPs, FQDNs)
|
||||
@@ -78,7 +81,7 @@ The network_map.json file contains the following anonymized information:
|
||||
- DNS configuration (nameservers, domains, custom zones)
|
||||
- Firewall rules (peer IPs, source/destination ranges)
|
||||
|
||||
SSH keys in the network map are replaced with a placeholder value. All IP addresses and domains in the network map follow the same anonymization rules as described above.
|
||||
SSH keys in the sync response are replaced with a placeholder value. All IP addresses and domains in the sync response follow the same anonymization rules as described above.
|
||||
|
||||
State File
|
||||
The state.json file contains anonymized internal state information of the NetBird client, including:
|
||||
@@ -105,7 +108,29 @@ go tool pprof -http=:8088 heap.prof
|
||||
This will open a web browser tab with the profiling information.
|
||||
|
||||
Routes
|
||||
For anonymized routes, the IP addresses are replaced as described above. The prefix length remains unchanged. Note that for prefixes, the anonymized IP might not be a network address, but the prefix length is still correct.
|
||||
The routes.txt file contains detailed routing table information in a tabular format:
|
||||
|
||||
- Destination: Network prefix (IP_ADDRESS/PREFIX_LENGTH)
|
||||
- Gateway: Next hop IP address (or "-" if direct)
|
||||
- Interface: Network interface name
|
||||
- Metric: Route priority/metric (lower values preferred)
|
||||
- Protocol: Routing protocol (kernel, static, dhcp, etc.)
|
||||
- Scope: Route scope (global, link, host, etc.)
|
||||
- Type: Route type (unicast, local, broadcast, etc.)
|
||||
- Table: Routing table name (main, local, netbird, etc.)
|
||||
|
||||
The table format provides a comprehensive view of the system's routing configuration, including information from multiple routing tables on Linux systems. This is valuable for troubleshooting routing issues and understanding traffic flow.
|
||||
|
||||
For anonymized routes, IP addresses are replaced as described above. The prefix length remains unchanged. Note that for prefixes, the anonymized IP might not be a network address, but the prefix length is still correct. Interface names are anonymized using string anonymization.
|
||||
|
||||
Resolved Domains
|
||||
The resolved_domains.txt file contains information about domain names that have been resolved to IP addresses by NetBird's DNS resolver. This includes:
|
||||
- Original domain patterns that were configured for routing
|
||||
- Resolved domain names that matched those patterns
|
||||
- IP address prefixes that were resolved for each domain
|
||||
- Parent domain associations showing which original pattern each resolved domain belongs to
|
||||
|
||||
All domain names and IP addresses in this file follow the same anonymization rules as described above. This information is valuable for troubleshooting DNS resolution and routing issues.
|
||||
|
||||
Network Interfaces
|
||||
The interfaces.txt file contains information about network interfaces, including:
|
||||
@@ -143,6 +168,22 @@ nftables.txt:
|
||||
- Shows packet and byte counters for each rule
|
||||
- All IP addresses are anonymized
|
||||
- Chain names, table names, and other non-sensitive information remain unchanged
|
||||
|
||||
IP Rules (Linux only)
|
||||
The ip_rules.txt file contains detailed IP routing rule information:
|
||||
|
||||
- Priority: Rule priority number (lower values processed first)
|
||||
- From: Source IP prefix or "all" if unspecified
|
||||
- To: Destination IP prefix or "all" if unspecified
|
||||
- IIF: Input interface name or "-" if unspecified
|
||||
- OIF: Output interface name or "-" if unspecified
|
||||
- Table: Target routing table name (main, local, netbird, etc.)
|
||||
- Action: Rule action (lookup, goto, blackhole, etc.)
|
||||
- Mark: Firewall mark value in hex format or "-" if unspecified
|
||||
|
||||
The table format provides comprehensive visibility into the IP routing decision process, including how traffic is directed to different routing tables based on various criteria. This is valuable for troubleshooting advanced routing configurations and policy-based routing.
|
||||
|
||||
For anonymized rules, IP addresses and prefixes are replaced as described above. Interface names are anonymized using string anonymization. Table names, actions, and other non-sensitive information remain unchanged.
|
||||
`
|
||||
|
||||
const (
|
||||
@@ -158,12 +199,11 @@ type BundleGenerator struct {
|
||||
anonymizer *anonymize.Anonymizer
|
||||
|
||||
// deps
|
||||
internalConfig *internal.Config
|
||||
internalConfig *profilemanager.Config
|
||||
statusRecorder *peer.Status
|
||||
networkMap *mgmProto.NetworkMap
|
||||
syncResponse *mgmProto.SyncResponse
|
||||
logFile string
|
||||
|
||||
// config
|
||||
anonymize bool
|
||||
clientStatus string
|
||||
includeSystemInfo bool
|
||||
@@ -180,9 +220,9 @@ type BundleConfig struct {
|
||||
}
|
||||
|
||||
type GeneratorDependencies struct {
|
||||
InternalConfig *internal.Config
|
||||
InternalConfig *profilemanager.Config
|
||||
StatusRecorder *peer.Status
|
||||
NetworkMap *mgmProto.NetworkMap
|
||||
SyncResponse *mgmProto.SyncResponse
|
||||
LogFile string
|
||||
}
|
||||
|
||||
@@ -198,7 +238,7 @@ func NewBundleGenerator(deps GeneratorDependencies, cfg BundleConfig) *BundleGen
|
||||
|
||||
internalConfig: deps.InternalConfig,
|
||||
statusRecorder: deps.StatusRecorder,
|
||||
networkMap: deps.NetworkMap,
|
||||
syncResponse: deps.SyncResponse,
|
||||
logFile: deps.LogFile,
|
||||
|
||||
anonymize: cfg.Anonymize,
|
||||
@@ -256,7 +296,11 @@ func (g *BundleGenerator) createArchive() error {
|
||||
}
|
||||
|
||||
if err := g.addConfig(); err != nil {
|
||||
log.Errorf("Failed to add config to debug bundle: %v", err)
|
||||
log.Errorf("failed to add config to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addResolvedDomains(); err != nil {
|
||||
log.Errorf("failed to add resolved domains to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if g.includeSystemInfo {
|
||||
@@ -264,34 +308,34 @@ func (g *BundleGenerator) createArchive() error {
|
||||
}
|
||||
|
||||
if err := g.addProf(); err != nil {
|
||||
log.Errorf("Failed to add profiles to debug bundle: %v", err)
|
||||
log.Errorf("failed to add profiles to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addNetworkMap(); err != nil {
|
||||
return fmt.Errorf("add network map: %w", err)
|
||||
if err := g.addSyncResponse(); err != nil {
|
||||
return fmt.Errorf("add sync response: %w", err)
|
||||
}
|
||||
|
||||
if err := g.addStateFile(); err != nil {
|
||||
log.Errorf("Failed to add state file to debug bundle: %v", err)
|
||||
log.Errorf("failed to add state file to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addCorruptedStateFiles(); err != nil {
|
||||
log.Errorf("Failed to add corrupted state files to debug bundle: %v", err)
|
||||
log.Errorf("failed to add corrupted state files to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addWgShow(); err != nil {
|
||||
log.Errorf("Failed to add wg show output: %v", err)
|
||||
log.Errorf("failed to add wg show output: %v", err)
|
||||
}
|
||||
|
||||
if g.logFile != "console" && g.logFile != "" {
|
||||
if g.logFile != "" && !slices.Contains(util.SpecialLogs, g.logFile) {
|
||||
if err := g.addLogfile(); err != nil {
|
||||
log.Errorf("Failed to add log file to debug bundle: %v", err)
|
||||
log.Errorf("failed to add log file to debug bundle: %v", err)
|
||||
if err := g.trySystemdLogFallback(); err != nil {
|
||||
log.Errorf("Failed to add systemd logs as fallback: %v", err)
|
||||
log.Errorf("failed to add systemd logs as fallback: %v", err)
|
||||
}
|
||||
}
|
||||
} else if err := g.trySystemdLogFallback(); err != nil {
|
||||
log.Errorf("Failed to add systemd logs: %v", err)
|
||||
log.Errorf("failed to add systemd logs: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -299,15 +343,19 @@ func (g *BundleGenerator) createArchive() error {
|
||||
|
||||
func (g *BundleGenerator) addSystemInfo() {
|
||||
if err := g.addRoutes(); err != nil {
|
||||
log.Errorf("Failed to add routes to debug bundle: %v", err)
|
||||
log.Errorf("failed to add routes to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addInterfaces(); err != nil {
|
||||
log.Errorf("Failed to add interfaces to debug bundle: %v", err)
|
||||
log.Errorf("failed to add interfaces to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addIPRules(); err != nil {
|
||||
log.Errorf("failed to add IP rules to debug bundle: %v", err)
|
||||
}
|
||||
|
||||
if err := g.addFirewallRules(); err != nil {
|
||||
log.Errorf("Failed to add firewall rules to debug bundle: %v", err)
|
||||
log.Errorf("failed to add firewall rules to debug bundle: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +410,6 @@ func (g *BundleGenerator) addConfig() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Add config content to zip file
|
||||
configReader := strings.NewReader(configContent.String())
|
||||
if err := g.addFileToZip(configReader, "config.txt"); err != nil {
|
||||
return fmt.Errorf("add config file to zip: %w", err)
|
||||
@@ -374,7 +421,6 @@ func (g *BundleGenerator) addConfig() error {
|
||||
func (g *BundleGenerator) addCommonConfigFields(configContent *strings.Builder) {
|
||||
configContent.WriteString("NetBird Client Configuration:\n\n")
|
||||
|
||||
// Add non-sensitive fields
|
||||
configContent.WriteString(fmt.Sprintf("WgIface: %s\n", g.internalConfig.WgIface))
|
||||
configContent.WriteString(fmt.Sprintf("WgPort: %d\n", g.internalConfig.WgPort))
|
||||
if g.internalConfig.NetworkMonitor != nil {
|
||||
@@ -471,15 +517,36 @@ func (g *BundleGenerator) addInterfaces() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *BundleGenerator) addNetworkMap() error {
|
||||
if g.networkMap == nil {
|
||||
log.Debugf("skipping empty network map in debug bundle")
|
||||
func (g *BundleGenerator) addResolvedDomains() error {
|
||||
if g.statusRecorder == nil {
|
||||
log.Debugf("skipping resolved domains in debug bundle: no status recorder")
|
||||
return nil
|
||||
}
|
||||
|
||||
resolvedDomains := g.statusRecorder.GetResolvedDomainsStates()
|
||||
if len(resolvedDomains) == 0 {
|
||||
log.Debugf("skipping resolved domains in debug bundle: no resolved domains")
|
||||
return nil
|
||||
}
|
||||
|
||||
resolvedDomainsContent := formatResolvedDomains(resolvedDomains, g.anonymize, g.anonymizer)
|
||||
resolvedDomainsReader := strings.NewReader(resolvedDomainsContent)
|
||||
if err := g.addFileToZip(resolvedDomainsReader, "resolved_domains.txt"); err != nil {
|
||||
return fmt.Errorf("add resolved domains file to zip: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *BundleGenerator) addSyncResponse() error {
|
||||
if g.syncResponse == nil {
|
||||
log.Debugf("skipping empty sync response in debug bundle")
|
||||
return nil
|
||||
}
|
||||
|
||||
if g.anonymize {
|
||||
if err := anonymizeNetworkMap(g.networkMap, g.anonymizer); err != nil {
|
||||
return fmt.Errorf("anonymize network map: %w", err)
|
||||
if err := anonymizeSyncResponse(g.syncResponse, g.anonymizer); err != nil {
|
||||
return fmt.Errorf("anonymize sync response: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,20 +557,21 @@ func (g *BundleGenerator) addNetworkMap() error {
|
||||
AllowPartial: true,
|
||||
}
|
||||
|
||||
jsonBytes, err := options.Marshal(g.networkMap)
|
||||
jsonBytes, err := options.Marshal(g.syncResponse)
|
||||
if err != nil {
|
||||
return fmt.Errorf("generate json: %w", err)
|
||||
}
|
||||
|
||||
if err := g.addFileToZip(bytes.NewReader(jsonBytes), "network_map.json"); err != nil {
|
||||
return fmt.Errorf("add network map to zip: %w", err)
|
||||
return fmt.Errorf("add sync response to zip: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *BundleGenerator) addStateFile() error {
|
||||
path := statemanager.GetDefaultStatePath()
|
||||
sm := profilemanager.NewServiceManager("")
|
||||
path := sm.GetStatePath()
|
||||
if path == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -541,7 +609,8 @@ func (g *BundleGenerator) addStateFile() error {
|
||||
}
|
||||
|
||||
func (g *BundleGenerator) addCorruptedStateFiles() error {
|
||||
pattern := statemanager.GetDefaultStatePath()
|
||||
sm := profilemanager.NewServiceManager("")
|
||||
pattern := sm.GetStatePath()
|
||||
if pattern == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -582,7 +651,6 @@ func (g *BundleGenerator) addLogfile() error {
|
||||
return fmt.Errorf("add client log file to zip: %w", err)
|
||||
}
|
||||
|
||||
// add rotated log files based on logFileCount
|
||||
g.addRotatedLogFiles(logDir)
|
||||
|
||||
stdErrLogPath := filepath.Join(logDir, errorLogFile)
|
||||
@@ -611,7 +679,7 @@ func (g *BundleGenerator) addSingleLogfile(logPath, targetName string) error {
|
||||
}
|
||||
defer func() {
|
||||
if err := logFile.Close(); err != nil {
|
||||
log.Errorf("Failed to close log file %s: %v", targetName, err)
|
||||
log.Errorf("failed to close log file %s: %v", targetName, err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -635,13 +703,21 @@ func (g *BundleGenerator) addSingleLogFileGz(logPath, targetName string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("open gz log file %s: %w", targetName, err)
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Errorf("failed to close gz file %s: %v", targetName, err)
|
||||
}
|
||||
}()
|
||||
|
||||
gzr, err := gzip.NewReader(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create gzip reader: %w", err)
|
||||
}
|
||||
defer gzr.Close()
|
||||
defer func() {
|
||||
if err := gzr.Close(); err != nil {
|
||||
log.Errorf("failed to close gzip reader %s: %v", targetName, err)
|
||||
}
|
||||
}()
|
||||
|
||||
var logReader io.Reader = gzr
|
||||
if g.anonymize {
|
||||
@@ -699,7 +775,6 @@ func (g *BundleGenerator) addRotatedLogFiles(logDir string) {
|
||||
return fi.ModTime().After(fj.ModTime())
|
||||
})
|
||||
|
||||
// include up to logFileCount rotated files
|
||||
maxFiles := int(g.logFileCount)
|
||||
if maxFiles > len(files) {
|
||||
maxFiles = len(files)
|
||||
@@ -727,7 +802,7 @@ func (g *BundleGenerator) addFileToZip(reader io.Reader, filename string) error
|
||||
// If the reader is a file, we can get more accurate information
|
||||
if f, ok := reader.(*os.File); ok {
|
||||
if stat, err := f.Stat(); err != nil {
|
||||
log.Tracef("Failed to get file stat for %s: %v", filename, err)
|
||||
log.Tracef("failed to get file stat for %s: %v", filename, err)
|
||||
} else {
|
||||
header.Modified = stat.ModTime()
|
||||
}
|
||||
@@ -775,89 +850,6 @@ func seedFromStatus(a *anonymize.Anonymizer, status *peer.FullStatus) {
|
||||
}
|
||||
}
|
||||
|
||||
func formatRoutes(routes []netip.Prefix, anonymize bool, anonymizer *anonymize.Anonymizer) string {
|
||||
var ipv4Routes, ipv6Routes []netip.Prefix
|
||||
|
||||
// Separate IPv4 and IPv6 routes
|
||||
for _, route := range routes {
|
||||
if route.Addr().Is4() {
|
||||
ipv4Routes = append(ipv4Routes, route)
|
||||
} else {
|
||||
ipv6Routes = append(ipv6Routes, route)
|
||||
}
|
||||
}
|
||||
|
||||
// Sort IPv4 and IPv6 routes separately
|
||||
sort.Slice(ipv4Routes, func(i, j int) bool {
|
||||
return ipv4Routes[i].Bits() > ipv4Routes[j].Bits()
|
||||
})
|
||||
sort.Slice(ipv6Routes, func(i, j int) bool {
|
||||
return ipv6Routes[i].Bits() > ipv6Routes[j].Bits()
|
||||
})
|
||||
|
||||
var builder strings.Builder
|
||||
|
||||
// Format IPv4 routes
|
||||
builder.WriteString("IPv4 Routes:\n")
|
||||
for _, route := range ipv4Routes {
|
||||
formatRoute(&builder, route, anonymize, anonymizer)
|
||||
}
|
||||
|
||||
// Format IPv6 routes
|
||||
builder.WriteString("\nIPv6 Routes:\n")
|
||||
for _, route := range ipv6Routes {
|
||||
formatRoute(&builder, route, anonymize, anonymizer)
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func formatRoute(builder *strings.Builder, route netip.Prefix, anonymize bool, anonymizer *anonymize.Anonymizer) {
|
||||
if anonymize {
|
||||
anonymizedIP := anonymizer.AnonymizeIP(route.Addr())
|
||||
builder.WriteString(fmt.Sprintf("%s/%d\n", anonymizedIP, route.Bits()))
|
||||
} else {
|
||||
builder.WriteString(fmt.Sprintf("%s\n", route))
|
||||
}
|
||||
}
|
||||
|
||||
func formatInterfaces(interfaces []net.Interface, anonymize bool, anonymizer *anonymize.Anonymizer) string {
|
||||
sort.Slice(interfaces, func(i, j int) bool {
|
||||
return interfaces[i].Name < interfaces[j].Name
|
||||
})
|
||||
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Network Interfaces:\n")
|
||||
|
||||
for _, iface := range interfaces {
|
||||
builder.WriteString(fmt.Sprintf("\nInterface: %s\n", iface.Name))
|
||||
builder.WriteString(fmt.Sprintf(" Index: %d\n", iface.Index))
|
||||
builder.WriteString(fmt.Sprintf(" MTU: %d\n", iface.MTU))
|
||||
builder.WriteString(fmt.Sprintf(" Flags: %v\n", iface.Flags))
|
||||
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
builder.WriteString(fmt.Sprintf(" Addresses: Error retrieving addresses: %v\n", err))
|
||||
} else {
|
||||
builder.WriteString(" Addresses:\n")
|
||||
for _, addr := range addrs {
|
||||
prefix, err := netip.ParsePrefix(addr.String())
|
||||
if err != nil {
|
||||
builder.WriteString(fmt.Sprintf(" Error parsing address: %v\n", err))
|
||||
continue
|
||||
}
|
||||
ip := prefix.Addr()
|
||||
if anonymize {
|
||||
ip = anonymizer.AnonymizeIP(ip)
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf(" %s/%d\n", ip, prefix.Bits()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func anonymizeLog(reader io.Reader, writer *io.PipeWriter, anonymizer *anonymize.Anonymizer) {
|
||||
defer func() {
|
||||
// always nil
|
||||
@@ -941,6 +933,88 @@ func anonymizeNetworkMap(networkMap *mgmProto.NetworkMap, anonymizer *anonymize.
|
||||
return nil
|
||||
}
|
||||
|
||||
func anonymizeNetbirdConfig(config *mgmProto.NetbirdConfig, anonymizer *anonymize.Anonymizer) {
|
||||
for _, stun := range config.Stuns {
|
||||
if stun.Uri != "" {
|
||||
stun.Uri = anonymizer.AnonymizeURI(stun.Uri)
|
||||
}
|
||||
}
|
||||
|
||||
for _, turn := range config.Turns {
|
||||
if turn.HostConfig != nil && turn.HostConfig.Uri != "" {
|
||||
turn.HostConfig.Uri = anonymizer.AnonymizeURI(turn.HostConfig.Uri)
|
||||
}
|
||||
if turn.User != "" {
|
||||
turn.User = "turn-user-placeholder"
|
||||
}
|
||||
if turn.Password != "" {
|
||||
turn.Password = "turn-password-placeholder"
|
||||
}
|
||||
}
|
||||
|
||||
if config.Signal != nil && config.Signal.Uri != "" {
|
||||
config.Signal.Uri = anonymizer.AnonymizeURI(config.Signal.Uri)
|
||||
}
|
||||
|
||||
if config.Relay != nil {
|
||||
for i, url := range config.Relay.Urls {
|
||||
config.Relay.Urls[i] = anonymizer.AnonymizeURI(url)
|
||||
}
|
||||
if config.Relay.TokenPayload != "" {
|
||||
config.Relay.TokenPayload = "relay-token-payload-placeholder"
|
||||
}
|
||||
if config.Relay.TokenSignature != "" {
|
||||
config.Relay.TokenSignature = "relay-token-signature-placeholder"
|
||||
}
|
||||
}
|
||||
|
||||
if config.Flow != nil {
|
||||
if config.Flow.Url != "" {
|
||||
config.Flow.Url = anonymizer.AnonymizeURI(config.Flow.Url)
|
||||
}
|
||||
if config.Flow.TokenPayload != "" {
|
||||
config.Flow.TokenPayload = "flow-token-payload-placeholder"
|
||||
}
|
||||
if config.Flow.TokenSignature != "" {
|
||||
config.Flow.TokenSignature = "flow-token-signature-placeholder"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func anonymizeSyncResponse(syncResponse *mgmProto.SyncResponse, anonymizer *anonymize.Anonymizer) error {
|
||||
if syncResponse.NetbirdConfig != nil {
|
||||
anonymizeNetbirdConfig(syncResponse.NetbirdConfig, anonymizer)
|
||||
}
|
||||
|
||||
if syncResponse.PeerConfig != nil {
|
||||
anonymizePeerConfig(syncResponse.PeerConfig, anonymizer)
|
||||
}
|
||||
|
||||
for _, p := range syncResponse.RemotePeers {
|
||||
anonymizeRemotePeer(p, anonymizer)
|
||||
}
|
||||
|
||||
if syncResponse.NetworkMap != nil {
|
||||
if err := anonymizeNetworkMap(syncResponse.NetworkMap, anonymizer); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, check := range syncResponse.Checks {
|
||||
for i, file := range check.Files {
|
||||
check.Files[i] = anonymizer.AnonymizeString(file)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func anonymizeSSHConfig(sshConfig *mgmProto.SSHConfig) {
|
||||
if sshConfig != nil && len(sshConfig.SshPubKey) > 0 {
|
||||
sshConfig.SshPubKey = []byte("ssh-placeholder-key")
|
||||
}
|
||||
}
|
||||
|
||||
func anonymizePeerConfig(config *mgmProto.PeerConfig, anonymizer *anonymize.Anonymizer) {
|
||||
if config == nil {
|
||||
return
|
||||
@@ -950,9 +1024,7 @@ func anonymizePeerConfig(config *mgmProto.PeerConfig, anonymizer *anonymize.Anon
|
||||
config.Address = anonymizer.AnonymizeIP(addr).String()
|
||||
}
|
||||
|
||||
if config.SshConfig != nil && len(config.SshConfig.SshPubKey) > 0 {
|
||||
config.SshConfig.SshPubKey = []byte("ssh-placeholder-key")
|
||||
}
|
||||
anonymizeSSHConfig(config.SshConfig)
|
||||
|
||||
config.Dns = anonymizer.AnonymizeString(config.Dns)
|
||||
config.Fqdn = anonymizer.AnonymizeDomain(config.Fqdn)
|
||||
@@ -964,7 +1036,6 @@ func anonymizeRemotePeer(peer *mgmProto.RemotePeerConfig, anonymizer *anonymize.
|
||||
}
|
||||
|
||||
for i, ip := range peer.AllowedIps {
|
||||
// Try to parse as prefix first (CIDR)
|
||||
if prefix, err := netip.ParsePrefix(ip); err == nil {
|
||||
anonIP := anonymizer.AnonymizeIP(prefix.Addr())
|
||||
peer.AllowedIps[i] = fmt.Sprintf("%s/%d", anonIP, prefix.Bits())
|
||||
@@ -975,9 +1046,7 @@ func anonymizeRemotePeer(peer *mgmProto.RemotePeerConfig, anonymizer *anonymize.
|
||||
|
||||
peer.Fqdn = anonymizer.AnonymizeDomain(peer.Fqdn)
|
||||
|
||||
if peer.SshConfig != nil && len(peer.SshConfig.SshPubKey) > 0 {
|
||||
peer.SshConfig.SshPubKey = []byte("ssh-placeholder-key")
|
||||
}
|
||||
anonymizeSSHConfig(peer.SshConfig)
|
||||
}
|
||||
|
||||
func anonymizeRoute(route *mgmProto.Route, anonymizer *anonymize.Anonymizer) {
|
||||
@@ -1043,7 +1112,7 @@ func anonymizeRecords(records []*mgmProto.SimpleRecord, anonymizer *anonymize.An
|
||||
|
||||
func anonymizeRData(record *mgmProto.SimpleRecord, anonymizer *anonymize.Anonymizer) {
|
||||
switch record.Type {
|
||||
case 1, 28: // A or AAAA record
|
||||
case 1, 28:
|
||||
if addr, err := netip.ParseAddr(record.RData); err == nil {
|
||||
record.RData = anonymizer.AnonymizeIP(addr).String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user