Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port google OTP code from kylemanna/openvpn
- Loading branch information
1 parent
895a697
commit 04e1276
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Generate OpenVPN users via google authenticator | ||
# | ||
|
||
if [ -z $1 ]; then | ||
echo "Usage: ovpn_otp_user USERNAME" | ||
exit 1 | ||
fi | ||
|
||
# Server name is in the form "udp://vpn.example.com:1194" | ||
if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then | ||
OVPN_PROTO=${BASH_REMATCH[2]}; | ||
OVPN_CN=${BASH_REMATCH[3]}; | ||
OVPN_PORT=${BASH_REMATCH[5]}; | ||
else | ||
echo "Need to pass in OVPN_SERVER_URL in 'proto://fqdn:port' format" | ||
exit 1 | ||
fi | ||
|
||
# Ensure the otp folder is present | ||
[ -d /etc/openvpn/otp ] || mkdir -p /etc/openvpn/otp | ||
|
||
# Binary is present in image, save an $user.google_authenticator file in /etc/openvpn/otp | ||
if [ "$2" == "interactive" ]; then | ||
# Authenticator will ask for other parameters. User can choose rate limit, token reuse policy and time window policy | ||
# Always use time base OTP otherwise storage for counters must be configured somewhere in volume | ||
google-authenticator --time-based --force -l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator | ||
else | ||
google-authenticator --time-based --disallow-reuse --force --rate-limit=3 --rate-time=30 --window-size=3 \ | ||
-l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Uses google authenticator library as PAM module using a single folder for all users tokens | ||
# User root is required to stick with an hardcoded user when trying to determine user id and allow unexisting system users | ||
# See https://github.com/google/google-authenticator/tree/master/libpam#secretpathtosecretfile--usersome-user | ||
auth required pam_google_authenticator.so secret=${OVPN_OTP}/${USER}.google_authenticator user=root | ||
|
||
# Accept any user since we're dealing with virtual users there's no need to have a system account (pam_unix.so) | ||
account sufficient pam_permit.so |