Freeradius + Google Autheticator + LDAP + Fortigate

ماذا لو كانت المصادقة الثنائية مرغوبة وشائكة على حد سواء ، ولكن لا يوجد مال مقابل الرموز المميزة للأجهزة ، وبشكل عام فإنها تعرض البقاء في حالة مزاجية جيدة.



هذا الحل ليس شيئًا أصليًا للغاية ، ولكنه مزيج من الحلول المختلفة الموجودة على الإنترنت.



لذلك ، معطى



مجال Active Directory .



مستخدمو المجال الذين يستخدمون VPN ، مثل الكثيرين اليوم.



تعمل Fortigate كبوابة VPN .



يحظر حفظ كلمة المرور لعميل VPN بموجب سياسة الأمان. لا يمكن تسمية



سياسة Fortinet بشأن الرموز المميزة الخاصة بها بأقل من المتخلف - هناك بالفعل 10 رموز مجانية ، والباقي بسعر غير كوشير. لم يتم النظر في RSASecureID و Duo وما شابه ، لأنني أريد مصدر مفتوح.



المتطلبات الأساسية: * لا يوجد مضيف مع تثبيت freeradius ، sssd - تم إدخاله في المجال ، يمكن لمستخدمي المجال المصادقة عليه بسهولة.



الحزم الإضافية: shellinabox ، figlet ، freeeradius-ldap ، rebel.tlf الخط من https://github.com/xero/figlet-fonts repository .



في المثال الخاص بي - CentOS 7.8.



منطق العمل هو كما يلي: عند الاتصال بشبكة VPN ، يجب على المستخدم إدخال تسجيل دخول المجال ومرة ​​واحدة بدلاً من كلمة المرور.



إنشاء الخدمات



في /etc/raddb/radiusd.conf ، يتم تغيير المستخدم والمجموعة فقط ، حيث يبدأ freeradius ، حيث يجب أن تكون خدمة radiusd قادرة على قراءة الملفات في جميع الدلائل الفرعية لـ / home / .



user = root
group = root


لتتمكن من استخدام المجموعات في إعدادات Fortigate ، تحتاج إلى تمرير سمة البائع المحددة . للقيام بذلك ، في دليل raddb / policy.d ، قم بإنشاء ملف بالمحتويات التالية:



group_authorization {
    if (&LDAP-Group[*] == "CN=vpn_admins,OU=vpn-groups,DC=domain,DC=local") {
            update reply {
                &Fortinet-Group-Name = "vpn_admins" }
            update control {
                &Auth-Type := PAM
                &Reply-Message := "Welcome Admin"
                }
        }
    else {
        update reply {
        &Reply-Message := "Not authorized for vpn"
            }
        reject
        }
}


بعد تثبيت freeradius-ldap في الدليل raddb / mods-available ، يتم إنشاء ملف ldap .



تحتاج إلى إنشاء ارتباط رمزي إلى الدليل الممكّن لـ raddb / mods .



ln -s /etc/raddb/mods-available/ldap /etc/raddb/mods-enabled/ldap


أحضر محتوياته إلى هذا النموذج:



ldap {
        server = 'domain.local'
        identity = 'CN=freerad_user,OU=users,DC=domain,DC=local'
        password = "SupeSecretP@ssword"
        base_dn = 'dc=domain,dc=local'
        sasl {
        }
        user {
                base_dn = "${..base_dn}"
                filter = "(sAMAccountname=%{%{Stripped-User-Name}:-%{User-Name}})"
                sasl {
                }
                scope = 'sub'
        }
        group {
                base_dn = "${..base_dn}"
                filter = '(objectClass=Group)'
                scope = 'sub'
                name_attribute = cn
                membership_filter = "(|(member=%{control:Ldap-UserDn})(memberUid=%{%{Stripped-User-Name}:-%{User-Name}}))"
                membership_attribute = 'memberOf'
        }
}


في الملفات raddb / sites-enabled / default و raddb / sites-enabled / inner-tunnel في قسم التفويض ، أضفت اسم السياسة التي ستُستخدم - group_authorization. نقطة مهمة - لا يتم تحديد اسم السياسة من خلال اسم الملف في دليل policy.d ، ولكن من خلال التوجيه الموجود داخل الملف قبل الأقواس المتعرجة.

في قسم المصادقة لنفس الملفات ، قم بإلغاء التعليق على بام .



في ملف clients.conf ، اكتب المعلمات التي سيتصل بها Fortigate :



client fortigate {
    ipaddr = 192.168.1.200
    secret = testing123
    require_message_authenticator = no
    nas_type = other
}


تكوين وحدة Pam.d / radiusd :



#%PAM-1.0
auth       sufficient   pam_google_authenticator.so
auth       include      password-auth
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
session    include      password-auth


تتضمن الخيارات الافتراضية لتنفيذ حزمة freeradius مع أداة مصادقة google المستخدم إدخال بيانات الاعتماد بالتنسيق: اسم المستخدم / كلمة المرور + OTP .



بعد تقديم عدد الشتائم التي ستقع على رأسك ، في حالة استخدام حزمة freeradius الافتراضية مع Google Authenticator ، فقد تقرر استخدام تكوين وحدة pam للتحقق من رمز Google Authenticator فقط .



عندما يتصل المستخدم ، يحدث ما يلي:



  • يتحقق Freeradius من وجود المستخدم في المجال وفي مجموعة معينة ، وفي حالة نجاحه ، يتحقق من رمز OTP المميز.


بدا كل شيء جيدًا بما يكفي حتى فكرت ، "كيف يمكنني تسجيل OTP لأكثر من 300 مستخدم؟"



يجب على المستخدم تسجيل الدخول إلى الخادم باستخدام freeradius وتحت حسابه وتشغيل تطبيق Google Authentator ، والذي سينشئ رمز QR للتطبيق للمستخدم. هذا هو المكان الذي يكون فيه shellinabox مفيدًا بالاشتراك مع .bash_profile .



[root@freeradius ~]# yum install -y shellinabox


يوجد ملف تكوين البرنامج الخفي في / etc / sysconfig / shellinabox .

أشير إلى المنفذ 443 هناك ويمكنك تحديد شهادتك.



[root@freeradius ~]#systemctl enable --now shellinaboxd


يحتاج المستخدم فقط إلى اتباع الرابط ، وإدخال اعتمادات المجال وتلقي رمز الاستجابة السريعة للتطبيق.



الخوارزمية هي على النحو التالي:



  • يقوم المستخدم بتسجيل الدخول إلى الجهاز من خلال متصفح.
  • يتم فحص مستخدم المجال. إذا لم يتم اتخاذ أي إجراء.
  • إذا كان المستخدم مستخدم مجال ، يتم التحقق من العضوية في مجموعة المسؤولين.
  • إذا لم يكن مشرفًا ، فإنه يتحقق مما إذا كان قد تم تكوين برنامج Google Autheticator. إذا لم يكن كذلك ، فسيتم إنشاء رمز الاستجابة السريعة وتسجيل خروج المستخدم.
  • إذا لم يكن مسؤولاً وتم تكوين Google Authenticator ، فما عليك سوى تسجيل الخروج.
  • إذا كان المسؤول ، فتحقق مرة أخرى من Google Authenticator. إذا لم يتم تكوينه ، فسيتم إنشاء رمز QR.


كل المنطق يتم باستخدام /etc/skel/.bash_profile .



cat /etc/skel/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
# Make several commands available from user shell

if [[ -z $(id $USER | grep "admins") || -z $(cat /etc/passwd | grep $USER) ]]
  then
    [[ ! -d $HOME/bin ]] && mkdir $HOME/bin
    [[ ! -f $HOME/bin/id ]] && ln -s /usr/bin/id $HOME/bin/id
    [[ ! -f $HOME/bin/google-auth ]] && ln -s /usr/bin/google-authenticator $HOME/bin/google-auth
    [[ ! -f $HOME/bin/grep ]] && ln -s /usr/bin/grep $HOME/bin/grep
    [[ ! -f $HOME/bin/figlet ]] && ln -s /usr/bin/figlet $HOME/bin/figlet
    [[ ! -f $HOME/bin/rebel.tlf ]] && ln -s /usr/share/figlet/rebel.tlf $HOME/bin/rebel.tlf
    [[ ! -f $HOME/bin/sleep ]] && ln -s /usr/bin/sleep $HOME/bin/sleep
  # Set PATH env to <home user directory>/bin
    PATH=$HOME/bin
    export PATH
  else
    PATH=PATH=$PATH:$HOME/.local/bin:$HOME/bin
    export PATH
fi


if [[ -n $(id $USER | grep "domain users") ]]
  then
    if [[ ! -e $HOME/.google_authenticator ]]
      then
        if [[ -n $(id $USER | grep "admins") ]]
          then
            figlet -t -f $HOME/bin/rebel.tlf "Welcome to Company GAuth setup portal"
            sleep 1.5
            echo "Please, run any of these software on your device, where you would like to setup OTP:
Google Autheticator:
AppStore - https://apps.apple.com/us/app/google-authenticator/id388497605
Play Market - https://play.google.com/stor/apps/details?id=com.google.android.apps.authenticator2&hl=en
FreeOTP:
AppStore - https://apps.apple.com/us/app/freeotp-authenticator/id872559395
Play Market - https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp&hl=en

And prepare to scan QR code.

"
            sleep 5
            google-auth -f -t -w 3 -r 3 -R 30 -d -e 1
            echo "Congratulations, now you can use an OTP token from application as a password connecting to VPN."
          else
            figlet -t -f $HOME/bin/rebel.tlf "Welcome to Company GAuth setup portal"
            sleep 1.5
            echo "Please, run any of these software on your device, where you would like to setup OTP:
Google Autheticator:
AppStore - https://apps.apple.com/us/app/google-authenticator/id388497605
Play Market - https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en
FreeOTP:
AppStore - https://apps.apple.com/us/app/freeotp-authenticator/id872559395
Play Market - https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp&hl=en

And prepare to scan QR code.

"
            sleep 5
            google-auth -f -t -w 3 -r 3 -R 30 -d -e 1
            echo "Congratulations, now you can use an OTP token from application as a password to VPN."
            logout
        fi
      else
        echo "You have already setup a Google Authenticator"
        if [[ -z $(id $USER | grep "admins") ]]
          then
          logout
        fi
    fi
  else
    echo "You don't need to set up a Google Authenticator"
fi




إعداد Fortigate:



  • قم بإنشاء خادم Radius



  • نقوم بإنشاء المجموعات الضرورية ، إذا لزم الأمر ، نميز الوصول حسب المجموعات. يجب أن يتطابق اسم المجموعة في Fortigate مع المجموعة التي تم تمريرها في سمة البائع المحددة Fortinet-Group-Name .



  • تحرير بوابات SSL المطلوبة .



  • أضف مجموعات إلى السياسات.







مزايا هذا الحل:

  • هناك إمكانية لمصادقة OTP على حل Fortigate مفتوح المصدر.
  • يستثني المستخدم الذي يدخل كلمة مرور المجال عند الاتصال عبر VPN ، مما يبسط عملية الاتصال إلى حد ما. يعد إدخال كلمة المرور المكونة من 6 أرقام أسهل من إدخال سياسة الأمان. نتيجة لذلك ، ينخفض ​​عدد التذاكر التي تحمل الموضوع: "لا يمكن الاتصال بـ VPN".


ملاحظة: هناك خطط لتشديد هذا الحل على مصادقة ثنائية كاملة مع استجابة التحدي.



تحديث:



كما وعدت ، انتهيت من خيار التحدي والاستجابة.

إذن:

في الملف / etc / raddb / sites-enabled / default ، يبدو قسم التفويض كما يلي:



authorize {
    filter_username
    preprocess
    auth_log
    chap
    mschap
    suffix
    eap {
        ok = return
    }
    files
    -sql
    #-ldap
    expiration
    logintime
    if (!State) {
        if (&User-Password) {
            # If !State and User-Password (PAP), then force LDAP:
            update control {
                Ldap-UserDN := "%{User-Name}"
                Auth-Type := LDAP
            }
        }
        else {
            reject
        }
    }
    else {
        # If State, then proxy request:
        group_authorization
    }
pap
}


يبدو قسم المصادقة الآن كما يلي:



authenticate {
        Auth-Type PAP {
                pap
        }
        Auth-Type CHAP {
                chap
        }
        Auth-Type MS-CHAP {
                mschap
        }
        mschap
        digest
        # Attempt authentication with a direct LDAP bind:
        Auth-Type LDAP {
        ldap
        if (ok) {
            update reply {
                # Create a random State attribute:
                State := "%{randstr:aaaaaaaaaaaaaaaa}"
                Reply-Message := "Please enter OTP"
                }
            # Return Access-Challenge:
            challenge
            }
        }
        pam
        eap
}


الآن يتم التحقق من المستخدم وفقًا للخوارزمية التالية:

  • يقوم المستخدم بإدخال اعتمادات المجال في عميل VPN.
  • يتحقق Freeradius من صحة الحساب وكلمة المرور
  • إذا كانت كلمة المرور صحيحة ، فسيتم إرسال طلب للحصول على رمز مميز.
  • تم التحقق من الرمز المميز.
  • الربح).



All Articles