Challenges with OpenVPN and configuring DNS
Hi,
Arne and I have discussed the challenge of DNS configuration and we have paid attention to a recent discussion here on the mailing list as well [1]. We have tried to consider various platforms and have a few proposals for unifying and documenting DNS configuration as much as possible.
[1]
<https://www.mail-archive.com/[email protected]/msg19512.html>
Message-Id: <[email protected]...>
DNS configuration has become fairly advanced in the later OS releases, compared to the traditional "send all requests to this DNS server" we're all very well used to.
Scenarios we have considered:
* Exclusive DNS resolver
All DNS lookup requests should go to a specified DNS server regardless of the host configuration prior to the VPN connection.
* Split-DNS
Only selected "route domains" should use the provided DNS server
* Windows has it's own DOMAIN setting which may impact how it handles DNS and NetBios configurations
* Some platforms differentiates between "search domains" (which is the typical 'search' option in /etc/resolv.conf) and "route domains" (which domains should use a specific DNS resolver)
* DNSSEC
Some resolver libraries supports enforcing or disabling DNSSEC - and some prefers DNSSEC but allows a downgrade (most typically needed for some login portals, where DNS lookups triggers a redirect if you are not already logged in).
We have the --dhcp-option option today, which can configure some of these parameters, but its implementation can often be inconsistent across platforms. We propose here to standardize and properly document the expected behavior.
--dhcp-option settings
- DNS
Provides an IPv4/IPv6 address to a DNS resolver to use. Can be used multiple times.
- DOMAIN
Set Connection-specific DNS Suffix to name. This should only be set once. On Windows this will have a platform specific meaning. Only the first DOMAIN should be expected to be handled.
If ``--dns-mode`` is set to default, DOMAIN will also be added to DOMAIN-SEARCH. For compatibility with existing servers pushing multiple DOMAIN entries, additional DOMAIN entries are appended to the DOMAIN-SEARCH list.
- DOMAIN-SEARCH
This is the equivalent to the traditional DNS Domain Search setting (like search in /etc/resolv.conf). Short hostnames will attempt DNS resolving using domains in all enlisted DOMAIN-SEARCH entries which results into a FQDN hostname for the lookup.
- DOMAIN-ROUTE
This can be used multiple times and defines domains which should only be resolved via the given DNS resolver. The lookup is based on a FQDN hostname, expanded via DOMAIN-SEARCH.
- DNSSEC
Defines the expected DNSSEC behavior of the resolver. Valid values:
:code:yes
If the provided DNS server does not support DNSSEC, look-ups will fail if this mode is used.
:code:no
DNSSEC validation is disabled.
:code:allow-downgrade
DNSSEC validation is enabled, but is turned off automatically if the selected server does not support it.
If DNSSEC is not configured, it will default to the default host configuration.
We also propose to add a new OpenVPN option to tell the platform specific DNS resolver how it should understand the --dhcp-options DNS related options:
--dns-mode mode
This defines how pushed DNS configuration settings should be processed when OpenVPN configures the DNS resolver on the host. mode can one of these values:
- default
Current default behavior, defined by the platform. This should typically not change the behavior much from prior OpenVPN releases.
- split-dns
Pushed DNS options should only be used for the VPN session. Hostname lookups will consider DOMAIN, DOMAIN-SEARCH and DOMAIN-ROUTE. If a FQDN hostname matches any of these, the lookup should only be sent to the provided DNS resolver. Non-matching lookups should go to the system defined DNS resolvers.
- exclusive
Any DNS lookup should go to to the DNS resolver provided by the OpenVPN server exclusively. Any other system defined resolvers should not be considered.
In addition we also propose to provide a possibility for OpenVPN clients to signal to the server what kind of DNS configuration it can support. The rationale here is so the server can decide if it wants to allow the connection (some VPN admins may want their clients to support specific features) or more advanced servers may adopt the DNS configuration it pushes to their clients, to get a more consistent behavior across VPN clients.
To avoid extending the IV_* scope with even more values, we are proposing to redo IV_PROTO to be a bit-field oriented variable. This is still possible as we currently have only defined the values of 1 and 2. We propose the following bit-mask:
- bit 0 (1)
Reserved (this is essentially today's IV_PROTO=1)
- bit 1 (2)
Supports P_DATA_V2 (IV_PROTO=2 in current implementations)
- bit 2 (4) - Extended DNS support
Supports the additional DNS options: DOMAIN-SEARCH, DOMAIN-ROUTE, DNSSEC. DOMAIN will only allowed once.
- bit 3 (8) - Split DNS
Client can configure split DNS on the host
- bit 4 (16) - Blocking/Exclusive DNS
Client can configure exclusive DNS with blocking (exclusive)
- bit 5 (32) - DNSSEC
Client can modify DNSSEC configuration for VPN DNS resolver based on the DNSSEC option.
We have looked through the other IV_* options as well, and we can also consider to allocate a bit for IV_TCPNL and start a process to deprecate the dedicated IV_TCPNL variable. This is to save space in the IV_* already limited IV buffer.
We considered the compression options as well (IV_LZO, IV_LZ4, IV_LZ4v2 and IV_COMP_STUB*) but believe these should move away from compression in the future.
Some of these IV_PROTO settings can on some platforms be added into OpenVPN itself. But we believe it is good to also allow the --plugin and script hooks to also facilitate these settings. This allows a simpler OpenVPN binary to signal to the server that it intends to support various features. In this discussion, we also realized this can also be used for the auth-pending feature as well, which currently is only supported via the management interface.
We therefore suggests adding yet another OpenVPN option:
--feature-support GROUP TEXT-FLAGS
* GROUP: dns with these flags:
- extended
sets IV_PROTO bit 2 if not already set.
- split-dns
sets IV_PROTO bit 3
- dns-block
sets IV_PROTO bit 4
- dnssec
sets IV_PROTO bit 5
* GROUP: auth-pending
This signals to the server which kind of pending authentication features the client can support
- openurl
Adds openurl to IV_SSO
- proxyurl
Adds proxyurl to IV_SSO
- crtext
Adds crtext to IV_SSO
For platform implementations we have considered the following:
* macOS
Tunnelblick uses external scripts which are well tested and seems to work fine. Will it make sense to implement native DNS configuration support into OpenVPN on macOS? This might mean we need to link OpenVPN against some Objective-C code to communicate directly with the network configuration APIs. It could also be possible to implement this as an external plug-in, which extends OpenVPN's current behavior.
* Windows
On Windows we already have a native implementation. We did not consider any alternative approaches here.
* Android
Has its own implementation in OpenVPN for Android, with ideas from the the Windows implementation. This also facilitates the possibilities provided via the VPN API in Android.
* Linux
Currently uses --up scripts (pull-resolv-conf, update-systemd-resolved) and --plugin (NetworkManager). It is possible to implement a plug-in which talks directly to systemd-resolved as well. Native support included would require linking against a D-Bus library, which can become pretty invasive.
There are some advantages to move over to a --plugin
for systemd-resolved support, as it can interact quicker with the service instead of running a script which parses options and does the same D-Bus calls to systemd-resolved. But this will not get a too high priority as the script based update-systemd-resolved approach will work well too.
OpenVPN 3 Linux will be extended with native systemd-resolved support in a coming release.
* *BSD
We do not know enough of the capabilities here. But a both script and --plugin solutions can work, especially if facilitating the new --feature-support option - where it will be more up to the script/plug-in to define what it will be capable of.
--
kind regards,
Arne Schwabe
David Sommerseth
OpenVPN Inc
Hi. There's a lot here and I haven't digested all of it, but have a couple of comments about macOS and Tunnelblick, below.
Quoted 27 lines · David Sommerseth
Hi,
Arne and I have discussed the challenge of DNS configuration and we have paid attention to a recent discussion here on the mailing list as well [1]. We have tried to consider various platforms and have a few proposals for unifying and documenting DNS configuration as much as possible.
[1]
<https://www.mail-archive.com/[email protected]/msg19512.html>Message-Id: <[email protected]...>DNS configuration has become fairly advanced in the later OS releases, compared to the traditional "send all requests to this DNS server" we're all very well used to.
Scenarios we have considered:
* Exclusive DNS resolver
All DNS lookup requests should go to a specified DNS server regardless of the host configuration prior to the VPN connection.* Split-DNS
Only selected "route domains" should use the provided DNS server
Quoted 6 lines
* Windows has it's own DOMAIN setting which may impact how it handles DNS and NetBios configurations
* Some platforms differentiates between "search domains" (which is the typical 'search' option in
/etc/resolv.conf) and "route domains" (which domains should use a specific DNS resolver)
Tunnelblick implements "search domains" by setting a list of macOS "SearchDomains". It isn't well documented, but as I understand it, a name that doesn't resolve is suffixed with the first "search domain" in the list and the result is looked up. If that doesn't resolve, the name is suffixed with the next "search domain" in the list, and the process is repeated. Is that what "the typical 'search' option in /etc/resolv.conf" does?
Currently Tunnelblick on macOS does not implement "route domains" — but they are "on my list".
<snip>
Quoted 9 lines
For platform implementations we have considered the following:
* macOS
Tunnelblick uses external scripts which are well tested and seems to work fine. Will it make sense to implement native DNS configuration support into OpenVPN on macOS? This might mean we need to link OpenVPN against some Objective-C code to communicate directly with the network configuration APIs. It could also be possible to implement this as an external plug-in, which extends OpenVPN's current behavior.
Building support for macOS network changes into OpenVPN would be a challenge to maintain.
The combination of
* Supporting Apple's annual release of a new version of macOS which
often changes the way changes to the network setup are done (probably four times in the past ten years); and
* Apple's terrible or nonexistent documentation; and
* Supporting multiple versions of macOS that each use a different mechanism
means there's a lot of work to do. (I know, because I'm doing it : )
That said, it would be cleaner/nicer to implement it within OpenVPN or as a plug-in, instead of having it happen in the "up", "down", and "reconnect" scripts. I can't commit to being involved in working on that, though I might provide comments or advice occasionally.
(As an aside, Apple tends to throw away stuff that works in favor of new, shiny stuff and they do that all the time. They've been pushing developers to use Swift, not Objective-C for a while now. Tunnelblick has stuck with Objective-C, but it isn't clear how long Apple will keep supporting it. Even so, I agree that code for macOS is integrated into OpenVPN, the code should be written in Objective-C.)
Best regards,
Jon