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
- Current Author: @Snuffy2
- Initial Author: @roman-vynar
- Expanded from: https://github.com/roman-vynar/random-scripts
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19ef1301e2f638b5e129f951dd0b3ebbaf7c912e325e6cfc47f8124af71cd3aa
|
|
| MD5 |
c1dc2f57c5a02b71cd3c32075a383fed
|
|
| BLAKE2b-256 |
e96b8c397913c35b72c4d510af26d341f56e8dd46e967fe4ad75fa8fbda928db
|
Provenance
The following attestation bundles were made for openvpn_otp_auth-1.4.1.tar.gz:
Publisher:
release.yml on Snuffy2/openvpn_otp_auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openvpn_otp_auth-1.4.1.tar.gz -
Subject digest:
19ef1301e2f638b5e129f951dd0b3ebbaf7c912e325e6cfc47f8124af71cd3aa - Sigstore transparency entry: 1529014193
- Sigstore integration time:
-
Permalink:
Snuffy2/openvpn_otp_auth@14ec0d349b930308e4ecf5a74792317202b7051a -
Branch / Tag:
refs/tags/v1.4.1 - Owner: https://github.com/Snuffy2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@14ec0d349b930308e4ecf5a74792317202b7051a -
Trigger Event:
release
-
Statement type:
File details
Details for the file openvpn_otp_auth-1.4.1-py3-none-any.whl.
File metadata
- Download URL: openvpn_otp_auth-1.4.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6d37c846bc44e5a6740f076d5818764a5feda948953893c3c9dd8c7267d7674
|
|
| MD5 |
47b44e51b5379a9c27969e8537a1aa12
|
|
| BLAKE2b-256 |
d78c76950c5bcbb5e1dcd432e76c9bbf852d194b2a4f0957fbdcb0ef7ebd393f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openvpn_otp_auth-1.4.1-py3-none-any.whl -
Subject digest:
c6d37c846bc44e5a6740f076d5818764a5feda948953893c3c9dd8c7267d7674 - Sigstore transparency entry: 1529014371
- Sigstore integration time:
-
Permalink:
Snuffy2/openvpn_otp_auth@14ec0d349b930308e4ecf5a74792317202b7051a -
Branch / Tag:
refs/tags/v1.4.1 - Owner: https://github.com/Snuffy2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@14ec0d349b930308e4ecf5a74792317202b7051a -
Trigger Event:
release
-
Statement type: