8
4

More than 3 years have passed since last update.

RadiusサーバとGoogle AuthenticatorでSoftetherにワンタイムパスワードを導入する

Posted at

はじめに

セキュリティ向上策としては証明書認証が一般的ですが、ちょっと互換性に難があるのでワンタイムパスワードにすればいいんじゃないか?と思って構築しました。

表題の構成でSoftetherにTOTP認証を導入する記事はいくつかありますが、Ubuntuでの例は見当たらなかったので備忘録として書いておきます

環境

RaspberryPi4 (2GB)
Ubuntu 20.04 for Rpi armv8

Softetherの導入については拙記事で書きましたので、導入後を前提とします。
Radius認証を利用するので有効化も合わせて行ってください。

Ubuntu 20.04 arm64bit on Raspberrypi 4にSoftetherを導入する
https://qiita.com/Shachihoko/items/543eea4c95153c719224

Radiusサーバの構成

インストール

$ sudo apt install freeradius freeradius-utils

設定

設定ファイルは /etc/freeradius/3.0 にあります。

$ cd /etc/freeradius/3.0

/etc/freeradius/3.0/radiusd.conf

//1箇所目

        #  The server will also try to use "initgroups" to read
        #  /etc/groups.  It will join all groups where "user" is a
        #  member.  This can allow for some finer-grained access
        #  controls.
        #
        user = root          //rootに変更
        group = root         //rootに変更

//2箇所目

        auth = yes           //yesに変更

        #  Log passwords with the authentication requests.
        #  auth_badpass  - logs password if it's rejected
        #  auth_goodpass - logs password if it's correct
        #
        #  allowed values: {no, yes}
        #
        auth_badpass = yes   //yesに変更
        auth_goodpass = yes  //yesに変更

/etc/freeradius/3.0/users

先頭に記載

DEFAULT    Group != "radius_permitted", Auth-Type := Reject //グループ radius_permittedのユーザに対して許可
       Reply-Message = "Your account has been disabled."
DEFAULT        Auth-Type := PAM                             //外部認証を使用

/etc/freeradius/3.0/sites-available/default

PAM認証を有効化

PAM //アンコメント

/etc/freeradius/3.0/clients.conf

Radiusにアクセスする際の共有シークレットを設定

//client localhost ディレクティブのsecretを変更
secret = testing123 //お好きな文字列に

PAM認証のModを有効化

$ ln -s etc/freeradius/3.0/mods-available/pam /etc/freeradius/3.0/mods-enabled/pam

/etc/pam.d/radiusd

pam認証にgoogle authenticatorを指定
現状の設定をコメントアウトして追記

auth    requisite /usr/local/lib/security/pam_google_authenticator.so
account required  pam_permit.so
session required  pam_permit.so

起動チェック

ここで正常に起動すれば大丈夫です。
うまくいかないときは前述の設定にミスがあるはず
自動起動も設定

$ sudo systemctl start radiusd
$ sudo systemctl enable radiusd

Google Authenticatorの導入

前提パッケージの導入

$ sudo apt install libpam0g-dev git gcc qrencode autoconf automake libtool

ビルド&インストール

$ git clone https://github.com/google/google-authenticator-libpam.git
$ cd google-authenticator-libpam
$ ./bootstrap.sh
$ ./configure
$ make
$ sudo make install

ユーザー設定

接続用ユーザーの作成

Google AuthenticatorはSSHと同じく各ユーザのホームディレクトリに関連ファイルを置くので adduserコマンドで作ったほうが楽

このユーザはサーバ自体のログインには影響を与えないので、既存ユーザーを流用しても大丈夫そう

$ sudo adduser vpnclient
//パスワードとか諸々はお好きなように

//グループ作成
$ sudo groupadd radius_permitted

//グループにユーザを追加
$ sudo usermod -aG vpnclient radius_permitted

Google Authenticatorの設定

//接続用のユーザーにスイッチ
$ sudo su vpnclient
$ /usr/local/bin/google-authenticator //sudo ダメ、絶対
$ Do you want authentication tokens to be time-based (y/n) y

このあとはコンソールにQRコードが出るので、それをGoogle Authenticatorアプリに読ませます。
その後の質問は基本的に y で答えていけば良いですが、ワンタイムパスワードの有効期限を4分にするオプションは n にした方がセキュリティ上いいです。(今どきそんなに時計もずれないので)

最後まで正常に完了すれば大丈夫です。
失敗した場合はホームディレクトリに作成されているgoogle authenticatorのディレクトリを削除してやり直しましょう。

接続確認

$ radtest [ユーザー名] [ワンタイムパスワード] [サーバーのアドレス] [ポート] [共有シークレット]

//Example (この記事通りであれば Listen Portは1812)
$ radtest vpnclient 123456 127.0.0.1 1812 testing123

//Received Access-Acceptが返ってくれば成功
Received Access-Accept Id xx from 127.0.0.1:1812 to 127.0.0.1 length xx

Softetherの設定

管理マネージャー上の設定で完結します。

仮想HUBの管理>認証サーバーの設定 でRadiusサーバを指定
rapture_20200503181437.jpg

仮想HUBの管理>ユーザーの管理 で新規ユーザーをRadius認証で作成 (ユーザー名はgoogle Authenticatorで設定したアカウント名と同一にする)
rapture_20200503181625.jpg

さいごに

任意のクライアントソフトで、
ユーザー名;そのまま
パスワード:認証アプリに表示されている6桁のコード
としてログインできるか確かめます。

必要な人だけ

Windows機でSSTPを使う場合は、アダプターの詳細設定でMSCHAPではなくPAPを使うように変更が必要です。
rapture_20200503182307.jpg

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4