Allow auth plugins not to be invoked if other auth plugins fail
PATCH 1/1 Allow auth plugins not to be invoked if other auth plugins fail
The current authentication process loops through all plugins, invoking them each in turn, then returning a combined result from each invocation. This causes a challenge if multiple plugins are configured and a later plugin should only be executed if an earlier plugin succeeds - such as sending a Multi-factor authentication challenge only if a previous username/password verification succeeds - as the OpenVPN admin has no way of configuring a dependency between plugins, and plugins have no visibility of the current authentication state, so an MFA challenge would always be sent even on a password challenge failure in the stated scenario.
To overcome this, a system similar to Linux PAM's control flags is being introduced where auth plugins can be marked as one of four states:
allows the plugin to fail without impacting other plugins whilst success of that plugin prevents any other plugins being run (sufficient), allow a plugin to fail whilst still then invoking certain other plugins before failing auth (required), allow a plugin's failure to abort the process immediately (requisite), or allow the plugin to be invoked but the result ignored (optional). For backwards compatibility plugins defined without a scope are treated as having a required scope. Attempting to specify a scope for a plugin that does not return an OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY mask will result in server startup aborting with an error, as will attempting to specify sufficient plugins after other auth plugins. For simplicity, any auth plugin that returns a deferred result but isn't specified as being a required scope will result in a server abort so that any subsequent plugins in the configuration aren't making an assumption about the deferred result.
To maintain backwards compatibility for plugins being invoked, the plugin scope is dropped from the command arguments passed to the plugin initialisation although the plugin binary path continues to be retained.
--- doc/man-sections/plugin-options.rst | 37 +++++++- src/openvpn/plugin.c | 125 ++++++++++++++++++++++++++-- src/openvpn/plugin.h | 10 +++ 3 files changed, 164 insertions(+), 8 deletions(-)
doc/man-sections/plugin-options.rst +35 -2
@@ -13,8 +13,41 @@ plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. plugin module-name plugin module-name "arguments" - The ``module-name`` needs to be the first - argument, indicating the plug-in to load. The second argument is an + Additionally, an auth plugin can use the following syntax: + :: + + plugin [scope] module-name + plugin [scope] module-name "arguments" + + The ``scope`` argument is optional but must be the first argument + if specified, and can be one of the following: + + * :code:`sufficient` - If the plugin returns success, the connection is + authenticated without calling any other plugins. If the plugin fails + then processing will continue on to the next plugin. + + :code:`sufficient` plugins must be listed before any other plugins. + * :code:`required` - The plugin must return success for the connection to + be authenticated. If the plugin fails then plugins will continue to be + invoked until a plugin not defined as :code:`required` is reached, at + which point the connection be be aborted as unauthenticated. + + Any plugin returning a deferred result must be in the :code:`required` + scope, or not have a scope set. + * :code:`requisite` - The plugin must return success for the connection to + be authenticated, but if the plugin fails, the connection is immediately + terminated without calling any other plugins. + * :code:`optional` - The plugin is called, but the result is ignored and + will have no bearing on the authentication state of the connection. + + If :code:`scope` is not specified for an auth plugin then the plugin will + be treated as :code:`required`. + + If :code:`scope` is specified for a non-auth plugin then the configuration + will be treated as invalid. + + The ``module-name`` needs to be the first argument - unless ``scope```, has + been specified - indicating the plug-in to load. The next argument is an optional init string which will be passed directly to the plug-in. If the init consists of multiple arguments it must be enclosed in double-quotes (\"). Multiple plugin modules may be loaded into one
src/openvpn/plugin.c +119 -6
201 lines not on this page · raw message
src/openvpn/plugin.h +10 -0
@@ -42,7 +42,16 @@#define MAX_PLUGINS 16 +enum plugin_scope { +PLUGIN_SCOPE_UNDEFINED , +PLUGIN_SCOPE_REQUIRED , +PLUGIN_SCOPE_REQUISITE , +PLUGIN_SCOPE_SUFFICIENT , +PLUGIN_SCOPE_OPTIONAL +}; +struct plugin_option { +enum plugin_scope plugin_scope;const char *so_pathname;const char **argv; };
@@ -54,6 +63,7 @@ struct plugin_option_list {struct plugin {bool initialized; +enum plugin_scope plugin_scope;const char *so_pathname;unsigned int plugin_type_mask;int requested_initialization_point;
Signature · 1 line
2.39.5 (Apple Git-154)
Am 06.11.24 um 17:59 schrieb Michael Clarke:
Thanks for submitting a patch to OpenVPN. I have gone through the patch and commented on the things that I found when going through it.
Quoted 10 lines
The current authentication process loops through all plugins, invoking them each in turn, then returning a combined result from each invocation. This causes a challenge if multiple plugins are configured and a later plugin should only be executed if an earlier plugin succeeds - such as sending a Multi-factor authentication challenge only if a previous username/password verification succeeds - as the OpenVPN admin has no way of configuring a dependency between plugins, and plugins have no visibility of the current authentication state, so an MFA challenge would always be sent even on a password challenge failure in the stated scenario.
This seems to only if you are using a different MFA approach than the current/recommended one, e.g. demonstrated by the demo script totp.py in the OpenVPN repository.
Quoted 10 lines
To overcome this, a system similar to Linux PAM's control flags is being introduced where auth plugins can be marked as one of four states:
allows the plugin to fail without impacting other plugins whilst success of that plugin prevents any other plugins being run (sufficient), allow a plugin to fail whilst still then invoking certain other plugins before failing auth (required), allow a plugin's failure to abort the process immediately (requisite), or allow the plugin to be invoked but the result ignored (optional). For backwards compatibility plugins defined without a scope are treated as having arequiredscope.
Quoted 8 lines
Attempting to specify a scope for a plugin that does not return an
OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFYmask will result in server startup aborting with an error, as will attempting to specifysufficientplugins after other auth plugins. For simplicity, any auth plugin that returns a deferred result but isn't specified as being arequiredscope will result in a server abort so that any subsequent plugins in the configuration aren't making an assumption about the deferred result.
To better understand what this patch is actually addressing, it would be nice to describe the scenario that you are addressing with this patch as that me do better understand what real-world scenario is actually addressed by this patch as the this is a bit abstract.
Quoted 16 lines
To maintain backwards compatibility for plugins being invoked, the plugin scope is dropped from the command arguments passed to the plugin initialisation although the plugin binary path continues to be retained.
--- doc/man-sections/plugin-options.rst | 37 +++++++- src/openvpn/plugin.c | 125 ++++++++++++++++++++++++++-- src/openvpn/plugin.h | 10 +++ 3 files changed, 164 insertions(+), 8 deletions(-)doc/man-sections/plugin-options.rst +0
-0@@ -13,8 +13,41 @@ plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. plugin module-name
doc/man-sections/plugin-options.rst plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. · line 21
Quoted 10 lines
doc/man-sections/plugin-options.rst +6
-2plugin module-name "arguments" - The ``module-name`` needs to be the first - argument, indicating the plug-in to load. The second argument is an + Additionally, an auth plugin can use the following syntax: + :: + + plugin [scope] module-name + plugin [scope] module-name "arguments" +
plugin foo foo
could be both as
plugin module-name "arguments"
and as
plugin [scope] module-name
according to the man page. I do not like the approach of using a whitelist of argument to determine which of the two is being used as a typo for example or using an old version can then change the parsing in unexpected way. I would rather see something that has not this ambiguity like introducing a new keyword like plugin-something.
doc/man-sections/plugin-options.rst plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. · line 27
Quoted 6 lines
doc/man-sections/plugin-options.rst +6
-0+ The ``scope`` argument is optional but must be the first argument + if specified, and can be one of the following: + + * :code:`sufficient` - If the plugin returns success, the connection is + authenticated without calling any other plugins. If the plugin fails + then processing will continue on to the next plugin.
What happens with other auth methods like management and auth scripts? That should be made clear without having to read the source code.
doc/man-sections/plugin-options.rst plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. · line 41
Quoted 13 lines
doc/man-sections/plugin-options.rst +13
-0+ :code:`sufficient` plugins must be listed before any other plugins. + * :code:`required` - The plugin must return success for the connection to + be authenticated. If the plugin fails then plugins will continue to be + invoked until a plugin not defined as :code:`required` is reached, at + which point the connection be be aborted as unauthenticated. + + Any plugin returning a deferred result must be in the :code:`required` + scope, or not have a scope set. + * :code:`requisite` - The plugin must return success for the connection to + be authenticated, but if the plugin fails, the connection is immediately + terminated without calling any other plugins. + * :code:`optional` - The plugin is called, but the result is ignored and + will have no bearing on the authentication state of the connection.
What happens if all plugins are optinal. And what is the point of a plugin being called but ignored? Some idea what to use this for would be good.
doc/man-sections/plugin-options.rst plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. · line 44
Quoted 3 lines
doc/man-sections/plugin-options.rst +3
-0+ + If :code:`scope` is not specified for an auth plugin then the plugin will + be treated as :code:`required`.
do we define what an auth plugin vs a non-plugin is anywhere?
doc/man-sections/plugin-options.rst plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. · line 48
Quoted 3 lines
doc/man-sections/plugin-options.rst +3
-0+ If :code:`scope` is specified for a non-auth plugin then the configuration + will be treated as invalid. +
And then what will happen?
Quoted 61 lines
doc/man-sections/plugin-options.rst +2
-0+ The ``module-name`` needs to be the first argument - unless ``scope```, has + been specified - indicating the plug-in to load. The next argument is an optional init string which will be passed directly to the plug-in. If the init consists of multiple arguments it must be enclosed in double-quotes (\"). Multiple plugin modules may be loaded into onesrc/openvpn/plugin.c +39
-1@@ -172,8 +172,36 @@ plugin_option_list_add(struct plugin_option_list *list, char **p, {struct plugin_option *o = &list->plugins[list->n++]; o->argv =make_extended_arg_array (p, false, gc); -if (o->argv[0 ]) +if (o->argv[0 ] && o->argv[1 ]) { +if (!strcmp (o->argv[0 ],"required" )) + { + o->plugin_scope =PLUGIN_SCOPE_REQUIRED ; + } +else if (!strcmp (o->argv[0 ],"requisite" )) + { + o->plugin_scope =PLUGIN_SCOPE_REQUISITE ; + } +else if (!strcmp (o->argv[0 ],"sufficient" )) + { + o->plugin_scope =PLUGIN_SCOPE_SUFFICIENT ; + } +else if (!strcmp (o->argv[0 ],"optional" )) + { + o->plugin_scope =PLUGIN_SCOPE_OPTIONAL ; + } +else + { + o->plugin_scope =PLUGIN_SCOPE_UNDEFINED ; + o->so_pathname = o->argv[0 ]; +return true; + } + o->argv =make_extended_arg_array ((char **) &o->argv[1 ], false, gc); + o->so_pathname = o->argv[0 ]; + } +else if (o->argv[0 ]) + { + o->plugin_scope =PLUGIN_SCOPE_UNDEFINED ; o->so_pathname = o->argv[0 ]; }return true;@@ -184,6 +212,28 @@ plugin_option_list_add(struct plugin_option_list *list, char **p, } } +static char * +plugin_scope_name (enum plugin_scope scope) +{ +switch (scope) + { +case PLUGIN_SCOPE_REQUIRED : +return "required" ; + +case PLUGIN_SCOPE_REQUISITE : +return "requisite" ;
src/openvpn/plugin.c plugin_option_list_add(struct plugin_option_list *list, char **p, · line 234
Quoted 10 lines
src/openvpn/plugin.c +10
-0+ +case PLUGIN_SCOPE_SUFFICIENT : +return "sufficient" ; + +case PLUGIN_SCOPE_OPTIONAL : +return "optional" ; + +default : +return "" ; + }
The PLUGIN_SCOPE_UNDEFINED is missing from this function and default should be something other than an empty string I think
src/openvpn/plugin.c plugin_common_open(struct plugin_common *pc, · line 802
Quoted 1 line
src/openvpn/plugin.c +1
-0+bool non_scope_sufficient_auth_plugin_seen = false;
I have trouble parsing this variable name and meaning. A plugin without scope is required from the earlier manpage changes. The combination of no scope but a sufficent scope makes no sense to me.
Quoted 5 lines
src/openvpn/plugin.c +0
-0for (i =0 ; i < pc->n; ++i) { plugin_open_item(&pc->plugins[i],@@ -746,6 +807,19 @@ plugin_common_open(struct plugin_common *pc, pr ? &pr->list[i] : NULL,
src/openvpn/plugin.c plugin_common_open(struct plugin_common *pc, · line 817
Quoted 10 lines
src/openvpn/plugin.c +8
-0envp, init_point); +if (pc->plugins[i].plugin_type_mask !=plugin_supported_types () && (pc->plugins[i].plugin_type_mask &OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY )) ==OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY )) + { +if (non_scope_sufficient_auth_plugin_seen && pc->plugins[i].plugin_scope ==PLUGIN_SCOPE_SUFFICIENT ) + { +msg (M_FATAL , +"PLUGIN_INIT: auth plugin %s is defined as 'sufficient' but has been specified after other auth plugins not specified as 'sufficient'" , + pc->plugins[i].so_pathname); + }
Is this restriction documented in the man page? Also why has this decision been made. I don't see any obvious reason for it.
Arne
Hi,
Thanks for the feedback.
I should have made it clear that this was a request for comment about the concept.
Whilst the functionality works for the setup I've tested with, I've not reviewed cases
of admin or auth-user-pass-verify scripts so there are potential gaps I'll need to
go back and fill.
For background, the options are based on Linux PAM:
https://linux.die.net/man/5/pam.conf.
I don't use all the PAM configuration in any of my set-ups, but I know of people who
cover use-cases through the likes of Optional, so didn't want to exclude it unless
there's a strong consensus that it wouldn't provide value in the OpenVPN case.
Quoted 4 lines
This seems to only if you are using a different MFA approach than the current/recommended one, e.g. demonstrated by the demo script
totp.pyin the OpenVPN repository.
This is primarily aimed at out-of-band Push OTP rather than a user entering a TOTP
into their VPN client.
Quoted 6 lines
To better understand what this patch is actually addressing, it would be nice to describe the scenario that you are addressing with this patch as that me do better understand what real-world scenario is actually addressed by this patch as the this is a bit abstract.
The use case I'm working with is LDAP authentication followed by a Duo Push, with the requirement being not to perform a Duo Push unless LDAP succeeds. Both of these are initiated from server-side plugins, which I don't think the
TOTP script handles, but I'm happy to be told there's an easy way of doing this!
Quoted 8 lines
plugin foo foo
could be both as
plugin module-name "arguments"
and as
Quoted 11 lines
plugin [scope] module-name
according to the man page. I do not like the approach of using a whitelist of argument to determine which of the two is being used as a typo for example or using an old version can then change the parsing in unexpected way. I would rather see something that has not this ambiguity like introducing a new keyword like plugin-something.
There would only be an incompatibility between old and new versions if you had a binary named optional, required, requisite, or suffiicient on your
path, and at that point your OpenVPN is likely to fail on the Plugin Init phase
as the binary won't have the expected init methods in it, otherwise you'd get
an error about not finding the binary for plugin required. Similarly having a
typo in the configuration would result in OpenVPN failing to start with a message about being unable to find the target binary for the plugin reequired.
I did consider adding a new scoped-plugin item, but wanted to avoid the ambiguity of someone mixing 'auth' plugins in plugin and scoped-plugin, or using plugins that don't support scope (i.e. non-auth plugins) in scoped-plugin. Do you have any suggestions about how you'd differentiate existing plugins and the new plugin type to prevent ambiguity from mix-and-matching old-and-new configuration, e.g. adding two auth-pam entries,
one under an existing plugin line and one under the newly named scoped-plugin line?
Quoted 3 lines
What happens with other auth methods like management and auth scripts? That should be made clear without having to read the source code.
I've not looked at these yet. I'll come back to you on the actual implementation of
these.
Quoted 6 lines
What happens if all plugins are optinal. And what is the point of a plugin being called but ignored? Some idea what to use this for would be good.
Good point. Just now OpenVPN terminates if verify-client-cert is none and then
doesn't have any auth-user-pass-verify scripts or plugins, but this change doesn't
prevent someone setting only sufficient plugins that all fail, or only setting optional
plugins. I can harden this by performing a configuration check to ensure a non-optional
plugin is set after loading all plugins and to ensure there's no fall-through for all
'sufficient'
plugins failing.
I don't use Optional in any of the PAM configurations I have, but know the common
use-case is for ensuring keyrings/keychains are unlocked but not failing if they're
unavailable.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + If :code:`scope` is not specified for an auth plugin then the pluginwill
Quoted 1 line
+ be treated as :code:
required.do we define what an auth plugin vs a non-plugin is anywhere?
No. This is a terminology I've gone with rather than an OpenVPN nomenclature.
It's any plugin that returns the OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY mask but didn't have a meaningful name for it that didn't refer to a constant in the
code. I'm happy to take any suggestions on how to better define that category
of plugins.
Quoted 8 lines
Quoted 2 lines
+ If :code:
scopeis specified for a non-auth plugin then theconfiguration
doc/man-sections/plugin-options.rst plug-ins must be prebuilt and adhere to the OpenVPN Plug-In API. · line 48
Quoted 2 lines
doc/man-sections/plugin-options.rst +2
-0+ will be treated as invalid. +And then what will happen?
OpenVPN will exit with an error about the configuration being invalid. Are you wanting
this to be explicitly called-out?
Quoted 14 lines
Quoted 14 lines
src/openvpn/plugin.c +14
-0+static char * +plugin_scope_name (enum plugin_scope scope) +{ +switch (scope) + { +case PLUGIN_SCOPE_REQUIRED : +return "required" ; + +case PLUGIN_SCOPE_REQUISITE : +return "requisite" ; + +case PLUGIN_SCOPE_SUFFICIENT : +return "sufficient" ; +
Quoted 10 lines
src/openvpn/plugin.c plugin_option_list_add(struct plugin_option_list *list, char **p, · line 234
Quoted 6 lines
src/openvpn/plugin.c +6
-0+case PLUGIN_SCOPE_OPTIONAL : +return "optional" ; + +default : +return "" ; + }The
PLUGIN_SCOPE_UNDEFINEDis missing from this function and default should be something other than an empty string I think
This was intentional - the only way you can have UNDEFINED is not to have defined a scope so when printing it back out anywhere I wanted to show the same value as what the user had originally entered.
Quoted 9 lines
Quoted 4 lines
+ bool
non_scope_sufficient_auth_plugin_seen= false;I have trouble parsing this variable name and meaning. A plugin without scope is required from the earlier manpage changes. The combination of no scope but a sufficent scope makes no sense to me.
Agreed the naming isn't great here. This is enforcing the section from the manpage
about ":code:sufficient plugins must be listed before any other plugins.", so checking
if we've seen something that's not a sufficient plugin as we iterate over plugins.
However, re-reading the PAM config man page the 'sufficient' should be able to be
placed anywhere but have the result ignore if a previous 'required' or 'requisite'
plugin has failed. I'll do some refactoring to make this work as-per what PAM is doing
which will ultimately remove the block of code in this area.
Quoted 11 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ msg(M_FATAL, + "PLUGIN_INIT: auth plugin %s is defined as'sufficient' but has been specified after other auth plugins not specified as 'sufficient'",
Review
Quoted 2 lines
(quoted diff) +2
-0+ pc->plugins[i].so_pathname); + }Is this restriction documented in the man page? Also why has this decision been made. I don't see any obvious reason for it.
Yes: " :code:sufficient plugins must be listed before any other plugins.". This was to
prevent ambiguity with a requisite or required plugin failing and having a sufficient
plugin listed afterwards. As mentioned above I've misunderstood what PAM does in
this area, so will update my implementation to be less restrictive.
Thanks,
Michael
Quoted 29 lines · Michael Clarke
The current authentication process loops through all plugins, invoking them each in turn, then returning a combined result from each invocation. This causes a challenge if multiple plugins are configured and a later plugin should only be executed if an earlier plugin succeeds - such as sending a Multi-factor authentication challenge only if a previous username/password verification succeeds - as the OpenVPN admin has no way of configuring a dependency between plugins, and plugins have no visibility of the current authentication state, so an MFA challenge would always be sent even on a password challenge failure in the stated scenario.
To overcome this, a system similar to Linux PAM's control flags is being introduced where auth plugins can be marked as one of four states:
allows the plugin to fail without impacting other plugins whilst success of that plugin prevents any other plugins being run (sufficient), allow a plugin to fail whilst still then invoking certain other plugins before failing auth (required), allow a plugin's failure to abort the process immediately (requisite), or allow the plugin to be invoked but the result ignored (optional). For backwards compatibility plugins defined without a scope are treated as having arequiredscope. Attempting to specify a scope for a plugin that does not return anOPENVPN_PLUGIN_AUTH_USER_PASS_VERIFYmask will result in server startup aborting with an error, as will attempting to specifysufficientplugins after other auth plugins. For simplicity, any auth plugin that returns a deferred result but isn't specified as being arequiredscope will result in a server abort so that any subsequent plugins in the configuration aren't making an assumption about the deferred result.
Quoted 3 lines
To maintain backwards compatibility for plugins being invoked, the plugin scope is dropped from the command arguments passed to the plugin initialisation although the plugin binary path continues to be retained.
This RFC makes a lot of sense on a conceptual level. But I'm not sure it's advisable to change the "plugin" option too much in the core of OpenVPN. As Arne points out, backwards compatibility and ambiguities can be some nasty traps. And there are plenty of relations between plug-ins and the script hooks in the code base - which would also need to be handled.
What I would suggest is actually to instead add a new plug-in, using the v3 API. This new plug-in can take a configuration file and load all the auth-plugins and treat each of them according to the requirements. This plug-in would then give the final result back to OpenVPN.
The advantage with this approach is that it would not require any changes to OpenVPN itself and it could be used on older OpenVPN versions as well - since the authentication steps is handled in the plug-in.
And while I'm writing this ... I do wonder why the auth-pam.so [1] plug-in doesn't fit. It should be possible to create your own PAM "profile" in /etc/pam.d, for example /etc/pam.d/openvpn-duo and then just use this in the OpenVPN config file:
plugin openvpn-auth-pam.so openvpn-duo
The openvpn-duo "profile" could have the needed authentication steps for username/password and Duo, within the flexibility the PAM stack provides.
[1] <https://github.com/OpenVPN/openvpn/tree/master/src/plugins/auth-pam>
In regards to re-using the username/password authentication. OpenVPN can cache this information already. And it should be possible to trigger an re-authentication with just the dynamic challenge, but it might be auth-pam does not properly support that.
So I'm generally thinking that we should aim to keep the authentication itself pretty simple in OpenVPN itself and rather push the more demanding authentication requirements into separate modules/plug-ins which can solve that task better. This gives a better flexibility while keeping the OpenVPN code itself simpler. After all, OpenVPN itself only needs to know if an authentication failed or succeeded - in which order or which authentication requirements were fulfilled is not important for OpenVPN. And that's what the current plug-in API already gives you.
If the auth-pam plug-in is not sufficient, I'd like to see some exploration if that could be improved - or by adding a new auth-plugin which OpenVPN can use, which solves this challenge better.
That's my 2cents.
--
kind regards,
David Sommerseth
OpenVPN Inc