[PR #6078] [client] Add Windows DNS firewall for non-netbird processes #27484

Open
opened 2026-08-05 07:08:47 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6078
Author: @lixmal
Created: 5/5/2026
Status: 🔄 Open

Base: mainHead: windows-dns-firewall


📝 Commits (9)

  • 4810e79 Add Windows DNS firewall to block DNS leaks from non-netbird processes
  • 6a201d1 Extract applyRouteAll helper and reorder package declarations
  • 0571eea Move strictMode to Windows-only and add manager unit tests
  • 7fd1666 Fix Windows lint: handle close error and exclude vendored WFP types from unused
  • 0415137 Address CodeRabbit nits: errors.As, defensive disable, port-aware filter name, log wording, provenance
  • f42b8ae Reject port 0 in NB_DNS_FIREWALL_PORTS and roll back firewall on DNS setup failure
  • 5f8b884 Initialize dnsFirewall in registryConfigurator tests
  • cca46f0 Merge remote-tracking branch 'origin/main' into windows-dns-firewall
  • 9157b74 Merge branch 'main' into windows-dns-firewall

📊 Changes

17 files changed (+1642 additions, -16 deletions)

View changed files

📝 .golangci.yaml (+3 -0)
client/internal/dns/dnsfw/config.go (+63 -0)
client/internal/dns/dnsfw/config_test.go (+39 -0)
client/internal/dns/dnsfw/dnsfw.go (+16 -0)
client/internal/dns/dnsfw/dnsfw_other.go (+15 -0)
client/internal/dns/dnsfw/dnsfw_windows.go (+144 -0)
client/internal/dns/dnsfw/dnsfw_windows_test.go (+72 -0)
client/internal/dns/dnsfw/helpers_windows.go (+53 -0)
client/internal/dns/dnsfw/rules_windows.go (+249 -0)
client/internal/dns/dnsfw/session_windows.go (+177 -0)
client/internal/dns/dnsfw/syscall_windows.go (+38 -0)
client/internal/dns/dnsfw/types_windows.go (+414 -0)
client/internal/dns/dnsfw/types_windows_32.go (+92 -0)
client/internal/dns/dnsfw/types_windows_64.go (+89 -0)
client/internal/dns/dnsfw/zsyscall_windows.go (+130 -0)
📝 client/internal/dns/host_windows.go (+40 -12)
📝 client/internal/dns/host_windows_test.go (+8 -4)

📄 Description

Describe your changes

Adds a Windows DNS firewall that blocks outbound DNS traffic from processes other than the netbird daemon when netbird is the default resolver. Uses WFP (Windows Filtering Platform) via vendored wireguard-windows scaffolding to install ALE_AUTH_CONNECT filters on a dynamic session, so filters are removed automatically on process exit.

  • New client/internal/dns/dnsfw package with a Manager interface; Windows implementation backed by WFP, no-op on other platforms
  • Wired into the Windows host configurator: enabled when RouteAll=true, disabled in match-only/split-DNS mode so non-netbird domains can still reach the host's resolver
  • Default mode permits any traffic on the netbird tunnel plus the daemon by App-ID, blocks DNS ports (53, 853 UDP/TCP) elsewhere
  • Strict mode (NB_DNS_FIREWALL_STRICT=true) permits DNS only to the in-tunnel virtual DNS IP and propagates failures so the daemon retries
  • Configurable via NB_DISABLE_DNS_FIREWALL and NB_DNS_FIREWALL_PORTS

Closes #3169

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Behavior is opt-out via env var; defaults are safe and don't change user-visible setup.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features

    • Windows DNS firewall manager with per-tunnel control, configurable blocked DNS ports (defaults include standard DNS ports), strict-mode handling, and no-op behavior on non-Windows
    • Env vars to disable the firewall, override blocked ports, and enable strict enforcement
    • Host DNS integration: firewall is enabled/disabled with "route all" and is disabled when restoring host DNS
  • Tests

    • Added tests for config parsing, strict-mode parsing, enable/disable idempotency, and env-driven no-op cases
  • Chores

    • Linter exclusion for generated/OS-specific firewall bindings

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6078 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 5/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `windows-dns-firewall` --- ### 📝 Commits (9) - [`4810e79`](https://github.com/netbirdio/netbird/commit/4810e79a0027cf3bc782091fb4eeaf281bccb2a4) Add Windows DNS firewall to block DNS leaks from non-netbird processes - [`6a201d1`](https://github.com/netbirdio/netbird/commit/6a201d12b503cd92dc9687d6b3da075eacc64118) Extract applyRouteAll helper and reorder package declarations - [`0571eea`](https://github.com/netbirdio/netbird/commit/0571eeaba03b6b3ada81058fd932f9b112870198) Move strictMode to Windows-only and add manager unit tests - [`7fd1666`](https://github.com/netbirdio/netbird/commit/7fd16666e3a568f280119fb5244955ade851352a) Fix Windows lint: handle close error and exclude vendored WFP types from unused - [`0415137`](https://github.com/netbirdio/netbird/commit/0415137acdb58d966e6d4033e9d4fe81f76ff0ec) Address CodeRabbit nits: errors.As, defensive disable, port-aware filter name, log wording, provenance - [`f42b8ae`](https://github.com/netbirdio/netbird/commit/f42b8aed90d1603afa725f32771e71f22c4e75bd) Reject port 0 in NB_DNS_FIREWALL_PORTS and roll back firewall on DNS setup failure - [`5f8b884`](https://github.com/netbirdio/netbird/commit/5f8b88471fd13a2206efdd9fbd83c67a49f5c735) Initialize dnsFirewall in registryConfigurator tests - [`cca46f0`](https://github.com/netbirdio/netbird/commit/cca46f070b6779c9ff264814d3b562767c337840) Merge remote-tracking branch 'origin/main' into windows-dns-firewall - [`9157b74`](https://github.com/netbirdio/netbird/commit/9157b749459ad64620c36178fb26eac40e9ca805) Merge branch 'main' into windows-dns-firewall ### 📊 Changes **17 files changed** (+1642 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `.golangci.yaml` (+3 -0) ➕ `client/internal/dns/dnsfw/config.go` (+63 -0) ➕ `client/internal/dns/dnsfw/config_test.go` (+39 -0) ➕ `client/internal/dns/dnsfw/dnsfw.go` (+16 -0) ➕ `client/internal/dns/dnsfw/dnsfw_other.go` (+15 -0) ➕ `client/internal/dns/dnsfw/dnsfw_windows.go` (+144 -0) ➕ `client/internal/dns/dnsfw/dnsfw_windows_test.go` (+72 -0) ➕ `client/internal/dns/dnsfw/helpers_windows.go` (+53 -0) ➕ `client/internal/dns/dnsfw/rules_windows.go` (+249 -0) ➕ `client/internal/dns/dnsfw/session_windows.go` (+177 -0) ➕ `client/internal/dns/dnsfw/syscall_windows.go` (+38 -0) ➕ `client/internal/dns/dnsfw/types_windows.go` (+414 -0) ➕ `client/internal/dns/dnsfw/types_windows_32.go` (+92 -0) ➕ `client/internal/dns/dnsfw/types_windows_64.go` (+89 -0) ➕ `client/internal/dns/dnsfw/zsyscall_windows.go` (+130 -0) 📝 `client/internal/dns/host_windows.go` (+40 -12) 📝 `client/internal/dns/host_windows_test.go` (+8 -4) </details> ### 📄 Description ## Describe your changes Adds a Windows DNS firewall that blocks outbound DNS traffic from processes other than the netbird daemon when netbird is the default resolver. Uses WFP (Windows Filtering Platform) via vendored wireguard-windows scaffolding to install ALE_AUTH_CONNECT filters on a dynamic session, so filters are removed automatically on process exit. - New `client/internal/dns/dnsfw` package with a `Manager` interface; Windows implementation backed by WFP, no-op on other platforms - Wired into the Windows host configurator: enabled when `RouteAll=true`, disabled in match-only/split-DNS mode so non-netbird domains can still reach the host's resolver - Default mode permits any traffic on the netbird tunnel plus the daemon by App-ID, blocks DNS ports (53, 853 UDP/TCP) elsewhere - Strict mode (`NB_DNS_FIREWALL_STRICT=true`) permits DNS only to the in-tunnel virtual DNS IP and propagates failures so the daemon retries - Configurable via `NB_DISABLE_DNS_FIREWALL` and `NB_DNS_FIREWALL_PORTS` ## Issue ticket number and link Closes #3169 ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) Behavior is opt-out via env var; defaults are safe and don't change user-visible setup. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Windows DNS firewall manager with per-tunnel control, configurable blocked DNS ports (defaults include standard DNS ports), strict-mode handling, and no-op behavior on non-Windows * Env vars to disable the firewall, override blocked ports, and enable strict enforcement * Host DNS integration: firewall is enabled/disabled with "route all" and is disabled when restoring host DNS * **Tests** * Added tests for config parsing, strict-mode parsing, enable/disable idempotency, and env-driven no-op cases * **Chores** * Linter exclusion for generated/OS-specific firewall bindings <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:08:47 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#27484