I am trying to execute auth flow with openvpn auth-pass-verify options.
sample config from openvpn.conf:
auth-user-pass-verify /etc/openvpn/auth2.sh via-file
verify-client-cert require
script-security 3
And the scripts I am trying to use
#!/usr/bin/bash
PATH=$PATH:/usr/local/bin
set -e
env
auth_usr=$(head -1 $1)
auth_passwd=$(tail -1 $1)
if [ $common_name = $auth_usr ]; then
result=curl -v -X GET -H "Content-type: application/json" -d '{"username"="${auth_usr}"&"password"="${auth_passwd}"}' http://openvpn-ui:8080/auth
echo $result
if [ $result = "Authorized" ]; then
echo "Authorization succeeded"
exit 0
else
echo "Authorization failed"
exit 1
fi
else
echo "Authorization failed"
exit 1
fi
py:
#!/usr/bin/python3
import sys
import sqlite3
DB_FILE = '/etc/openvpn/db/openvpn-ui.db'
def main():
with open(sys.argv[1], 'r') as tmpfile:
username = tmpfile.readline().rstrip('n')
password = tmpfile.readline().rstrip('n')
creds = get_password(username)
if not creds:
print(f'>> user {username} not defined.')
sys.exit(1)
if password != creds[0][1]:
print(f'>> Incorrect password provided by user {username}.')
sys.exit(1)
sys.exit(0)
def get_password(username):
db = sqlite3.connect(DB_FILE)
cursor = db.cursor()
cursor.execute('''select username, password from user where username=?''', (username, ))
creds = cursor.fetchall()
db.close()
return creds
if __name__ == '__main__':
main()
In each one I have the same error:
WARNING: Failed running command (--auth-user-pass-verify): could not execute external program
Permissions on script -rwxr-xr-x 1 root root 493 May 16 20:52 auth2.sh
I have tried changing permissions already. openvpn running from user nobody.
Any suggestions are welcome.