Skip to content

Commit 229e003

Browse files
authored
[client] Add dns config to debug bundle (#4704)
1 parent 75327d9 commit 229e003

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

client/internal/debug/debug.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ interfaces.txt: Anonymized network interface information, if --system-info flag
4444
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.
4545
iptables.txt: Anonymized iptables rules with packet counters, if --system-info flag was provided.
4646
nftables.txt: Anonymized nftables rules with packet counters, if --system-info flag was provided.
47+
resolv.conf: DNS resolver configuration from /etc/resolv.conf (Unix systems only), if --system-info flag was provided.
48+
scutil_dns.txt: DNS configuration from scutil --dns (macOS only), if --system-info flag was provided.
4749
resolved_domains.txt: Anonymized resolved domain IP addresses from the status recorder.
4850
config.txt: Anonymized configuration information of the NetBird client.
4951
network_map.json: Anonymized sync response containing peer configurations, routes, DNS settings, and firewall rules.
@@ -184,6 +186,20 @@ The ip_rules.txt file contains detailed IP routing rule information:
184186
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.
185187
186188
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.
189+
190+
DNS Configuration
191+
The debug bundle includes platform-specific DNS configuration files:
192+
193+
resolv.conf (Unix systems):
194+
- Contains DNS resolver configuration from /etc/resolv.conf
195+
- Includes nameserver entries, search domains, and resolver options
196+
- All IP addresses and domain names are anonymized following the same rules as other files
197+
198+
scutil_dns.txt (macOS only):
199+
- Contains detailed DNS configuration from scutil --dns
200+
- Shows DNS configuration for all network interfaces
201+
- Includes search domains, nameservers, and DNS resolver settings
202+
- All IP addresses and domain names are anonymized
187203
`
188204

189205
const (
@@ -357,6 +373,10 @@ func (g *BundleGenerator) addSystemInfo() {
357373
if err := g.addFirewallRules(); err != nil {
358374
log.Errorf("failed to add firewall rules to debug bundle: %v", err)
359375
}
376+
377+
if err := g.addDNSInfo(); err != nil {
378+
log.Errorf("failed to add DNS info to debug bundle: %v", err)
379+
}
360380
}
361381

362382
func (g *BundleGenerator) addReadme() error {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//go:build darwin && !ios
2+
3+
package debug
4+
5+
import (
6+
"bytes"
7+
"context"
8+
"fmt"
9+
"os/exec"
10+
"strings"
11+
"time"
12+
13+
log "github.com/sirupsen/logrus"
14+
)
15+
16+
// addDNSInfo collects and adds DNS configuration information to the archive
17+
func (g *BundleGenerator) addDNSInfo() error {
18+
if err := g.addResolvConf(); err != nil {
19+
log.Errorf("failed to add resolv.conf: %v", err)
20+
}
21+
22+
if err := g.addScutilDNS(); err != nil {
23+
log.Errorf("failed to add scutil DNS output: %v", err)
24+
}
25+
26+
return nil
27+
}
28+
29+
func (g *BundleGenerator) addScutilDNS() error {
30+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
31+
defer cancel()
32+
33+
cmd := exec.CommandContext(ctx, "scutil", "--dns")
34+
output, err := cmd.CombinedOutput()
35+
if err != nil {
36+
return fmt.Errorf("execute scutil --dns: %w", err)
37+
}
38+
39+
if len(bytes.TrimSpace(output)) == 0 {
40+
return fmt.Errorf("no scutil DNS output")
41+
}
42+
43+
content := string(output)
44+
if g.anonymize {
45+
content = g.anonymizer.AnonymizeString(content)
46+
}
47+
48+
if err := g.addFileToZip(strings.NewReader(content), "scutil_dns.txt"); err != nil {
49+
return fmt.Errorf("add scutil DNS output to zip: %w", err)
50+
}
51+
52+
return nil
53+
}

client/internal/debug/debug_mobile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ package debug
55
func (g *BundleGenerator) addRoutes() error {
66
return nil
77
}
8+
9+
func (g *BundleGenerator) addDNSInfo() error {
10+
return nil
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build unix && !darwin && !android
2+
3+
package debug
4+
5+
import (
6+
log "github.com/sirupsen/logrus"
7+
)
8+
9+
// addDNSInfo collects and adds DNS configuration information to the archive
10+
func (g *BundleGenerator) addDNSInfo() error {
11+
if err := g.addResolvConf(); err != nil {
12+
log.Errorf("failed to add resolv.conf: %v", err)
13+
}
14+
15+
return nil
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !unix
2+
3+
package debug
4+
5+
func (g *BundleGenerator) addDNSInfo() error {
6+
return nil
7+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build unix && !android
2+
3+
package debug
4+
5+
import (
6+
"fmt"
7+
"os"
8+
"strings"
9+
)
10+
11+
const resolvConfPath = "/etc/resolv.conf"
12+
13+
func (g *BundleGenerator) addResolvConf() error {
14+
data, err := os.ReadFile(resolvConfPath)
15+
if err != nil {
16+
return fmt.Errorf("read %s: %w", resolvConfPath, err)
17+
}
18+
19+
content := string(data)
20+
if g.anonymize {
21+
content = g.anonymizer.AnonymizeString(content)
22+
}
23+
24+
if err := g.addFileToZip(strings.NewReader(content), "resolv.conf"); err != nil {
25+
return fmt.Errorf("add resolv.conf to zip: %w", err)
26+
}
27+
28+
return nil
29+
}

0 commit comments

Comments
 (0)