Skip to content

Add nm_ip NetworkManager provider for network.managed (#54791) - #69620

Merged
dwoz merged 9 commits into
saltstack:3006.xfrom
ggiesen:feature-nm-ip-provider
Aug 11, 2026
Merged

dwoz merged 9 commits into
saltstack:3006.xfrom
ggiesen:feature-nm-ip-provider

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

network.managed has been broken on RedHat-family systems since EL8. The rh_ip provider writes /etc/sysconfig/network-scripts/ifcfg-* files and brings interfaces up with ifup/ifdown from the network-scripts package, which is not installed by default on EL8+ and is removed entirely on EL10. The state fails with:

Unable to run command '['ifdown', 'eth1']' ... [Errno 2] No such file or directory: 'ifdown'

and configures nothing.

This adds nm_ip, an ip provider that writes NetworkManager keyfiles under /etc/NetworkManager/system-connections/ and applies them with nmcli. It supports ethernet (static/dhcp/disabled, dual-stack), bond, vlan, and bridge, with bond/bridge members written as their own port keyfiles. A deterministic per-interface connection uuid keeps build_interface output identical to the keyfile NetworkManager reads back, so the state stays idempotent.

Fixes #54791. Also addresses #68252 and #62844, which share this root cause.

Compatibility note (automatic provider swap)

Provider selection is a single condition both modules test: nmcli present, /run/NetworkManager exists, and no ifup/ifdown on PATH. nm_ip claims the ip virtual when that holds; rh_ip defers.

This means the ip provider changes automatically on affected hosts:

  • EL8/9/10 with NetworkManager and no network-scripts (the default): the provider switches from rh_ip to nm_ip. On these hosts rh_ip is already non-functional (it dies on ifdown), so nothing that previously worked stops working -- but operators should be aware the config now lands as NM keyfiles rather than ifcfg-* files.
  • Hosts with network-scripts installed (legacy setups, or where an admin has added it): ifup/ifdown are present, the condition is false, and rh_ip continues to own the ip provider exactly as before. No change.

The switch is intentional -- it is what makes network.managed work again on modern EL -- but it is a behavior change worth calling out for anyone who inspects ifcfg-* files or has tooling that reads them.

What issues does this PR fix or reference?

Fixes #54791
Refs #68252, #62844

Previous Behavior

network.managed on EL8+ failed with No such file or directory: 'ifdown' and wrote no configuration.

New Behavior

On NetworkManager-managed RedHat hosts, network.managed writes NM keyfiles and applies them with nmcli; interfaces come up and persist across reboot.

Tests written?

Yes. 33 unit tests for nm_ip plus deferral tests for rh_ip. The existing rh_ip unit tests were also migrated from the legacy TestCase style to pytest in this branch.

Validated end-to-end on real AlmaLinux 8, 9, and 10 VMs (VMware): nm_ip is selected, network.managed brings the interface up, a second apply is a no-op, and the address persists across reboot.

Platform Provider selected Apply Idempotent Reboot-persist
AlmaLinux 8.10 nm_ip pass pass pass
AlmaLinux 9.4 nm_ip pass pass pass
AlmaLinux 10.2 nm_ip pass pass pass

Branch target

Targeted at 3006.x since it fixes a severity-high regression that makes the state unusable on current EL. Happy to rebase onto master (or a newer branch) if maintainers consider a new provider module more appropriate there.

@ggiesen
ggiesen requested a review from a team as a code owner July 1, 2026 02:42
@dwoz dwoz added the test:full Run the full test suite label Jul 1, 2026
Comment thread salt/modules/nm_ip.py Resolved
Comment thread salt/modules/nm_ip.py Resolved

@charzl charzl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, I think the PR is on the correct direction, just some minor issue that can improve.

Comment thread salt/modules/rh_ip.py Resolved
@ggiesen

ggiesen commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @charzl, good catches - both addressed in the latest push.

Keyfile permissions: switched _write_keyfile to salt.utils.files.fpopen(path, "w", mode=0o600), so the connection file is created and chmod'd to 0600 before any content is written, rather than writing first and chmod'ing a briefly world-readable file afterward. The dead post-hoc os.chmod/try-except is gone. And to your point about secret-bearing fields (wifi PSK, VPN keys) potentially living here later - that's still out of scope for this provider, but the chmod-before-write change means the permissions are already correct for whenever such fields land.

MTU on bond/bridge/vlan: I dug into this rather than adding a warn/error, and it turns out MTU is settable on those types, so I implemented emitting it. You're right that the native [bond]/[bridge]/[vlan] settings have no mtu property, but NetworkManager carries MTU on virtual devices by attaching an 802-3-ethernet setting to the same connection: an [ethernet] mtu= block on the bond/bridge/vlan keyfile (equivalently nmcli con modify <conn> 802-3-ethernet.mtu <n>). So for bond/bridge/vlan I now emit a separate [ethernet] section (ethernet interfaces keep folding mtu into their own [ethernet] device section), which also matches rh_ip's uniform MTU=. Previously mtu was accepted and silently dropped on those types.

Deduplication: the provider-selection gate duplicated in nm_ip.nm_managed and rh_ip._nm_managed is now a single salt.utils.network.nm_managed() helper both call.

While I was in here I closed a few adjacent gaps against the rh_ip parity bar, each with direct + inverse tests: hwaddr -> [ethernet]/[bridge] mac-address (honouring auto/none) and macaddr -> cloned-mac-address; autoneg/speed/duplex -> [ethernet] (offload/channel knobs still refused); bond options generalized from the fixed ten-key map to a validated pass-through of the full kernel bonding set (ad_select, fail_over_mac, min_links, ...); dns-search now also under [ipv6] so it isn't lost on IPv6-only hosts; vlan reorder_hdr/gvrp/loose_binding -> [vlan] flags; and wol -> [ethernet] wake-on-lan.

Validation: beyond the unit tests, I rendered the emitted keyfile for every one of these and parsed it back with libnm on EL8/EL9/EL10/Fedora (NetworkManager 1.40 through 1.56), asserting each property comes back set - 48/48 green, mtu-on-bond included on the old 1.40 stack. So the new keys are accepted across the supported NM range, not just the latest. Changelog added as 5479.added.md.

ggiesen added 5 commits July 11, 2026 14:43
Move tests/unit/modules/test_rh_ip.py to
tests/pytests/unit/modules/test_rh_ip.py, converting the legacy
unittest.TestCase style (LoaderModuleMockMixin, self.assertX) to modern
pytest (configure_loader_modules fixture, plain asserts, pytest.raises).
Faithful style-only migration: all 26 tests preserved and passing; the
legacy file (which no longer runs under the current pytest/py3.12 test
env) is removed.

This lets the rh_ip test suite run in the maintained pytests tree, ahead
of adding NetworkManager-aware provider selection for saltstack#54791.
network.managed has been broken on RedHat-family systems since EL8. The
rh_ip provider writes /etc/sysconfig/network-scripts/ifcfg-* files and
brings interfaces up with ifup/ifdown from the network-scripts package.
That package is not installed by default on EL8+ and is removed entirely
on EL10, so the state fails with

    Unable to run command '['ifdown', 'eth1']' ... No such file or
    directory: 'ifdown'

and configures nothing. Verified on AlmaLinux 8, 9 and 10.

nm_ip writes NetworkManager keyfiles under
/etc/NetworkManager/system-connections/ and applies them with nmcli, the
supported way to manage networking on modern RedHat systems. It supports
ethernet (static/dhcp/disabled, dual-stack), bond, vlan and bridge, with
bond/bridge members written as their own port keyfiles. A deterministic
per-interface connection uuid keeps build_interface output identical to
the keyfile NetworkManager reads back, so the state stays idempotent.

Provider selection is a single condition both modules test: nmcli
present, /run/NetworkManager exists, and no ifup/ifdown on PATH. nm_ip
claims the ip virtual when that holds; rh_ip defers to it. Hosts that
still have network-scripts installed keep the legacy rh_ip behavior.

Also addresses saltstack#68252 and saltstack#62844, which share this root cause.

Validated end to end on AlmaLinux 8, 9 and 10 VMs: nm_ip is selected,
network.managed brings the interface up, a second apply is a no-op, and
the address persists across reboot.
3006.27 was released 2026-07-01 without this provider, so the next
available 3006.x release is 3006.28.
… Amazon deferral

The direct tests call nm_ip.build_interface at the exact altitude
network.managed uses (name, iface_type, enabled, **kwargs with the
state-injected test flag): test=True must return the rendered keyfile
lines for the diff without writing anything (including bond port
keyfiles), and the same call with test=False must write those exact
lines. The inverse tests guard the refactored rh_ip.__virtual__ against
overcorrection: Amazon Linux 2 with network-scripts must still claim ip
and Amazon Linux 1 must still decline, verified against the base branch
module as well.
Close a set of coverage gaps in the nm_ip (NetworkManager keyfile) ip
provider so it maps more of the network.managed schema and moves closer to
rh_ip parity, and address review feedback on keyfile permissions and code
duplication.

Coverage:

- mtu on bond/bridge/vlan is now emitted via a separate [ethernet]
  (802-3-ethernet) section attached to the connection, matching how NM sets
  MTU on virtual devices. Previously it was accepted and silently dropped
  because the native [bond]/[bridge]/[vlan] settings have no mtu key.
  Ethernet interfaces keep folding mtu into their own [ethernet] section.
- hwaddr pins a connection to a NIC's permanent MAC (802-3-ethernet
  mac-address, or bridge.mac-address for bridges), honouring the auto/none
  sentinels. macaddr sets the in-use MAC (802-3-ethernet cloned-mac-address)
  and is mutually exclusive with hwaddr, matching rh_ip.
- The autoneg/speed/duplex ethtool link parameters map to [ethernet]
  auto-negotiate/speed/duplex (speed and duplex must be set together)
  instead of being rejected. Offload/channel/advertise ethtool knobs, which
  have no keyfile equivalent, are still refused.
- Bond options are passed through to [bond] from the full kernel bonding set
  (ad_select, fail_over_mac, primary_reselect, arp_validate,
  all_slaves_active, min_links, ...) rather than a fixed ten-key allow-list.
  Option names are validated and mode stays required.
- dns-search is written under [ipv6] as well as [ipv4], so search domains
  survive on IPv6-only hosts; a disabled family no longer carries a dead
  dns-search line.
- vlan reorder_hdr/gvrp/loose_binding fold into the [vlan] flags bitmask
  (emitted only when it diverges from NM's default), and wol maps to
  [ethernet] wake-on-lan.

Hardening / cleanup:

- Write keyfiles with salt.utils.files.fpopen(mode=0o600) so the connection
  file is created with 0600 permissions before any content is written,
  instead of chmod'ing an already-populated file.
- Extract the shared NetworkManager provider-selection check into
  salt.utils.network.nm_managed; nm_ip.nm_managed and rh_ip._nm_managed now
  both call it so exactly one provider claims the ip module.

Add direct and inverse unit tests for each gap under
tests/pytests/unit/modules/test_nm_ip.py.
charzl
charzl previously approved these changes Jul 13, 2026

@charzl charzl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread salt/modules/nm_ip.py Resolved
Comment thread salt/modules/nm_ip.py Resolved
Comment thread salt/modules/nm_ip.py Resolved
…d-mode error

- _write_keyfile writes to a 0600 mkstemp temp in the keyfile's own directory
  and os.replace()s it onto the target, so NetworkManager (which watches these
  files via inotify) never sees a half-written or briefly world-readable
  keyfile. Replaces the in-place fpopen write; a copy that preserves the
  destination mode (salt.utils.files.copyfile) would let an existing 0644
  keyfile stay world-readable, so it is deliberately not used here.
- _listify also splits on ';', NetworkManager's on-disk array delimiter, so a
  pillar value pre-formatted that way parses into individual entries.
- The missing-bond-mode error names example modes and explains why mode is
  required rather than defaulted (rh_ip requires it too).

Adds direct tests for the atomic 0600 write (including rewriting an existing
0644 keyfile) and for semicolon _listify.
twangboy
twangboy previously approved these changes Jul 15, 2026
@twangboy

Copy link
Copy Markdown
Contributor

Please address the lint failures, otherwise looks good.

The atomic-write test read the file back with a bare open(), which the test
suite's pylint checker flags as W8470 (resource-leakage). Use
salt.utils.files.fopen instead, per the salt convention. This is what broke
Lint / Lint Salt's Test Suite on the previous commit.
@ggiesen

ggiesen commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Done in ec566e2 -- the lint failure was salt's W8470 (resource-leakage) checker flagging two bare open() calls in the test I added; switched them to salt.utils.files.fopen. Test-lint should be green on the re-run. Thanks!

This branch was previously deployed

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

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants