Disable multiple deferred authentication
v4 cover Disable multiple deferred authentication
From: David Sommerseth <[email protected]...>
It was discovered an issue with OpenVPN 2.x when multiple --plugin modules were loaded and more than one of them used deferred authentication. To fix this properly will require a larger refactoring of the plug-in code, so it was decided in the mean time to disable the possibility to run an OpenVPN server with such a setup. This issue affects the OpenVPN server mode only.
This patch set adds a new test plug-in and adds some test documentation on how to test various combinations of authentication plug-ins. Since this new plug-in (multi-auth.c) is fairly close to the simple.c plug-in, just more flexible for test setups, we remove the old one. The fix itself is isolated in a separate patch in this set.
The order of patches are insignificant; there are no inter-dependencies between them.
--
kind regards,
David Sommerseth
OpenVPN Inc
---
David Sommerseth (3):
sample-plugin: New plugin for testing multiple auth plugins
plug-ins: Disallow multiple deferred authentication plug-ins
plugins: Remove defer/simple.c sample plugin
doc/man-sections/plugin-options.rst | 9 +
doc/tests/authentication-plugins.md | 153 +++++++++++
include/openvpn-plugin.h.in | 4 +-
sample/sample-plugins/Makefile.plugins | 2 +-
sample/sample-plugins/README | 6 +-
.../defer/{simple.c => multi-auth.c} | 248 ++++++++++--------
sample/sample-plugins/defer/simple.def | 6 -
src/openvpn/plugin.c | 33 ++-
8 files changed, 333 insertions(+), 128 deletions(-)
create mode 100644 doc/tests/authentication-plugins.md
rename sample/sample-plugins/defer/{simple.c => multi-auth.c} (61%)
delete mode 100755 sample/sample-plugins/defer/simple.defSignature · 1 line
2.27.0
PATCH v4 1/3 sample-plugin: New plugin for testing multiple auth plugins
From: David Sommerseth <[email protected]...>
This plugin allows setting username/passwords as well as configure deferred authentication behaviour as part of the runtime initialization.
With this plug-in it is easier to test various scenarios where multiple authentication plug-ins are active on the server side.
A test documentation was also added to describe various test cases and the expected results.
---
v2 - Flipped NULL==var to var==NULL
--- doc/tests/authentication-plugins.md | 153 +++++++++ sample/sample-plugins/Makefile.plugins | 1 + sample/sample-plugins/defer/multi-auth.c | 413 +++++++++++++++++++++++ 3 files changed, 567 insertions(+) create mode 100644 doc/tests/authentication-plugins.md create mode 100644 sample/sample-plugins/defer/multi-auth.c
doc/tests/authentication-plugins.md new file +153 -0
@@ -0,0 +1,153 @@ +# TESTING OF MULTIPLE AUTHENTICATION PLUG-INS + + +OpenVPN 2.x can support loading and authenticating users through multiple +plug-ins at the same time. But it can only support a single plug-in doing +deferred authentication. However, a plug-in supporting deferred +authentication may be accompanied by other authentication plug-ins **not** +doing deferred authentication. + +This is a test script useful to test the various combinations and order of +plug-in execution. + +The configuration files are expected to be used from the root of the build +directory. + +To build the needed authentication plug-in, run: + + make -C sample/sample-plugins + + +## Test configs + +* Client config + + verb 4 + dev tun + client + remote x.x.x.x + ca sample/sample-keys/ca.crt + cert sample/sample-keys/client.crt + key sample/sample-keys/client.key + auth-user-pass + +* Base server config (`base-server.conf`) + + verb 4 + dev tun + server 10.8.0.0 255.255.255.0 + dh sample/sample-keys/dh2048.pem + ca sample/sample-keys/ca.crt + cert sample/sample-keys/server.crt + key sample/sample-keys/server.key + + +## Test cases + +### Test: *sanity-1* + +This tests the basic authentication with an instant answer. + + config base-server.conf + plugin multi-auth.so S1.1 0 foo bar + +#### Expected results + - Username/password `foo`/`bar`: **PASS** + - Anything else: **FAIL** + + +### Test: *sanity-2* + +This is similar to `sanity-1`, but does the authentication +through two plug-ins providing an instant reply. + + config base-server.conf + plugin multi-auth.so S2.1 0 foo bar + plugin multi-auth.so S2.2 0 foo bar + +#### Expected results + - Username/password `foo`/`bar`: **PASS** + - Anything else: **FAIL** + + +### Test: *sanity-3* + +This is also similar to `sanity-1`, but uses deferred authentication +with a 1 second delay on the response. + + plugin multi-auth.so S3.1 1000 foo bar + +#### Expected results + - Username/password `foo`/`bar`: **PASS** + - Anything else: **FAIL** + + +### Test: *case-a* + +Runs two authentications, the first one deferred by 1 second and the +second one providing an instant response. + + plugin multi-auth.so A.1 1000 foo bar + plugin multi-auth.so A.2 0 foo bar + +#### Expected results + - Username/password `foo`/`bar`: **PASS** + - Anything else: **FAIL** + + +### Test: *case-b* + +This is similar to `case-a`, but the instant authentication response +is provided first before the deferred authentication. + + plugin multi-auth.so B.1 0 foo bar + plugin multi-auth.so B.2 1000 test pass + +#### Expected results + - **Always FAIL** + - This test should never pass, as each plug-in expects different + usernames and passwords. + + +### Test: *case-c* + +This is similar to the two prior tests, but the authentication result +is returned instantly in both steps. + + plugin multi-auth.so C.1 0 foo bar + plugin multi-auth.so C.2 0 foo2 bar2 + +#### Expected results + - **Always FAIL** + - This test should never pass, as each plug-in expects different + usernames and passwords. + + +### Test: *case-d* + +This is similar to the `case-b` test, but the order of deferred +and instant response is reversed. + + plugin ./multi-auth.so D.1 2000 test pass + plugin ./multi-auth.so D.2 0 foo bar + +#### Expected results + - **Always FAIL** + - This test should never pass, as each plug-in expects different + usernames and passwords. + + +### Test: *case-e* + +This test case will run two deferred authentication plug-ins. This is +**not** supported by OpenVPN, and should therefore fail instantly. + + plugin ./multi-auth.so E1 1000 test1 pass1 + plugin ./multi-auth.so E2 2000 test2 pass2 + +#### Expected results + - The OpenVPN server process should stop running + - An error about multiple deferred plug-ins being configured + should be seen in the server log. + +
sample/sample-plugins/Makefile.plugins +1 -0
@@ -8,6 +8,7 @@ # PLUGINS = \ defer/simple \ + defer/multi-auth \ keying-material-exporter-demo/keyingmaterialexporter \ log/log log/log_v3 \ simple/base64 \
sample/sample-plugins/defer/multi-auth.c new file +413 -0
413 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 2/3 plug-ins: Disallow multiple deferred authentication plug-ins
In reply to David SommersethFrom: David Sommerseth <[email protected]...>
The plug-in API in OpenVPN 2.x is not designed for running multiple deferred authentication processes in parallel. The authentication results of such configurations are not to be trusted. For now we bail out when this discovered with an error in the log.
CVE: 2022-0547
---
v2 - flip CONSTANT==var to var==CONSTANT in if() clause v3 - Use M_FATAL instead of M_ERR
--- doc/man-sections/plugin-options.rst | 9 ++++++++ src/openvpn/plugin.c | 33 ++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-)
doc/man-sections/plugin-options.rst +9 -0
@@ -55,3 +55,12 @@ plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. (such as tls-verify, auth-user-pass-verify, or client-connect), then every module and script must return success (:code:`0`) in order for the connection to be authenticated. + + **WARNING**: + Plug-ins may do deferred execution, meaning the plug-in will + return the control back to the main OpenVPN process and provide + the plug-in result later on via a different thread or process. + OpenVPN does **NOT** support multiple authentication plug-ins + **where more than one of them** do deferred authentication. + If this behaviour is detected, OpenVPN will shut down upon first + authentication.
src/openvpn/plugin.c +30 -3
@@ -802,7 +802,7 @@ plugin_call_ssl(const struct plugin_list *pl,const char **envp;const int n =plugin_n (pl);bool error = false; -bool deferred = false; +bool deferred_auth_done = false;setenv_del (es,"script_type" ); envp =make_env_array (es, false, &gc);
@@ -824,7 +824,34 @@ plugin_call_ssl(const struct plugin_list *pl,break ;case OPENVPN_PLUGIN_FUNC_DEFERRED : - deferred = true; +if ((type ==OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY ) + && deferred_auth_done) + { +/* +* Do not allow deferred auth if a deferred auth has +* already been started. This should allow a single +* deferred auth call to happen, with one or more +* auth calls with an instant authentication result. +* +* The plug-in API is not designed for multiple +* deferred authentications to happen, as the +* auth_control_file file will be shared across all +* the plug-ins. +* +* Since this is considered a critical configuration +* error, we bail out and exit the OpenVPN process. +*/ + error = true; +msg (M_FATAL , +"Exiting due to multiple authentication plug-ins " +"performing deferred authentication. Only one " +"authentication plug-in doing deferred auth is " +"allowed. Ignoring the result and stopping now, " +"the current authentication result is not to be " +"trusted." ); +break ; + } + deferred_auth_done = true;break ;default :
@@ -844,7 +871,7 @@ plugin_call_ssl(const struct plugin_list *pl, {return OPENVPN_PLUGIN_FUNC_ERROR ; } - else if (deferred) + else if (deferred_auth_done) {return OPENVPN_PLUGIN_FUNC_DEFERRED ; }
Signature · 1 line
2.27.0
PATCH v4 3/3 plugins: Remove defer/simple.c sample plugin
In reply to David SommersethFrom: David Sommerseth <[email protected]...>
The use case for this plug-in is dubious now with the new multi-auth.c plugin available. This new plugin is based on simple.c, but allows far more flexibility for testing.
--- include/openvpn-plugin.h.in | 4 +- sample/sample-plugins/Makefile.plugins | 1 - sample/sample-plugins/README | 6 +- sample/sample-plugins/defer/simple.c | 393 ------------------------- sample/sample-plugins/defer/simple.def | 6 - 5 files changed, 6 insertions(+), 404 deletions(-) delete mode 100644 sample/sample-plugins/defer/simple.c delete mode 100755 sample/sample-plugins/defer/simple.def
include/openvpn-plugin.h.in +2 -2
@@ -584,8 +584,8 @@ OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC(openvpn_plugin_op * * OpenVPN will delete the auth_control_file after it goes out of scope. * - * See plugin/defer/simple.c for an example on using asynchronous - * authentication. + * See sample/sample-plugins/defer/multi-auth.c for an example on using + * asynchronous authentication. */ OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_func_v2) (openvpn_plugin_handle_t handle,
sample/sample-plugins/Makefile.plugins +0 -1
@@ -7,7 +7,6 @@ # Plug-ins to build - listed entries should not carry any extensions # PLUGINS = \ - defer/simple \ defer/multi-auth \ keying-material-exporter-demo/keyingmaterialexporter \ log/log log/log_v3 \
sample/sample-plugins/README +4 -2
@@ -5,8 +5,10 @@ Examples provided: * authentication and logging simple/simple.c -- using the --auth-user-pass-verify callback, verify that the username/password is "foo"/"bar". -defer/simple.c -- using the --auth-user-pass-verify callback, - test deferred authentication. +defer/multi-auth.c + -- using the --auth-user-pass-verify callback, + test deferred authentication. Can be used to test multiple + authentication plugins in the same server config. log/log.c -- Extended variant of simple/simple.c which adds more logging of what is happening inside the plug-in log/log_v3.c -- A variant of log/log.c, which makes use of the
sample/sample-plugins/defer/simple.c deleted +0 -393
393 lines not on this page · raw message
sample/sample-plugins/defer/simple.def deleted +0 -6
@@ -1,6 +0,0 @@ -LIBRARY OpenVPN_PLUGIN_SAMPLE -DESCRIPTION "Sample OpenVPN plug-in module." -EXPORTS - openvpn_plugin_open_v1 @1 - openvpn_plugin_func_v1 @2 - openvpn_plugin_close_v1 @3
Signature · 1 line
2.27.0
Re: [Openvpn-devel] [PATCH v4 2/3] plug-ins: Disallow multiple deferred authentication plug-ins
In reply to David SommersethQuoted 32 lines
David Sommerseth <[email protected]...> hat am 13.03.2022 20:31 geschrieben:
src/openvpn/plugin.c +12
-2@@ -802,7 +802,7 @@ plugin_call_ssl(const struct plugin_list *pl,const char **envp;const int n =plugin_n (pl);bool error = false; -bool deferred = false; +bool deferred_auth_done = false;setenv_del (es,"script_type" ); envp =make_env_array (es, false, &gc);@@ -824,7 +824,34 @@ plugin_call_ssl(const struct plugin_list *pl,break ;case OPENVPN_PLUGIN_FUNC_DEFERRED : - deferred = true; +if ((type ==OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY ) + && deferred_auth_done) + { +/* +* Do not allow deferred auth if a deferred auth has +* already been started. This should allow a single +* deferred auth call to happen, with one or more +* auth calls with an instant authentication result. +* +* The plug-in API is not designed for multiple +* deferred authentications to happen, as the
src/openvpn/plugin.c plugin_call_ssl(const struct plugin_list *pl, · line 847
Quoted 10 lines
src/openvpn/plugin.c +10
-0+* auth_control_file file will be shared across all +* the plug-ins. +* +* Since this is considered a critical configuration +* error, we bail out and exit the OpenVPN process. +*/ + error = true; +msg (M_FATAL , +"Exiting due to multiple authentication plug-ins " + "performing deferred authentication. Only one "
Super nitpick, but there is a second space missing here to be consistent with the other full stop.
src/openvpn/plugin.c plugin_call_ssl(const struct plugin_list *pl, · line 857
Quoted 10 lines
src/openvpn/plugin.c +7
-0+"authentication plug-in doing deferred auth is " +"allowed. Ignoring the result and stopping now, " +"the current authentication result is not to be " + "trusted."); +break ; + } + deferred_auth_done = true;break ;default :
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH v4 1/3] sample-plugin: New plugin for testing multiple auth plugins
In reply to David SommersethHi,
Quoted 5 lines · David Sommerseth
From: David Sommerseth <[email protected]...>
This plugin allows setting username/passwords as well as configure deferred authentication behaviour as part of the runtime initialization.
Quoted 7 lines
With this plug-in it is easier to test various scenarios where multiple authentication plug-ins are active on the server side.
A test documentation was also added to describe various test cases and the expected results.
Signed-off-by David Sommerseth <[email protected]...>
Same as the patch for master.
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v4 2/3] plug-ins: Disallow multiple deferred authentication plug-ins
In reply to David SommersethHi,
Quoted 9 lines · David Sommerseth
From: David Sommerseth <[email protected]...>
The plug-in API in OpenVPN 2.x is not designed for running multiple deferred authentication processes in parallel. The authentication results of such configurations are not to be trusted. For now we bail out when this discovered with an error in the log.
CVE: 2022-0547
Signed-off-by David Sommerseth <[email protected]...>
Same as the patch for master.
src/openvpn/plugin.c plugin_call_ssl(const struct plugin_list *pl, · line 851
Quoted 8 lines
src/openvpn/plugin.c +8
-0+ error = true; +msg (M_FATAL , +"Exiting due to multiple authentication plug-ins " +"performing deferred authentication. Only one " +"authentication plug-in doing deferred auth is " +"allowed. Ignoring the result and stopping now, " +"the current authentication result is not to be " +"trusted." );
Frank reported that we should use double space after the full-stop. Honestly I'd prefer just single-space everywhere as it is more "traditional".
This said, Gert can make the final decision and modify the patch on the fly.
Cheers,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v4 3/3] plugins: Remove defer/simple.c sample plugin
In reply to David SommersethHi,
Quoted 7 lines · David Sommerseth
From: David Sommerseth <[email protected]...>
The use case for this plug-in is dubious now with the new
multi-auth.cplugin available. This new plugin is based onsimple.c, but allows far more flexibility for testing.Signed-off-by David Sommerseth <[email protected]...>
Same as the patch for master.
Signature · 1 line
Antonio Quartulli
[Openvpn-devel] [PATCH applied] Re: sample-plugin: New plugin for testing multiple auth plugins
In reply to David SommersethDiffing the patch against the previous one only circulated on the seclist shows no differences except "mail headers", and I have reviewed and tested that plugin for my "multiple deferred auth" (draft) patch.
So, today only tested that it builds on both branches (it does).
If someone wants to spend a bit more time working on this plugin, I think it could be improved by having the "how much delay?" "direct or deferred?" and "fail or succeed?" behaviour controlled by UV_$prefix_VAR variable settings that can be "--push-peer-info"'ed from the client - so fully automated testing of all combinations without modifying the server config and restarting. But this is an enhancement / feature wish, not a showstopper.
Your patch has been applied to the master and release/2.5 branch.
commit 79a111c7e16d157278495cb5f4c52eab2229b68e (master) commit 08c6d9b016f9e8cf3f917e83bcd96f5a26345989 (release/2.5)
Author: David Sommerseth Date: Sun Mar 13 20:31:52 2022 +0100
sample-plugin: New plugin for testing multiple auth plugins
Signed-off-by: David Sommerseth <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23932.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: plugins: Remove defer/simple.c sample plugin
In reply to David SommersethThis one does not need much brains to review - "does it apply" and "does it break 'make distcheck'" (yes, and no).
The reason why this plugin is deleted is because the new multi-auth plugin does mostly the same thing, "but more" - and it's 90% the same code, so not much to be learned from the older one anymore.
For 2.5 and 2.4 branches, after some discussion on IRC, it makes sense to leave defer/simple alone - it still has "PF" support, which defer/auth-multi does not have (and does not need). So, unlike master, there is something to be learned from having both plugins, and someone might even make use of the "simple" feature set...
Your patch has been applied to the master branch.
commit d816207bc2fe1ee5a04c394b215d50123cb25aad (master)
Author: David Sommerseth Date: Sun Mar 13 20:31:54 2022 +0100
plugins: Remove defer/simple.c sample plugin
Signed-off-by: David Sommerseth <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23933.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: plug-ins: Disallow multiple deferred authentication plug-ins
In reply to David SommersethThis is the same patch that Antonio tested when it was still only discussed on the security@ list (except for the "two spaces" comment fix). Also, fixed a "do" -> "does" in plugin-options.rst.
As discussed before, I still think that "aborting the server process" is excessive and we should just return OPENVPN_PLUGIN_FUNC_ERROR in this case (with a proper log message), but we'll have to agree to disagree on this one. I have a patch to bring proper functionality instead... :-)
I have not tested this particular scenario (Antonio has), just made sure nothing else got broken.
I have not updated Changes.rst in the context of this patch - will do that when preparing 2.5.6 release.
Your patch has been applied to the master and release/2.5 branch.
commit 282ddbac54f8d4923844f69983b38dd2b813a00a (master) commit af3e382649d96ae77cc5e42be8270f355e5cfec5 (release/2.5)
Author: David Sommerseth Date: Sun Mar 13 20:31:53 2022 +0100
plug-ins: Disallow multiple deferred authentication plug-ins
Signed-off-by: David Sommerseth <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23931.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v4 2/3] plug-ins: Disallow multiple deferred authentication plug-ins
In reply to Antonio QuartulliQuoted 6 lines
Antonio Quartulli <[email protected]...> hat am 15.03.2022 16:11 geschrieben:
Frank reported that we should use double space after the full-stop. Honestly I'd prefer just single-space everywhere as it is more "traditional".
Yeah, I also prefer one space but I actually grepped the code and while it is somewhat inconsistent, double-space seems to be winning decisively right now. And we definitely should not use both in the same message ;)
Regards,
--
Frank Lichtenheld