From 74587ec8e1946becd1f8a8ff28f083eaaf9eafb2 Mon Sep 17 00:00:00 2001 From: nessi Date: Thu, 19 Mar 2026 22:27:52 +0100 Subject: [PATCH] refactor: move vpn-dns config directory from /etc/coredns to /tmp/nexavpn-vpn-dns Add configDir, corefilePath, and overridesPath constants pointing to /tmp/nexavpn-vpn-dns directory. Update all file path references in writeCorefile and refreshOverrides to use new constants instead of hardcoded /etc/coredns paths. --- deploy/vpn-dns/main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/deploy/vpn-dns/main.go b/deploy/vpn-dns/main.go index c472c84..69010a7 100644 --- a/deploy/vpn-dns/main.go +++ b/deploy/vpn-dns/main.go @@ -14,6 +14,12 @@ import ( "time" ) +const ( + configDir = "/tmp/nexavpn-vpn-dns" + corefilePath = configDir + "/Corefile" + overridesPath = configDir + "/service-overrides.hosts" +) + type dnsResponse struct { Records []dnsRecord `json:"records"` } @@ -26,7 +32,7 @@ type dnsRecord struct { func main() { ctx := context.Background() - if err := os.MkdirAll("/etc/coredns", 0o755); err != nil { + if err := os.MkdirAll(configDir, 0o755); err != nil { log.Fatalf("unable to create coredns config dir: %v", err) } @@ -47,7 +53,7 @@ func main() { } }() - cmd := exec.Command("/coredns", "-conf", "/etc/coredns/Corefile") + cmd := exec.Command("/coredns", "-conf", corefilePath) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -65,7 +71,7 @@ func writeCorefile() error { corefile := fmt.Sprintf(`%s { errors - hosts /etc/coredns/service-overrides.hosts { + hosts ` + overridesPath + ` { ttl 30 reload 15s fallthrough @@ -75,7 +81,7 @@ func writeCorefile() error { } `, envOrDefault("NEXAVPN_VPN_DNS_ADDR", ":53"), strings.Join(upstreams, " ")) - return os.WriteFile("/etc/coredns/Corefile", []byte(corefile), 0o644) + return os.WriteFile(corefilePath, []byte(corefile), 0o644) } func refreshOverrides(ctx context.Context) error { @@ -116,7 +122,7 @@ func refreshOverrides(ctx context.Context) error { content += "\n" } - return os.WriteFile(filepath.Clean("/etc/coredns/service-overrides.hosts"), []byte(content), 0o644) + return os.WriteFile(filepath.Clean(overridesPath), []byte(content), 0o644) } func parseList(raw string) []string {