Skip to main content

OpenVPN username, password, and TOTP authentication helper.

Project description

OpenVPN OTP Auth

  • Validates OpenVPN username/password/TOTP from file passed as the first arg when called from OpenVPN server using auth-user-pass-verify.
  • TOTP (aka. 2FA, MFA) uses Google Authenticator (or Authenticator-supporting third-party applications).
  • User management is done from the CLI and stores users credentials and sessions in SQLite DBs.

Installation

Install the PyPI package as an isolated command-line tool with uv:

uv tool install openvpn-otp-auth

Generate the OpenWrt config file at /etc/config/openvpn_otp_auth:

openvpn-otp-auth --install

If the current user cannot write to /etc/config, run the command with the needed privileges. If sudo cannot find the uv-installed command, use the full path shown by uv tool dir --bin.

The helper reads /etc/config/openvpn_otp_auth/openvpn_otp_auth.conf at runtime. Review the generated config and make any necessary changes so the storage locations are correct and the issuer name is set. The default config below shows what --install creates.

For local development, sync the checkout with uv and run the package module or console script from that environment:

uv sync --all-groups
uv run python -m openvpn_otp_auth --help
uv run openvpn-otp-auth --help

The generated config defaults the SQLite databases and TOTP output files under /etc/config/openvpn_otp_auth too.

Default openvpn_otp_auth.conf (Created by running: openvpn-otp-auth --install)

[OpenVPN OTP Auth]
; set to your business name or name of your vpn
issuer = OpenVPN OTP Auth Issuer
; where the totp qr code files are saved to
totp_out_path = /etc/config/openvpn_otp_auth
; number of hours before requiring new totp if nothing else changes
session_duration = 164
user_db_file = /etc/config/openvpn_otp_auth/users.db
session_db_file = /etc/config/openvpn_otp_auth/sessions.db

Example server.ovpn (incomplete)

Use the installed uv tool executable path in the OpenVPN server configuration. Run uv tool dir --bin and replace <uv-tool-bin> in the example below with that directory.

mode server
server xx.yy.zz.0 255.255.255.0
port 1234
proto udp4
dev tun0
topology subnet
verb 3
mute 10
log-append '/var/log/openvpn.log'
status '/var/log/openvpn-status.log'
status-version 2
persist-key
persist-tun
user openvpn
group openvpn
script-security 2
auth-user-pass-verify <uv-tool-bin>/openvpn-otp-auth via-file
auth-gen-token 0 external-auth
reneg-sec 3600
keepalive 10 60
explicit-exit-notify
client-to-client
username-as-common-name
mtu-test
push "persist-key"
push "persist-tun"
push "topology subnet"
push "route xx.yy.bb.0 255.255.255.0"
push "dhcp-option DNS xx.yy.bb.1"
push "dhcp-option DOMAIN-SEARCH vpn"

Example client.ovpn (incomplete)

client
remote vpn.server.address port
proto udp4
dev tun
verb 3
nobind
persist-key
persist-tun
remote-cert-tls server
resolv-retry 5
connect-retry-max 5
explicit-exit-notify
auth-user-pass
auth-nocache
auth-retry interact
static-challenge "Enter Authentication Code (TOTP)" 1

Command Line Options

Option Description
-h, --help Show help message and exit
--install Generate the config file with default values
--adduser <username> Add a new user
--deluser <username> Delete an existing user
--changepass <username> Change the password for an existing user
--changetotp <username> Generate a new TOTP for an existing user
--showtotp <username> Show the TOTP for an existing user
--listusers List all users

Notes

  • Put the username in quotes if getting errors with not enough or too many arguments.
  • When new users are created or TOTP is changed, the TOTP QR Code and URL will display and also be saved to a file called <username>.totp

Authors

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_otp_auth-1.4.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openvpn_otp_auth-1.4.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file openvpn_otp_auth-1.4.1.tar.gz.

File metadata

  • Download URL: openvpn_otp_auth-1.4.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openvpn_otp_auth-1.4.1.tar.gz
Algorithm Hash digest
SHA256 19ef1301e2f638b5e129f951dd0b3ebbaf7c912e325e6cfc47f8124af71cd3aa
MD5 c1dc2f57c5a02b71cd3c32075a383fed
BLAKE2b-256 e96b8c397913c35b72c4d510af26d341f56e8dd46e967fe4ad75fa8fbda928db

See more details on using hashes here.

Provenance

The following attestation bundles were made for openvpn_otp_auth-1.4.1.tar.gz:

Publisher: release.yml on Snuffy2/openvpn_otp_auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openvpn_otp_auth-1.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openvpn_otp_auth-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6d37c846bc44e5a6740f076d5818764a5feda948953893c3c9dd8c7267d7674
MD5 47b44e51b5379a9c27969e8537a1aa12
BLAKE2b-256 d78c76950c5bcbb5e1dcd432e76c9bbf852d194b2a4f0957fbdcb0ef7ebd393f

See more details on using hashes here.

Provenance

The following attestation bundles were made for openvpn_otp_auth-1.4.1-py3-none-any.whl:

Publisher: release.yml on Snuffy2/openvpn_otp_auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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