Skip to main content

An auth verify script for OpenVPN to authenticate via LDAP.

Project description

Python OpenVPN LDAP Auth

PyPI license PyPI status PyPI version shields.io PyPI pyversions main build status

An auth verify script for OpenVPN to authenticate via LDAP. Each VPN login is forwarded to this script and the script in turn attempts a simple bind against the specified LDAP server. When the bind is successful the script returns exit code 0 telling OpenVPN that the credentials are valid.

Although there already is the openvpn-auth-ldap plugin I felt the need to write this auth script. First the source code is more accessible due to it being written in Python. Second it offers more possibilities regarding OpenVPN's static-challenge parameter (see below).

The downsides of using a script instead of a C-plugin are less performance and slightly reduced security. If you are fine with that go ahead.

Quickstart

Install the package via pip:

pip install openvpn-ldap-auth

Then create /etc/openvpn/ldap.yaml:

ldap:
  url: 'ldaps://first.ldap.tld:636/ ldaps://second.ldap.tld:636/'
  bind_dn: 'uid=readonly,dc=example,dc=org'
  password: 'somesecurepassword'
  timeout: 5 # optional
authorization:
  base_dn: 'ou=people,dc=example,dc=org'
  search_filter: '(uid={})' # optional, {} will be replaced with the username
  static_challenge: 'ignore' # optional, other values are prepend, append 

Find out where openvpn-ldap-auth lives:

which openvpn-ldap-auth

Add the following line to you OpenVPN server configuration:

script-security 2
auth-user-pass-verify /path/to/openvpn-ldap-auth via-file

Now you can start your OpenVPN server and try to connect with a client.

Installation

From Source

Download or clone this repository, cd into it and run

pip install poetry
poetry install --no-dev
poetry build
pip install --upgrade --find-links=dist openvpn-ldap-auth

Exchange pip with pip3 if applicable.

Configuration

Static Challenge

If you want users to provide a normal password combined with a one-time-password OpenVPN's static-challenge parameter is what you are looking for.

In the client configuration you need to add a line like

static-challenge "Enter OTP" 1 # use 0 if the OTP shoul not be echoed

When connecting you will now be prompted for your password and your OTP. By setting authorization.static_challenge you can now influence how the OTP is used:

  • ignore (default): Just use the password for binding.
  • prepend: Prepend the OTP to your password and use that for binding.
  • append: Append the OTP to your password and use that for binding.

The last two options are useful if your LDAP server offers internal 2FA validation like oath-ldap.

Using via-env

In the server configuration the following alternative setting is also supported but discouraged:

auth-user-pass-verify /path/to/openvpn-ldap-auth via-env

OpenVPN's manpage about that topic:

If method is set to "via-env", OpenVPN will call script with the environmental variables username and password set to the username/password strings provided by the client. Be aware that this method is insecure on some platforms which make the environment of a process publicly visible to other unprivileged processes.

If you still want to use via-env make sure to set script-security to 3.

Running Tests

First make sure to install Docker with docker-compose and tox. Then run

tox

To run a specific Python-OpenVPN combination run something like

tox -e python38-openvpn25

To see a full list of current environment see the tool.tox section in pyproject.toml.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openvpn-ldap-auth-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

openvpn_ldap_auth-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file openvpn-ldap-auth-0.1.2.tar.gz.

File metadata

  • Download URL: openvpn-ldap-auth-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1041-azure

File hashes

Hashes for openvpn-ldap-auth-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b94df74414d7306bbc4a5db348b2a94c7decd7617d5c3c683366e1c419c9306c
MD5 795784c1728248928dd537c05031c104
BLAKE2b-256 c0e8fbdd139b9674a29080c85ccee26d8ef3f19bdad9bcfd64602e5d8c0c6354

See more details on using hashes here.

Provenance

File details

Details for the file openvpn_ldap_auth-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: openvpn_ldap_auth-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1041-azure

File hashes

Hashes for openvpn_ldap_auth-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9f8b576a2a8709cb10e1f47626bcab0fb612a890ba63ad27a7e40c38106abc
MD5 3baa221d0c6217e1f7cefc809465d9e2
BLAKE2b-256 97e966fcf6950f97f183dcaa78c3ae342872cd5e4cb4e0a335bed3d6bc87565d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page