Freeradius + Google Authenticator + LDAP + Fortigate

Unsa kaha kung ang duha ka hinungdan nga pag-authenticate parehas nga tilinguhaon ug tusok, apan wala’y kuwarta alang sa mga token sa hardware ug sa kinatibuk-an gitanyag nila nga magpabilin sa maayong kahimtang.

Kini nga solusyon dili usa ka butang nga super orihinal, apan usa ka pagsagol sa lainlaing mga solusyon nga makita sa Internet.

Busa gihatag

Ngalan sa Domain Active Directory.

Ang mga tiggamit sa domain nga nagtrabaho pinaagi sa usa ka VPN, sama sa kadaghanan karon.

Naglihok ingon usa ka gateway sa VPN Pagpalig-on.

Ang pagtipig sa password alang sa kliyente sa VPN gidili sa palisiya sa seguridad.

Politika Fortinet may kalabotan sa imong kaugalingon nga mga token, dili nimo kini matawag nga ubos sa usa ka zhlob - adunay ingon ka daghan sa 10 nga libre nga mga token, ang nahabilin - sa usa ka dili kaayo kosher nga presyo. Wala nako gikonsiderar ang RSASecureID, Duo ug uban pa, tungod kay gusto nako ang open source.

Kinahanglanon: host * nix uban sa natukod freeradius, ssd - nakasulod sa domain, ang mga tiggamit sa domain dali nga makapamatuod niini.

Dugang nga mga pakete: kahon sa shellina, igos, freeradius-ldap, font rebelde.tlf gikan sa repository https://github.com/xero/figlet-fonts.

Sa akong pananglitan - CentOS 7.8.

Ang lohika sa trabaho kinahanglan nga ingon sa mosunod: kung magkonektar sa usa ka VPN, ang user kinahanglan nga mosulod sa usa ka domain login ug OTP imbes sa usa ka password.

Pag-setup sa mga serbisyo

В /etc/raddb/radiusd.conf ang user ug grupo lamang ang nagsugod freeradius, sukad sa serbisyo radiusd kinahanglan nga makabasa sa mga file sa tanan nga mga subdirectory / home /.

user = root
group = root

Aron magamit ang mga grupo sa mga setting Pagpalig-on, kinahanglan ipasa Piho nga Hiyas sa Vendor. Aron mahimo kini, sa direktoryo raddb/policy.d Naghimo ko og file nga adunay mosunod nga sulod:

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
        }
}

Pagkahuman sa pag-instalar freeradius-ldap sa direktoryo raddb/mods-anaa file gihimo ldap.

Kinahanglan nga maghimo usa ka simbolo nga link sa direktoryo raddb/mods-enabled.

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

Gidala nako ang mga sulod niini nga porma:

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'
        }
}

Sa mga file raddb/sites-enabled/default и raddb/sites-enabled/inner-tunnel sa seksyon pagtugot Akong idugang ang ngalan sa polisiya nga gamiton - group_authorization. Usa ka importante nga punto - ang ngalan sa polisiya wala matino sa ngalan sa file sa direktoryo palisiya.d, apan pinaagi sa usa ka direktiba sulod sa file sa wala pa ang curly braces.
Sa seksyon sa pagpamatuod sa sa parehas nga mga file kinahanglan nimo nga i-uncomment ang linya Pam.

Sa file mga kliyente.conf pagreseta sa mga parametro diin kini magkonektar Pagpalig-on:

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

Pag-ayo sa module 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

Default nga mga opsyon sa pagpatuman sa bundle freeradius с google authenticator nagkinahanglan sa user sa pagsulod sa mga kredensyal sa format: username/password+OTP.

Pinaagi sa paghanduraw sa gidaghanon sa mga tunglo nga mahulog sa ulo, sa kaso sa paggamit sa default bundle freeradius с Google Authenticator, nakahukom nga gamiton ang configuration sa module Pam para token ra ang masusi Google Authenticator.

Kung magkonektar ang usa ka tiggamit, mahitabo ang mosunod:

  • Gisusi sa Freeradius kung ang tiggamit naa sa domain ug sa usa ka piho nga grupo ug, kung malampuson, susihon ang OTP token.

Nindot tan-awon ang tanan hangtod sa higayon nga naghunahuna ko "Unsaon nako pagparehistro ang OTP alang sa 300+ nga tiggamit?"

Ang user kinahanglang mag-log in sa server gamit ang freeradius ug gikan sa ilawom sa imong account ug pagdagan ang aplikasyon Google Authenticator, nga makamugna og QR code alang sa aplikasyon alang sa user. Dinhi diin moabut ang tabang. kahon sa shellina kauban ang .bash_profile.

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

Ang daemon configuration file nahimutang sa /etc/sysconfig/shellinabox.
Gipunting nako ang port 443 didto ug mahimo nimong ipiho ang imong sertipiko.

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

Ang user kinahanglan lamang nga mosunod sa link, mosulod sa domain credits ug makadawat og QR code alang sa aplikasyon.

Ang algorithm mao ang mosunud:

  • Ang user mo-log in sa makina pinaagi sa browser.
  • Kung gisusi ba ang tiggamit sa domain. Kung dili, nan wala’y aksyon nga gihimo.
  • Kung ang user usa ka domain user, ang membership sa Administrators group gisusi.
  • Kung dili usa ka admin, gisusi niini kung gi-configure ba ang Google Authenticator. Kung dili, nan usa ka QR code ug logout sa user ang namugna.
  • Kung dili usa ka admin ug Google Authenticator ang na-configure, nan logout lang.
  • Kung admin, susiha pag-usab ang Google Authenticator. Kung dili ma-configure, usa ka QR code ang mabuhat.

Ang tanan nga lohika gihimo gamit /etc/skel/.bash_profile.

iring /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

Pagpalig-on sa setup:

  • Kami nagmugna Radyos-server

    Freeradius + Google Authenticator + LDAP + Fortigate

  • Naghimo kami sa gikinahanglan nga mga grupo, kung gikinahanglan, pag-access sa kontrol sa mga grupo. Ngalan sa grupo sa Pagpalig-on kinahanglan nga magkatugma sa grupo nga gipasa Piho nga Hiyas sa Vendor Fortinet-Group-Ngalan.

    Freeradius + Google Authenticator + LDAP + Fortigate

  • Pag-edit sa gikinahanglan SSL- mga portal.

    Freeradius + Google Authenticator + LDAP + Fortigate

  • Pagdugang mga grupo sa mga palisiya.

    Freeradius + Google Authenticator + LDAP + Fortigate

Ang mga bentaha niini nga solusyon:

  • Posible nga ma-authenticate pinaagi sa OTP sa Pagpalig-on open source nga solusyon.
  • Ang tiggamit dili mosulod sa usa ka password sa domain kung magkonektar pinaagi sa VPN, nga medyo nagpasimple sa proseso sa koneksyon. Ang 6-digit nga password mas sayon ​​nga isulod kay sa gihatag sa security policy. Ingon usa ka sangputanan, ang gidaghanon sa mga tiket nga adunay hilisgutan: "Dili ako makakonekta sa VPN" mikunhod.

PS Nagplano kami nga i-upgrade kini nga solusyon sa usa ka bug-os nga duha ka hinungdan nga panghimatuud nga adunay tubag sa hagit.

update:

Sama sa gisaad, gibag-o nako kini sa kapilian nga tubag sa hagit.
Busa:
Sa file /etc/raddb/sites-enabled/default seksyon pagtugot ingon niini:

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
}

Seksyon sa pagpamatuod sa karon tan-awon sama niini:

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
}

Karon ang pag-verify sa user mahitabo sumala sa mosunod nga algorithm:

  • Ang user mosulod sa domain credits sa VPN client.
  • Gisusi sa Freeradius ang kabalido sa account ug password
  • Kung husto ang password, ipadala ang usa ka hangyo alang sa usa ka token.
  • Ang token gipamatud-an.
  • ganansya).

Source: www.habr.com

Idugang sa usa ka comment