salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG] setting source_address doesn't work if default route doesn't function

Open nickhuber opened this issue 6 years ago • 7 comments

Description If you try and work around a non-functional default route by setting the source_address to something that will get matched by policy routing into a functional routing table, the salt-minion will never try to actually connect with the defined source address. In my case I have a local DNS resolver (unbound) that can resolve the DNS name even though the default route is non-functional

Setup

# ip rule
0:	from all lookup local
100:	from 10.87.100.177 lookup 100
32766:	from all lookup main
32767:	from all lookup default
# ip route show table 100
default via 10.87.100.1 dev eth1 proto static
10.87.100.0/24 dev eth1 proto static scope link
# ip route show table main
default via 10.87.100.1 dev eth1
10.87.100.0/24 dev eth1 proto kernel scope link src 10.87.100.249

I have a local unbound DNS resolver that sends DNS requests out specific source addresses so even though the default route doesn't function DNS requests are able to resolve. I imagine the same behaviour could be imitated by setting an entry in /etc/hosts.

Steps to Reproduce the behavior

Finally, set source_address 10.87.100.177 in the salt-minion configuration and restart salt minion, I can see that there is a socket for the minion but it is not for the configured source address

# ss -antp | grep salt-minion
SYN-SENT   0        1                10.87.100.249:38652        10.87.100.5:4506    users:(("salt-minion",pid=707967,fd=15))

The minion never connects.

Expected behavior With a source_address defined, the minion should try and connect with the source address set in the configuration. Right now it seems in minion.py.resolve_dns it will first try and connect to the master without considering the source_address configuration setting before continuing.

Versions Report

# salt-minion  --versions
Salt Version:
           Salt: 2018.3.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.7.3
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.7.3 (default, Dec 20 2019, 18:57:59)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.1.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.1

System Versions:
           dist: debian 10.4
         locale: utf-8
        machine: x86_64
        release: 5.8.4-200.fc32.x86_64
         system: Linux
        version: debian 10.4

Additional context If I set my master to an IP address instead of hostname everything functions as expected, so it purely seems to be a problem with how connectivity is checked with the master being a hostname.

nickhuber avatar Sep 08 '20 21:09 nickhuber

@nickhuber Thank you for reporting this issue.

I see you reported this issue against version 2018.3.4, which is an unsupported version of salt. https://www.saltstack.com/product-support-lifecycle/

Do you you see the same behavior on 3000 or 3001?

Thanks.

frogunder avatar Sep 09 '20 16:09 frogunder

I haven't tested on 3000 yet, but I briefly looked through the code for the resolve_dns function on the master branch and it seems that it follows the same logic as the 2018.3.4 version. I'll see if I can test on a newer version.

nickhuber avatar Sep 09 '20 17:09 nickhuber

So I just ran the test again with salt 3001.1 and saw the same behaviour

Here are some debug logs

[DEBUG   ] Elapsed time getting FQDNs: 0.11469745635986328 seconds
[DEBUG   ] LazyLoaded zfs.is_supported
[INFO    ] Creating minion process manager
[DEBUG   ] Process Manager starting!
[DEBUG   ] Process Manager starting!
[DEBUG   ] Connecting to master. Attempt 1 of 1
[DEBUG   ] "m.nick.cwk.multapplied.net" Not an IP address? Assuming it is a hostname.
[DEBUG   ] Using 10.87.100.177 as source IP address
[DEBUG   ] Master URI: tcp://10.87.100.5:4506
[DEBUG   ] Initializing new AsyncAuth for ('/var/lib/salt/pki/minion', 'node-7', 'tcp://10.87.100.5:4506')
[DEBUG   ] Generated random reconnect delay between '2000ms' and '62000ms' (7074)
[DEBUG   ] Setting zmq_reconnect_ivl to '7074ms'
[DEBUG   ] Setting zmq_reconnect_ivl_max to '62000ms'
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/var/lib/salt/pki/minion', 'node-7', 'tcp://10.87.100.5:4506', 'clear')
[DEBUG   ] Connecting the Minion to the Master URI (for the return server): tcp://10.87.100.5:4506
[DEBUG   ] Trying to connect to: tcp://10.87.100.5:4506
[DEBUG   ] salt.crypt.get_rsa_pub_key: Loading public key
[ERROR   ] Minion unable to successfully connect to a Salt Master.
[DEBUG   ] SaltReqTimeoutError, retrying. (1/7)
[DEBUG   ] SaltReqTimeoutError, retrying. (2/7)
[DEBUG   ] SaltReqTimeoutError, retrying. (3/7)
[DEBUG   ] SaltReqTimeoutError, retrying. (4/7)
[DEBUG   ] SaltReqTimeoutError, retrying. (5/7)
[DEBUG   ] SaltReqTimeoutError, retrying. (6/7)
[DEBUG   ] SaltReqTimeoutError, retrying. (7/7)
[DEBUG   ] Re-init ZMQ socket: Message timed out
[DEBUG   ] Trying to connect to: tcp://10.87.100.5:4506
[DEBUG   ] Closing AsyncZeroMQReqChannel instance
[ERROR   ] Error while bringing up minion for multi-master. Is master at m.nick.cwk.multapplied.net responding?

Despite the logs stating that 10.87.100.177 is being used as a source address if I look at the socket I can see that is a lie.

# ss -antp | grep salt
SYN-SENT    0        1               10.87.100.240:51828       10.87.100.5:4506     users:(("salt-minion",pid=861368,fd=37))

nickhuber avatar Sep 09 '20 18:09 nickhuber

in minion.py The master_uri is set here, and it doesn't take into account the source_address that is passed so no matter what you set as the source_address or source_interface_name, the salt-minion still connects using the source ip of the outgoing interface.

    ret["master_uri"] = "tcp://{ip}:{port}".format(
        ip=ret["master_ip"], port=opts["master_port"]
    )

I made this modification which seems to work.

    s_ip=''
    if opts["source_interface_name"] or opts["source_address"]:
      s_ip=ret['source_ip']+":0;"

    ret["master_uri"] = "tcp://{src_ip}{ip}:{port}".format(
        ip=ret["master_ip"], port=opts["master_port"], src_ip=s_ip
    )

edwinlam09 avatar May 15 '22 05:05 edwinlam09

Is this bug going to be fixed? It's been quite a while since it's identified as bug and the fix doesn't seem to be too hard.

seanzhang422 avatar May 31 '24 06:05 seanzhang422

@seanzhang422 Would be happy to take a PR with tests, if the problem still exists, current supported version of Salt is 3006.8, does the issue still apply on this supported version.

Noting that the Salt team has been reduced significantly recently, hence the request for a PR that fixes the issue.

dmurphy18 avatar May 31 '24 16:05 dmurphy18

Thanks for the original report. This issue has been open for more than three years without recent activity and carries a severity label below severity-high. As part of a backlog cleanup, we're closing older low- and medium-severity issues so triage can focus on reports against currently supported releases.

Closing isn't a judgement that the problem wasn't real — only that the codebase has moved through several releases since this was filed, and much of the surrounding code has changed.

If you — or anyone else — can still reproduce this on the 3008.x LTS release, please leave a comment with a reproduction and a maintainer will reopen. The original reporter can also reopen directly.

dwoz avatar Oct 15 '26 23:10 dwoz