Freeradius + Google Authenticator + LDAP + Fortigate

XNUMX 要素認証は望ましいものであると同時に厄介なものですが、ハードウェア トークンを購入するお金がなく、一般的には良い気分を維持しようとしている場合はどうなるでしょうか。

このソリューションは、非常に独創的なものではなく、インターネット上で見つかったさまざまなソリューションを組み合わせたものです。

だから与えられた

Домен Active Directory.

現在の多くのドメイン ユーザーと同様に、VPN を介して作業するドメイン ユーザー。

VPNゲートウェイとして機能 FortiGateの.

VPN クライアントのパスワードを保存することは、セキュリティ ポリシーにより禁止されています。

政治 フォーティネット 自分のトークンに関しては、10 zhlob 未満とは言えません。無料トークンは XNUMX 個あり、残りは非常に非コーシャ価格です。 私はオープンソースを望んでいたので、RSASecureIDやDuoなどは考慮しませんでした。

前提条件: ホスト * nix 確立された FreeRADIUSの, sssd - ドメインに入力すると、ドメイン ユーザーはそのドメインで簡単に認証できます。

追加のパッケージ: シェリナボックス, イチジク, フリーラジアス-LDAP、フォント 反逆者.tlf リポジトリから https://github.com/xero/figlet-fonts.

私の例では、CentOS 7.8。

作業ロジックは次のようになります。VPN に接続するとき、ユーザーはパスワードの代わりにドメイン ログインと OTP を入力する必要があります。

サービスのセットアップ

В /etc/raddb/radiusd.conf 代表して開始されるユーザーとグループのみ FreeRADIUSの、サービス以来 半径 すべてのサブディレクトリ内のファイルを読み取ることができる必要があります / 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
        }
}

インストール後 フリーラジアス-LDAP ディレクトリ内で raddb/mods が利用可能 ファイルが作成されました 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/サイト有効/デフォルト и raddb/sites-enabled/inner-tunnel セクションで 認める 使用するポリシーの名前「group_authorization」を追加します。 重要な点 - ポリシーの名前は、ディレクトリ内のファイルの名前によって決まりません。 ポリシー.dただし、ファイル内の波括弧の前のディレクティブによって行われます。
セクションで 認証 同じファイル内の行のコメントを解除する必要があります PAM.

ファイル内 クライアント.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の с 、モジュール構成を使用することが決定されました。 PAM トークンのみを確認できるようにする .

ユーザーが接続すると、次のことが起こります。

  • Freeradius は、ユーザーがドメインおよび特定のグループに属しているかどうかを確認し、成功した場合は OTP トークンを確認します。

「300 人以上のユーザーに OTP を登録するにはどうすればよいでしょうか?」と考えた瞬間までは、すべてが十分にうまくいっているように見えました。

ユーザーは次のコマンドを使用してサーバーにログインする必要があります FreeRADIUSの そしてあなたのアカウントからアプリケーションを実行してください Googleオーセンティケータ、ユーザーのアプリケーションの QR コードが生成されます。 ここで助けが必要になります。 シェリナボックス と組み合わせて .bash_profile.

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

デーモン構成ファイルは次の場所にあります。 /etc/sysconfig/shellinabox.
そこでポート 443 を指定すると、証明書を指定できます。

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

ユーザーは、リンクをたどり、ドメイン クレジットを入力し、アプリケーションの QR コードを受け取るだけで済みます。

アルゴリズムは次のとおりです。

  • ユーザーはブラウザを通じてマシンにログインします。
  • ドメインユーザーがチェックされているかどうか。 そうでない場合、アクションは実行されません。
  • ユーザーがドメイン ユーザーの場合は、Administrators グループのメンバーシップがチェックされます。
  • 管理者でない場合は、Google Authenticator が設定されているかどうかを確認します。 そうでない場合は、QR コードが生成され、ユーザーがログアウトします。
  • 管理者ではなく、Google Authenticator が設定されている場合は、そのままログアウトしてください。
  • 管理者の場合は、Google Authenticator を再度確認します。 構成されていない場合は、QR コードが生成されます。

すべてのロジックは次を使用して実行されます /etc/skel/.bash_profile.

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

強化セットアップ:

  • 作成する 半径-サーバ

    Freeradius + Google Authenticator + LDAP + Fortigate

  • 必要に応じて必要なグループを作成し、グループによるアクセス制御を行います。 グループ名 FortiGateの 渡されるグループと一致する必要があります ベンダー固有の属性 フォーティネットグループ名.

    Freeradius + Google Authenticator + LDAP + Fortigate

  • 必要な編集 SSL-ポータル。

    Freeradius + Google Authenticator + LDAP + Fortigate

  • ポリシーへのグループの追加。

    Freeradius + Google Authenticator + LDAP + Fortigate

このソリューションの利点:

  • OTPによる認証が可能です。 FortiGateの オープンソースのソリューション。
  • VPN 経由で接続する場合、ユーザーはドメイン パスワードを入力しないため、接続プロセスが多少簡素化されます。 6 桁のパスワードは、セキュリティ ポリシーで規定されているパスワードよりも入力が簡単です。 その結果、「VPN に接続できません」という件名のチケットの数が減少します。

PS このソリューションを、チャレンジ/レスポンスを備えた本格的な XNUMX 要素認証にアップグレードする予定です。

アップデート:

約束どおり、チャレンジ/レスポンスのオプションに微調整しました。
だから:
ファイル内 /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 はアカウントとパスワードの有効性をチェックします
  • パスワードが正しい場合、トークンのリクエストが送信されます。
  • トークンは検証中です。
  • 利益)。

出所: habr.com

コメントを追加します