Freeradius + Google Authenticator + LDAP + Fortigate

Ahoana raha toa ka tiana sy masiaka ny fanamarinana roa, saingy tsy misy vola ho an'ny mari-pamantarana fitaovana ary amin'ny ankapobeny dia manolotra ny hijanona ao anaty toe-tsaina tsara izy ireo.

Ity vahaolana ity dia tsy zavatra tena tany am-boalohany, fa fifangaroana vahaolana samihafa hita ao amin'ny Internet.

Ka nomena

Домен Active Directory.

Ireo mpampiasa sehatra miasa amin'ny VPN, toy ny maro ankehitriny.

Miasa ho vavahady VPN Fortigate.

Ny fitahirizana ny tenimiafina ho an'ny mpanjifa VPN dia voararan'ny politika fiarovana.

Politika Fortinet mifandraika amin'ny mari-pamantaranao manokana, tsy azonao atao ny miantso azy io ho latsaky ny zhlob - misy marika maimaim-poana 10, ny ambiny - amin'ny vidiny tena tsy kosher. Tsy nieritreritra ny RSASecureID, Duo sy ny toy izany aho, satria mila loharano misokatra.

Fepetra takiana: miaramila * nix miaraka amin'ny naorina freeradius, ssd - niditra tao amin'ny sehatra, ireo mpampiasa sehatra dia afaka manamarina mora foana azy.

Fonosana fanampiny: boaty shellina, aviavy, freeradius-ldap, endritsoratra rebel.tlf avy amin'ny repository https://github.com/xero/figlet-fonts.

Amin'ny ohatra ahy - CentOS 7.8.

Ny lojikan'ny asa dia tokony ho toy izao manaraka izao: rehefa mifandray amin'ny VPN, ny mpampiasa dia tsy maintsy miditra amin'ny sehatra fidirana sy OTP fa tsy tenimiafina.

Fametrahana serivisy

В /etc/raddb/radiusd.conf ny mpampiasa sy ny vondrona ihany no manomboka freeradius, hatramin'ny fanompoana radiusd tokony ho afaka mamaky rakitra ao amin'ny subdirectories rehetra / Home /.

user = root
group = root

Mba hahafahana mampiasa vondrona amin'ny toe-javatra Fortigate, tsy maintsy ampitaina Toetra manokana amin'ny mpivarotra. Mba hanaovana izany, ao amin'ny lahatahiry raddb/policy.d Mamorona rakitra miaraka amin'ireto atiny manaraka ireto aho:

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

Aorian'ny fametrahana freeradius-ldap ao amin'ny lahatahiry raddb/mods-available noforonina ny rakitra LDAP.

Mila mamorona rohy an'ohatra mankany amin'ny lahatahiry raddb/mods-enabled.

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

Entiko amin'ity endrika ity ny ao anatiny:

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

Amin'ny rakitra raddb/sites-enabled/default и raddb/sites-enabled/inner-tunnel amin'ny fizarana manome lalana Ampiako ny anaran'ny politika ampiasaina - group_authorization. Hevi-dehibe iray - ny anaran'ny politika dia tsy voafaritra amin'ny anaran'ny rakitra ao amin'ny lahatahiry politika.d, fa amin'ny alalan'ny toromarika ao anatin'ny rakitra mialohan'ny braces olioly.
Ao amin'ny fizarana manamarina ao anatin'ireo rakitra ireo ihany no ilainao hanesorana ny tsipika Pam.

Ao anaty rakitra clients.conf mametra ny masontsivana izay hifandraisany Fortigate:

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

Fanamboarana 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

Safidy fampiharana fehezam-boninkazo mahazatra freeradius с google authenticator mitaky ny mpampiasa hampiditra fahazoan-dàlana amin'ny endrika: solonanarana / tenimiafina+OTP.

Amin'ny alalan'ny sary an-tsaina ny isan'ny ozona izay hianjera eo amin'ny lohany, amin'ny raharaha ny fampiasana ny default amboara freeradius с Google Authenticator, dia nanapa-kevitra ny hampiasa ny fanamafisana ny module Pam ka ny token ihany no azo jerena Google Authenticator.

Rehefa mifandray ny mpampiasa dia mitranga izao manaraka izao:

  • Ny Freeradius dia manamarina raha ao amin'ny sehatra sy vondrona iray ny mpampiasa ary, raha mahomby, dia manamarina ny mari-pamantarana OTP.

Toa tsara daholo ny zava-drehetra mandra-pahatongan'ny fotoana nieritreritra aho hoe "Ahoana no ahafahako misoratra anarana OTP ho an'ny mpampiasa 300+?"

Ny mpampiasa dia tsy maintsy miditra amin'ny server miaraka amin'ny freeradius ary avy eo ambanin'ny kaontinao ary tanteraho ny fampiharana Google Authenticator, izay hamorona kaody QR ho an'ny fampiharana ho an'ny mpampiasa. Eto no misy ny fanampiana. boaty shellina miaraka amin'ny .bash_profile.

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

Ny rakitra fanamafisana daemon dia hita ao amin'ny /etc/sysconfig/shellinabox.
Manondro port 443 aho ao ary azonao atao ny mamaritra ny taratasy fanamarinanao.

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

Ny mpampiasa dia mila manaraka ny rohy ihany, miditra ny crédit domaine ary mahazo kaody QR ho an'ny fampiharana.

Ireto ny algorithm:

  • Ny mpampiasa dia miditra amin'ny milina amin'ny alàlan'ny navigateur.
  • Raha voamarina ny mpampiasa domaine. Raha tsy izany dia tsy misy fepetra raisina.
  • Raha mpampiasa sehatra ny mpampiasa dia voamarika ny maha-mpikambana ao amin'ny vondrona Administrators.
  • Raha tsy admin dia manamarina raha toa ka voarindra ny Google Authenticator. Raha tsy izany, dia misy kaody QR sy ny fidirana mpampiasa.
  • Raha tsy admin sy Google Authenticator no namboarina dia midira fotsiny.
  • Raha admin dia jereo indray ny Google Authenticator. Raha tsy voafefy, dia misy kaody QR avoaka.

Ny lojika rehetra dia vita amin'ny fampiasana /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

Fanamboarana forigate:

  • Mamorona isika rayon-server

    Freeradius + Google Authenticator + LDAP + Fortigate

  • Mamorona vondrona ilaina izahay, raha ilaina, fanaraha-maso ny fidirana amin'ny vondrona. Anaran'ny vondrona Fortigate tsy maintsy mifanandrify amin'ny vondrona nampidirina Toetra manokana amin'ny mpivarotra Fortinet-Group-Name.

    Freeradius + Google Authenticator + LDAP + Fortigate

  • Fanovana ny ilaina SSL- vavahady.

    Freeradius + Google Authenticator + LDAP + Fortigate

  • Manampy vondrona amin'ny politika.

    Freeradius + Google Authenticator + LDAP + Fortigate

Ny tombony amin'ity vahaolana ity:

  • Azo atao ny manamarina amin'ny OTP on Fortigate vahaolana open source.
  • Ny mpampiasa dia tsy mampiditra tenimiafina domaine rehefa mifandray amin'ny VPN, izay manamora ny fizotran'ny fifandraisana. Mora kokoa ny miditra amin'ny tenimiafina 6 isa noho ilay nomen'ny politika fiarovana. Vokatr'izany dia mihena ny isan'ny tapakila misy lohahevitra hoe: "Tsy afaka mifandray amin'ny VPN aho".

PS Mikasa ny hanavao ity vahaolana ity izahay ho fanamarinana roa lafin-javatra feno miaraka amin'ny valin'ny fanamby.

vaovao farany:

Araka ny nampanantenaina, dia nanova azy io ho amin'ny safidy valin'ny fanamby.
Noho izany:
Ao anaty rakitra /etc/raddb/sites-enabled/default faritra manome lalana toy izao ity:

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
}

Faritra manamarina toa izao:

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
}

Amin'izao fotoana izao ny fanamarinana ny mpampiasa dia mitranga araka ity algorithm manaraka ity:

  • Ny mpampiasa dia miditra amin'ny crédit domain amin'ny mpanjifa VPN.
  • Freeradius dia manamarina ny fahamarinan'ny kaonty sy ny tenimiafina
  • Raha marina ny tenimiafina dia alefa ny fangatahana mari-pamantarana.
  • Hamarinina ny token.
  • tombony).

Source: www.habr.com

Add a comment