Git Product home page Git Product logo

Comments (3)

Sispheor avatar Sispheor commented on September 3, 2024 2

Thank you very much @kirik . We were facing the exact same issue.
And we replaced as well the module by a bash script.

Here is our version of the script that perform the check against 2 different DN (we have real user and service account)

#!/bin/bash
ourname=ldap_auth.sh
facility=auth

output=$(mktemp)
error=$(mktemp)

log_this () {
  echo "$1"
}

log_this "Connection from username: $username at $(date)"

exit_if_ok() {
  if [ $status -eq 0 ]; then
    numentries=$(awk '/numEntries:/{ne = $3} END{print ne + 0}' "$output")
    if [ $numentries -eq 1 ]; then
      log_this "User ${username} authenticated successfully"
      echo "1" > "${auth_control_file}"
      exit 0
    fi
  fi

}

# child process - try simple shell backgrounding
(
  # check email
  ldapsearch -x -H ldaps://ldap.domain:636 \
  -D "uid=${username},ou=People,o=domain.com" \
  -w "${password}" \
  -b "ou=People,o=domain.com" \
  "uid=${username}" 1>"${output}" 2>"${error}"
  status=$?
  exit_if_ok

  # # check service account
  ldapsearch -x -H ldaps://ldap.domaint:636 \
    -D "cn=${username},ou=Applications,o=domain.com" \
    -w "${password}" \
    -b "ou=Applications,o=domain.com" \
    "cn=${username}" 1>"${output}" 2>"${error}"
  status=$?
  exit_if_ok

  log_this "User ${username} NOT authenticated"
  echo "0" > "${auth_control_file}"
  exit 1

) &

# tell openvpn that auth will be deferred
exit 2

from openvpn-auth-ldap.

kirik avatar kirik commented on September 3, 2024 1

Had this weird packet losses. I found a workaround (actually solution) using auth-user-pass-verify script which support deferred auth since OpenVPN 2.5+.

Some source links:
https://community.openvpn.net/openvpn/ticket/222
https://github.com/waldner/openvpn-ldap

OpenVPN server config file:

...
script-security 3
auth-user-pass-verify /etc/openvpn/ldap_auth.sh via-env
...

Example of ldap_auth.sh script (use your <BINDDN> and <BASEDN>). ldapsearch should be installed where script will run.

#!/bin/bash

ourname=ldap_auth.sh
facility=auth

output=$(mktemp)
error=$(mktemp)

# child process - try simple shell backgrounding
(
  ldapsearch -h auth.local -D "cn=${username},<BASEDN>" -b "<BINDDN>" -s base "objectClass=*" 1.1 -w "${password}"  1>"${output}" 2>"${error}"

  # save exist status here, otherwise the following assignment resets $?
  status=$?

  if [ $status -ne 0 ]; then
    logger -p "${facility}.err" -t "${ourname}" "There was an error authenticating user ${username} against AD."
    logger -p "${facility}.err" -t "${ourname}" "The error was: $(tr '\n' ' ' < "${error}" )"  # turn multiline into single line
    echo "0" > "${auth_control_file}"
    exit 1
  fi

  # look for the "numEntries" line in the output of ldapsearch
  numentries=$(awk '/numEntries:/{ne = $3} END{print ne + 0}' "$output")

  if [ $numentries -eq 1 ]; then
    logger -p "${facility}.info" -t "{$ourname}" "User ${username} authenticated successfully"
    echo "1" > "${auth_control_file}"
    exit 0
  else
    logger -p "${facility}.err" -t "${ourname}" "User ${username} NOT authenticated (user not in group?)"
    echo "0" > "${auth_control_file}"
    exit 1
  fi
) &

# tell openvpn that auth will be deferred
exit 2

After using this you should see deferred auth messages in OpenVPN server log: Username/Password authentication deferred for username 'username'

Hope this will help

from openvpn-auth-ldap.

farvour avatar farvour commented on September 3, 2024

I opened a PR for this issue #67 which I'm hoping helps solve this issue.

from openvpn-auth-ldap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.