core: IPsec site to site with dynamic DNS results in "unable to resolve %any, initiate aborted" on initialization

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

I’ll start by stating that I’m not sure if this is indeed a bug or me just misunderstanding things. But, to me it looks like a likely bug.

I’m currently running OPNsense 23.1.1_2-amd64. I recently did an upgrade, but I’m not sure from which version that was. I don’t think this used to be an issue, but I can’t be sure of that either because the tunnel works if initiated by the remote party.

The problem is that if I enable Allow any remote gateway to connect under phase 1 IPsec settings, it won’t connect to the remote party. It will log unable to resolve %any, initiate aborted, and nothing further seems to happen. Both parties (OPNsense in this end, an older pfSense in the other) have dynamically assigned IP addresses and thus use dynamic DNS for resolving the remote addresses. If I initiate the connection from the pfSense installation, the tunnel goes up and everything works just fine. But, initiation from the OPNsense end seems impossible.

If I disable Allow any remote gateway to connect, OPNsense will also connect straight away. Why not just leave it disabled then? This is where I’m unsure if I misunderstand something. The “help text” for Allow any remote gateway to connect states:

Recommended for dynamic IP addresses that can be resolved by DynDNS at IPsec startup or update time.

This sounds like something I should have enabled from the description. My understanding is that it won’t reject the remote party during initialization if the remote IP doesn’t match the remote DNS entry. That might happen just after a change, due to DNS caching before expiry. So, it seems like a good idea not to reject the other party if this situation occurs.

It should however not, as I understand it, affect the “outgoing address” when trying to initiate a connection. The error seems to indicate that it’s trying to establish a connection with an undefined remote address. That’s not the case, it should still use that specified under Remote Gateway when initializing a connection.

To Reproduce

I’m not sure what circumstances that’s required for this to happen, except that Allow any remote gateway to connect must be enabled. This happens even if I put a static IP in the Remote Gateway field, as long as Allow any remote gateway to connect is enabled. That might be all it takes to reproduce, but to narrow it down a but, I can mention that I’m using IKEv2, IPv4, Start immediate, Mutual PSK, and User distinguished name for both identifiers. It’s hard to imagine that the encryption, hashing or phase 2 settings matter as it never comes to any of that.

Expected behavior

I expect that it’s possible to initiate a IPsec connection even if Allow any remote gateway to connect is enabled.

Environment

OPNsense 23.1.1_2 (amd64, OpenSSL 1.1.1t) Intel® Atom™ CPU C3558 @ 2.20GHz (4 cores, 4 threads)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for confirming. I’m considering this as a hotfix for later this week.

@Nadahar ok, thanks for reporting back. I expect that %any and 0.0.0.0, ::0/0 are more or less the same for mobile, but better to leave it as it was in this case.

@AdSchellevis With 3af487bcf65a4d8a32ea999f16f1a932620e80e7 it works 👍

While I don’t know how this impacts mobile clients, it sounds logical to me that it should be left with %any given that the firewall never (?) initiates a connection to a mobile client, so it doesn’t need an address to connect to.

23.1.2 next week.

Reading the migration notes again, this looks like a bug indeed. should be fixed with https://github.com/opnsense/core/commit/24806500c55a51979ec8ff3fac06520e454ce03e

The rightallowany option should be translated to ipv4+ipv6 subnet according to https://wiki.strongswan.org/projects/strongswan/wiki/Fromipsecconf (we switched from ipsec.conf to swanctl.conf in 23.1)