Linux – OpenVPN Python plugin

linuxopenvpnpython

I have a task about authentication OpenVPN users using database which is located on remote server (not a host with OpenVPN server instance). And we use Python as main language for all our tools.

General solution for this task can be usage of OpenVPN option [b]auth-user-pass-verify[/b] with path to my python script which perform any authentication logic I want. But execution of my python script can take some time, for example remote server is far away or it may do serious calculations for user authentication. I think auth script may take few seconds for execution. As you know, OpenVPN is a single thread application and it uses non blocking I/O for handling several clients. That is why when OpenVPN execute some script it stops all I/O operations and waits for script execution finish. In case we have long-time auth script and a big amount of users who wants to auth we may have performance troubles with OpenVPN network. It would be great if OpenVPN had support deferred auth operations. And it does have this support but only in plugin system. All modern plugins use it, for example openvpn-radius. But I do not want write all logic in c/c++ or have a hassle with making OpenVPN plugin in other language. I think good solution would be write OpenVPN plugin in cm this plugin will use deferred method for auth and call python code separated thread or process. This python code can do things like – use db wrappers, use requests library, etc. And this python code will not stop OpenVPN handling of other clients.

I suppose something like this we can see in OpenVPN Access Server, but I would like to use poor OpenVPN server. And Access Server is not open source.

I can try to write this OpenVPN Python Plugin, but before starting I decided to do this research and ask you: Does OpenVPN have some methods to call auth-script without stopping handling other network I/O? I would like to hear that we have this option and no need to write such plugin, but I really was not able to find something like this.

Best Answer

I have created plugin. If you are interested in it you can check https://github.com/greendev5/openvpn-python

P.S. This plugin is a little bit pointless, because you can use OpenVPN management interface to get notifications about connections and process them without blocking OpenVPN main thread. Maybe someone will think plugin is more easy than listening the management interface.