saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
13.98k stars 5.47k forks source link

[BUG] salt-ssh breaks on FreeBSD if IFCONFIG_FORMAT is set to return CIDR #66571

Open hhartzer opened 1 month ago

hhartzer commented 1 month ago

Description salt-ssh does not work on FreeBSD if IFCONFIG_FORMAT is set in such a way as to return CIDR notation instead of netmask notation.

Setup

FreeBSD 14.0

Steps to Reproduce the behavior

This breaks locally, before even talking to any "minions."

IFCONFIG_FORMAT=inet:cidr,inet6:cidr salt-ssh ...

Output:

salt-ssh: error: Error while processing <bound method ConfigDirMixIn.process_config_dir of <salt.cli.ssh.SaltSSH object at 0x2e898649ab50>>: Traceback (most recent call last):
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/parsers.py", line 196, in parse_args
    process_option_func()
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/parsers.py", line 570, in process_config_dir
    self.config.update(self.setup_config())
                       ^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/parsers.py", line 3406, in setup_config
    return config.master_config(self.get_config_file_path())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/config/__init__.py", line 3937, in master_config
    opts = apply_master_config(overrides, defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/config/__init__.py", line 4043, in apply_master_config
    opts["id"], using_ip_for_id = get_id(opts, cache_minion_id=None)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/config/__init__.py", line 3658, in get_id
    newid = salt.utils.network.generate_minion_id()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/network.py", line 225, in generate_minion_id
    ret = salt.utils.stringutils.to_unicode(_generate_minion_id().first())
                                            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/network.py", line 214, in _generate_minion_id
    [addr for addr in ip_addrs() if not ipaddress.ip_address(addr).is_loopback]
                      ^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/network.py", line 1455, in ip_addrs
    return _ip_addrs(interface, include_loopback, interface_data, "inet")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/salt/lib/python3.11/site-packages/salt/utils/network.py", line 1442, in _ip_addrs
    addr = ipaddress.ip_address(addr.get("address"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ipaddress.py", line 54, in ip_address
    raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
ValueError: '192.168.1.100/24' does not appear to be an IPv4 or IPv6 address

Expected behavior

It should work as it does normally.

Additional context

https://github.com/freebsd/freebsd-src/pull/1216

It's possible to force ifconfig to use netmasks by setting the environment variable like so: IFCONFIG_FORMAT=inet:hex,inet6:numeric. This may be the easiest fix.

igalic commented 1 month ago

It's possible to force ifconfig to use netmasks by setting the environment variable like so: IFCONFIG_FORMAT=inet:hex,inet6:numeric. This may be the easiest fix.

it's equally possible to write code that gracefully handles both formats, https://github.com/canonical/cloud-init/pull/5272 and if somebody is already touching the code, why not do that?