Skip to content

[BUG] Minion behind NAT incorrectly shows not connected #66295

Open

Description

@merlinz01

Description
I have a minion on my local network connecting to a cloud-based master. That minion never shows as connected, but all my minions with public IP addresses do show as connected. That is, the local minion doesn't show as connected in SaltGUI, nor show up in the results of salt-run manage.present. However, salt functions still work because it is actually connected.

I did some digging around in the Salt source code and discovered that the problem is in the way Salt determines whether a minion is connected.
It works like this:

  1. Get the list of known minions.
  2. Run ss -ant src <master_publish_port> to get a list of active network connections to the master's port.
  3. Compare the list of active connections with each minion's reported IP addresses (like running ip address on the minion).
  4. If one of the minion's reported IP addresses is in the list of connections, it must be connected.
  5. If not, then it is assumed disconnected.

The problem is that when a minion is behind NAT, it doesn't know its public IP address, and therefore is never connected according to this algorithm. A much better way to do it would be for the Salt master to keep a list of the minions that it received a connection from.
However I am not familiar with ZeroMQ so maybe this is impossible?

Setup

Please be as specific as possible and give set-up details.

  • on-prem machine
  • VM (Virtualbox, KVM, etc. please specify)
  • VM running on a cloud service, please be explicit and add details
  • container (Kubernetes, Docker, containerd, etc. please specify)
  • or a combination, please be explicit
  • jails if it is FreeBSD
  • classic packaging
  • onedir packaging
  • used bootstrap to install

Steps to Reproduce the behavior
salt-run manage.present
is showing

- (all minions except fs2)

Expected behavior
salt-run manage.present
should show

- fs2
- (other minions)

Screenshots
image

Versions Report

Salt Version:
          Salt: 3007.0

Python Version:
        Python: 3.10.13 (main, Feb 19 2024, 03:31:20) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.16.0
      cherrypy: unknown
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.3
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.15.1
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.3.3
           ZMQ: 4.3.4

Salt Package Information:
  Package Type: onedir

System Versions:
          dist: debian 12.5 bookworm
        locale: utf-8
       machine: x86_64
       release: 6.1.0-18-amd64
        system: Linux
       version: Debian GNU/Linux 12.5 bookworm

Additional context

Activity

  1. added
    bug
    on Apr 2, 2024
  2. welcome commented on Apr 2, 2024

    @welcome

    Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
    Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

    There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
    If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

  3. added this to the Sulfur v3006.8 milestone on Apr 10, 2024
  4. 18 remaining items

  5. added
    severity-medium
    on Oct 21, 2026
  6. cstrahan commented on Oct 23, 2026

    @cstrahan
    Contributor

    Confirming this still reproduces on 3008.3, and adding some findings from
    digging into it that I think change how it should be scoped.

    Setup: a master managing minions across two networks. manage.present returns
    only the minions local to the master's own network; minions in the other
    network are absent while salt -C '<id>' test.ping answers true instantly.

    There is no fallback — every id-level presence path is the same check

    entry point source
    manage.present / alived / joined / allowed / reaped list_state() → CkMinions.connected_ids()
    presence_events connected_ids() (master.py, Maintenance.handle_presence)
    wheel minions.connected con_cache if enabled, else connected_ids()
    con_cache CacheWorker.run() → connected_ids()

    So there's no "use X instead" workaround to point people at — they all inherit
    the grains-IP comparison.

    con_cache looks like a workaround but isn't

    This one surprised me. The master records the correct id at authentication:

    # salt/master.py
    if self.cache_cli:
        self.cache_cli.put_cache([load["id"]])

    That's NAT-safe, since auth carries the id. But then:

    # salt/utils/master.py — CacheWorker.run()
    new_mins = list(salt.utils.minions.CkMinions(self.opts).connected_ids())
    cc.put_cache([new_mins])        # replaces the whole list

    Correct ids go in at auth and the periodic refresh sweeps them back out. So
    con_cache: True doesn't help here, which is worth knowing before suggesting
    it.

    Also: detect_remote_minions isn't applicable — it defaults off and keys on
    remote_minions_port, default 22, which is a different (salt-ssh-shaped)
    scenario.

    The TCP transport already solves this correctly

    This seems like the most useful thing I found. On transport: tcp, presence is
    tracked in the transport, keyed by authenticated minion id:

    # salt/channel/server.py — presence_callback
    if not self.aes_funcs.verify_minion(load["id"], load["tok"]):
        return
    subscriber.id_ = load["id"]
    self._add_client_present(subscriber)      # self.present[id_] = {client}

    with remove_presence_callback on disconnect — and Maintenance.__init__
    deliberately skips the connected_ids() polling when the transport is
    tcp-only ("For a TCP only transport, the presence events will be handled in
    the transport code").

    So this isn't "salt can't do correct presence", it's "0MQ doesn't, and TCP
    does"
    . The asymmetry seems like the right frame for a fix.

    One dead end, to save someone the time

    The obvious fix — record the source address seen at auth and match on that too
    — doesn't appear implementable on 0MQ. The auth handler only receives the
    decoded payload (handle_message(self, stream, payload) →
    self.message_handler(payload)), and the ROUTER socket sits behind a
    zmq_device proxying to workers over an internal DEALER, so the peer is gone
    by then; a ROUTER identity frame is a ZeroMQ identity, not an address. The
    master has the id and no address.

    Similarly, just making CacheWorker stop clobbering the auth-recorded ids
    isn't enough on its own — nothing would ever remove an entry, so it would
    trade silent under-reporting for silent over-reporting.

    Possible directions

    Happy to put up a PR if a maintainer has a preference on scope:

    1. Make the failure visible. connected_ids() can see it has established
      connections on the publish port matching no cached minion. Logging that
      count would turn a confidently-wrong answer into a detectable one. No
      behaviour change; smallest useful thing.
    2. Make the matched grain keys configurable (currently hardcoded ipv4 /
      ipv6), so a NAT'd fleet can surface its externally-visible address as a
      grain and have presence work. Backward compatible, but needs operator
      setup.
    3. Give 0MQ an id-keyed presence signal of the kind TCP has — e.g. tracking
      last-seen per id from authenticated traffic on the ret port. Bigger, and
      presumably wants a maintainer's view on whether that's the direction before
      anyone writes it.
  7. cstrahan commented on Oct 28, 2026

    @cstrahan
    Contributor

    I've opened a discussion around one way we could resolve this: #70582

    The proposed solution is implemented on one of my branches (described in that discussion).

  8. twangboy commented on Oct 30, 2026

    @twangboy
    Contributor

    Does this address the issue? #70385

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions