Automate 2FA client response? #182
-
We have a situation where the server-side has implemented 2FA for all client connections. However, some clients open site-to-site tunnels using CLI automation. We have cli tools registered to generate the expected TOTP code, but have been unable to determine a means of scripting the generated TOTP submission during OpenVPN client connection. Is this possible with OpenVPN 2.x or 3.x? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
How do you pass in the 2FA result? As "pseudo password"? Or as proper challenge-response reply? If it's a pseudo-password, for 2.x, you can just generate a file with username+password in it and point the config to it ( For 3.x, I have no idea, @dsommers knows. |
Beta Was this translation helpful? Give feedback.
-
By "script the management interface" are you suggesting using something like |
Beta Was this translation helpful? Give feedback.
-
I would never suggest the use of The OpenVPN management interface (for 2.x) is a fairly simple line-oriented API which can be used by programs like Tunnelblick on Mac or Windows-GUI on Windows to "talk to the openvpn core", get status information, and feed in authentication credentials (and answer challenges). See It might be possible to do something with |
Beta Was this translation helpful? Give feedback.
-
Okay, there's more things to tackle here. First, it is not really a good practice to have site-to-site clients use username/password authentication - there are no "user" using the VPN tunnel, it is a "host" using it. So I would strongly recommend to look into the server side setup and read-up on the If you for some reason cannot avoid the username/password with OTP authentication, OpenVPN 3 Linux provides a Python module to easily write your own "front-end" to provide start the VPN session and provide user credentials. I would recommend you to have a look at the systemd integration; as I suspect you would want to use that approach to start the VPN automatically during boot. The code section dealing with retrieving user credentials can be found in What I'm suggesting is that you create your own version of this Python script using a new filename under
With this in place, all you need to do now:
and it will hopefully work. During testing and development, you can run the
It will respond to SIGINT/CTRL-C to stop the tunnel. |
Beta Was this translation helpful? Give feedback.
-
@dsommers, I understand the "best practice" point of view here. Also appreciate the extra info and recognition that, sometimes, we cannot always reach "best practice" goals in the short-term. This is all great info. Thank you for the suggestions! |
Beta Was this translation helpful? Give feedback.
Okay, there's more things to tackle here.
First, it is not really a good practice to have site-to-site clients use username/password authentication - there are no "user" using the VPN tunnel, it is a "host" using it. So I would strongly recommend to look into the server side setup and read-up on the
--auth-user-pass-optional
option in the man-page. Such "host clients" should only use certificate based authentication. When using said option, the configuration file on these "host clients" can drop theauth-user-pass
option from the config file. Taking this approach will make life a lot easier.If you for some reason cannot avoid the username/password with OTP authentication, OpenVPN 3 Linux…