Skip to content

[pfsense] Do not write config.xml while the Nexus controller serves the configuration - #420

Merged
opoplawski merged 1 commit into
pfsensible:mainfrom
RomainTie:nexus_controller_write
Dec 5, 2026
Merged

opoplawski merged 1 commit into
pfsensible:mainfrom
RomainTie:nexus_controller_write

Conversation

@RomainTie

Copy link
Copy Markdown

Describe the bug
On pfSense Plus 26.07, pfSense reads its configuration from the Netgate Nexus controller whenever the controller answers on its socket (pfnet_controller_ready() and config_provider_init() in /etc/inc/config.lib.inc), whatever the controller's Enable setting says. The modules still read and write /cf/conf/config.xml directly, then delete /tmp/config.cache: the next PHP call asks the controller to reload, and pfSense goes on with whatever the controller serves.

On one of our firewalls (pfSense Plus 26.07.2) this took the site offline:

  • The controller had been enabled for a test, then disabled, but it kept running. The Nexus package's install script runs service pfnet-controller restart whenever /var/etc/pfnet-controller/pfnet-controller.conf exists, and the package had been reinstalled.
  • Four days later, a pfsense_alias change wrote config.xml.
  • Twenty seconds later, PHP's config_get_path() returned no virtual IP and no address for the WAN interface. config.xml still had them: the next pfsense_alias tasks read it fine.
  • The firewall dropped off the network about a minute later, and has to be restored on site.

I could not find why the controller's reload lost those values: its log stayed on the firewall. But config.xml is not what pfSense reads while the controller runs, so writing it then cannot be safe.

To Reproduce

  1. On pfSense Plus 26.07, enable the Netgate Nexus controller (System > Advanced > Netgate Nexus).
  2. Run any module that changes the configuration, for example pfsense_alias.

Expected behavior
The module refuses to write, instead of changing a file that pfSense does not read.

Fix

  • write_config() first checks whether the controller serves the configuration, with the same test as pfnet_controller_ready(): the socket /var/run/pfnet-controller.sock exists, and GET /api/config/?ping answers 200.
  • If it does, the write fails before anything is written: « Refusing to write pfSense configuration: the Netgate Nexus controller serves this firewall's configuration, so config.xml is not written. Stop the controller first (System > Advanced > Netgate Nexus) ».
  • The check is done in Python, without PHP: loading config.inc would read the configuration through the controller.
  • Check mode and read-only runs are not affected ([pfsense_interface] Read the assignable ports with config_get_path() #411 keeps working there). Without the controller (CE, older Plus releases, or the controller stopped), nothing changes.

Tests

  • New tests in test_config_write.py:
    • the write is refused, with config.xml, the cache and the backup untouched;
    • the detection, against a Unix socket in a temporary directory: it answers 200, it answers 503, it does not answer, a stale socket, a regular file, no socket.
    • The 7 new tests fail without the change.
  • All unit tests pass: 1678 for the modules, 103 for module_utils. ruff check and ruff format --check pass.
  • Not run against a live controller: none of our firewalls runs it any more. The socket path and the ping URL come from /etc/inc/globals.plus.inc and config.lib.inc on pfSense Plus 26.07.2.

…he configuration

On pfSense Plus 26.07, pfSense reads its configuration from the Netgate
Nexus controller whenever the controller answers on its socket, whatever
its Enable setting says. Writing config.xml then changes a file pfSense
does not read, and the reload that follows can leave the firewall on a
configuration that matches neither.

write_config() now fails before writing when the controller serves the
configuration, with the same test as pfSense's pfnet_controller_ready():
the socket exists and its ping answers 200.
@opoplawski opoplawski added the bug Something isn't working label Dec 5, 2026
@opoplawski opoplawski added this to the 0.8.0 milestone Dec 5, 2026
@opoplawski
opoplawski merged commit 199c099 into pfsensible:main Dec 5, 2026
7 checks passed
@opoplawski

Copy link
Copy Markdown
Contributor

Sorry you got bit by this, but glad we got it before the release. I think I'm pretty much done with my latest exercising of the modules. I can build my firewalls from scratch now (minus Wireguard). I might wait a bit longer and test out Wireguard before releasing 0.8.0, but we're pretty close. Let me know if anything changes on your end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants