【目的】
現状の限られた利用者のテレワークシステムを回避するため、社内Webシステムを2要素認証を使って、社外から利用可能にする。
(背景)
災害対策として、仮想デスクトップ+リモート接続方式では、ネットワーク接続口がボトルネックとなる。また、テレワークでは、ノートPCやスマートデバイスなど貸与機器が増え、サーバー/ネットワーク増強ではまかない切れない
【概要】
CentOS7にて、Google Authenticatorを導入し、社内外のネットワークを問わず直ぐに業務できるWeb環境(内製Webシステム)
【参考記事】
【環境設定】
# nmtui (アドレスとデフォルトゲートウェイを修正) 最後に、「OK」を押し、「戻る」 (システムのホスト名を設定する) 最後に、「OK」を押し、「戻る」 (ホスト名が表示される) 再起動して、IPアドレス、サーバー名が変わったことを確認する。 |
# yum install httpd httpd-devel mod_ssl openssl-devel (サーバー起動) # systemctl start httpd.service(Firewall設定){# firewall-cmd –zone=public –permanent –add-port=80/tcp} <= 試験のみ # firewall-cmd –zone=public –permanent –add-port=443/tcpsuccess# firewall-cmd –reload (自動起動設定) # systemctl enable httpd.serviceCreated symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. |
【SSL追加設定】※まだ、basic認証(BASIC認証用) <- 試験 # htpasswd -b -c /var/www/.htpasswd u000326 123 # chown apache.apache /var/www/.htpasswd # chmod 644 /var/www/.htpasswd (環境設定変更 1.ssl.conf) # cd /etc/httpd/conf.d# vi ssl.conf # diff ssl.conf ssl.conf.org 59,60c59,60 < DocumentRoot “/var/www/html” < ServerName www.aitake.net:443— >#DocumentRoot “/var/www/html” > #ServerName www.example.com: 44364,67c64,65 < #ErrorLog logs/ssl_error_log < #TransferLog logs/ssl_access_log < ErrorLog logs/error_log < TransferLog logs/access_log— > ErrorLog logs/ssl_error_log > TransferLog logs/ssl_access_log 102,103c100 < #SSLCertificateFile /etc/pki/tls/certs/localhost.crt < SSLCertificateFile /opt/http/ssl/certs/server.crt— > SSLCertificateFile /etc/pki/tls/certs/localhost.crt 110,111c107 < #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key < SSLCertificateKeyFile /opt/http/ssl/certs/server.key— > SSLCertificateKeyFile /etc/pki/tls/private/localhost.key 127d122 < SSLCACertificateFile /opt/http/ssl/certs/ca-bundle.crt 151,158d145 < < <Location /> < AuthUserFile /var/www/.htpasswd < AuthGroupFile /dev/null < AuthName “Basic Auth” < AuthType Basic < Require valid-user < </Location> (環境設定変更 2.httpd-ssl-pass-dialog) # cd /usr/libexec # cp httpd-ssl-pass-dialog httpd-ssl-pass-dialog.org # diff httpd-ssl-pass-dialog httpd-ssl-pass-dialog.org 3,4c3 < #exec /bin/systemd-ask-password “Enter SSL pass phrase for $1 ($2) : ” < echo “aitake.net” — > exec /bin/systemd-ask-password “Enter SSL pass phrase for $1 ($2) : ” (ssl設定の設定) ※別途、記述 (apache再起動)# systemctl reload httpd |
(DNSの設定) ※まだ、暫定 https://www.aitake.net/***/ に接続し、ユーザー/パスワードでページが開くこと |
(GoogleAuth本番) |
# vi /etc/yum.conf一時的に、以下の内容をコメントアウトするexclude=kernel* # yum install automake gcc git ftp ntp # vi /etc/yum.conf 以下の内容をコメントアウトを戻す exclude=kernel *Proxy環境を設定する(もしあれば) proxy=http://***.***.***.***:8080 (時刻設定) # vi /etc/ntp.conf # Please consider joining the pool (http://www.pool.ntp.org/join.html). server 192.168.10.254 (下の4アドレスをコメントアウト) # systemctl start ntpd.service# systemctl enable ntpd.service # firewall-cmd –add-service=ntp –zone=public# firewall-cmd –reload |
(ソースの取得) # git clone https://github.com/archiecobbs/mod-authn-otp (ソフト作成&導入) /etc/httpd/modules/mod_authn_otp.so が作成される cd mod-authn-otp ./autogen.sh -cmakesudo make install (httpdサーバー再構成) # service httpd configtestSyntax OK # systemctl reload httpd.service (httpdのOTP設定) # cd /etc/httpd/conf.d # cp ssl.conf ssl.conf.org # vi ssl.conf (変更内容) # diff ssl.conf ssl.conf.org 59,60c59,60 < DocumentRoot “/var/www/html” < ServerName localweb.***.***.co.jp:443 — > #DocumentRoot “/var/www/html” > #ServerName www.example.com :44364,67c64,65 < #ErrorLog logs/ssl_error_log < #TransferLog logs/ssl_access_log < ErrorLog logs/error_log < TransferLog logs/access_log — > ErrorLog logs/ssl_error_log > TransferLog logs/ssl_access_log 102,103c100 < #SSLCertificateFile /etc/pki/tls/certs/localhost.crt < SSLCertificateFile /opt/http/ssl/certs/server.crt — > SSLCertificateFile /etc/pki/tls/certs/localhost.crt 110,111c107 < #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key < SSLCertificateKeyFile /opt/http/ssl/certs/server.key — > SSLCertificateKeyFile /etc/pki/tls/private/localhost.key127d122 < SSLCACertificateFile /opt/http/ssl/certs/ca-bundle.crt151,182d145 < < # BASIC認証 < #<Location /> < # AuthUserFile /var/www/.htpasswd < # AuthGroupFile /dev/null < # AuthName “Basic Auth” < # AuthType Basic < # Require valid-user < #</Location> < < # Add Config T.Ishiguro< <Location /> < Satisfy any < Order allow,deny < Allow from 127.0.0.1 < # 特定のIP帯からはMFA無しで利用できるようにしたい場合 < #Allow from xxx.xxx.xxx.xxx/30 < < #Debug. 誰でもアクセスできる。 < #Require all granted < < AuthType Basic < AuthName “OTP Authentication (Enter OTP as password)” < AuthBasicProvider OTP < Require valid-user < OTPAuthUsersFile /var/www/otp/users < OTPAuthMaxLinger 3600 < # OTPAuthMaxOTPFailure 20 < OTPAuthPINAuthProvider file < OTPAuthLogoutOnIPChange On < </Location> < |
# mkdir -p /var/www/otp/usersToken Type: HOTP/T30(Google Authenticatorの時間ベースで扱える形式) この設定以外は、Shell内容を修正する模様だがまだ、解析していない。Username: 適当にPIN: 無しToken Key: ランダムに生成したsecret_keyをBase16エンコードした値を記入 (実行結果) # sh OtpUserMake.sh u000326 https://chart.googleapis.com/chart?chs=300×300&cht=qr&chl=otpauth%3A//totp/%3Au000326%3Fsecret%3DGJWHMZ3OMVUGGMDQG42XG2DT%26issuer%3D # cat /var/www/otp/usersHOTP/T30 u000326 – 326C76676E65686330703735736873 |
Webサーバーのトップ/etc/httpd/conf.d/ssl.conf にGoogleAuth設定が有効なので下位の設定で加えなくてもよい(省略可)。 # cd /etc/httpd/conf.d 【WebMail-設定】webmail.conf # WebMail 対応 <Location /webmail> ProxyPass http://webmail.***.***.co.jp:8880/roundcube/ ProxyPassReverse http://webmail/.***.***.co.jp:8880/roundcube/ </Location> |
どのユーザーがアクセスしたか? # cat /var/log/httpd/access_log | awk -F ‘ ‘ ‘{ print $3 }’ | sort | uniq どこにつなげたか? # cat /var/log/httpd/access_log | awk -F ‘/’ ‘{ print $4 }’ | sort | uniq アクセス元 IP の一覧 # cat /var/log/httpd/access_log | cut -d ” ” -f 1 | sort | uniq 特定の IP からのアクセスだけを抽出 # grep “^10.0.0.101” /var/log/httpd/access_log 上記から画像やら CSS やらへのアクセスを除外したい # grep “^10.0.0.101” /var/log/httpd/access_log | grep -ive “GET /.*\.\(css\|js\|jpg\|gif\|png\|swf\|ico\)\ HTTP” ブラウザ毎のアクセス数が知りたい # for UA in MSIE Firefox Chrome; do COUNT=`grep “$UA” /var/log/httpd/access_log | wc -l`; echo “$UA : $COUNT”; done 《テキストベースのアクセスログ》 yum install https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/g/goaccess-1.3-1.el7.x86_64.rpm (操作方法) # goaccess /var/log/httpd/access_log  |
【管理設定】
# useradd -G wheel -c “Kanri User” kanri# passwd kanri (確認) # grep kanri /etc/passwdkanri:x:1000:1000:Kanri User:/home/kanri:/bin/bash # grep wheel /etc/groupwheel:x:10:kanri (rootでSSHログインできないようにする) # vi /etc/pam.d/suauth required pam_wheel.so use_uid ※上記行のコメントアウトを解除 # vi /etc/ssh/sshd_config #PermitRootLogin yes PermitRootLogin without-password ※上記追加 |
3132
「/etc/logrotate.d/httpd」 /var/log/httpd/*log { daily missingok notifempty sharedscripts rotate 10 compress delaycompress prerotate /opt/script/system/HttpdKanri.sh 2>/dev/null endscript postrotate /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true endscript } 「/opt/script/system/HttpdKanri.sh」 #!/bin/bash # # httpdサーバーの接続記録を保存する # 注意:この設定は、/etc/logrotate.d/httpd にありログローテート毎に実行する # #CREATE T.Ishiguro 新規作成 # LOGFILE=/var/log/httpd/access_log USRLOGDIR=/var/log/httpd/user FILEDIR=/var/log/httpd/report DATESTR=`date +”%Y%m%d”` #日次のユーザー記録 cat ${LOGFILE} | awk -F ‘ ‘ ‘{ print $3 }’ | sort | uniq > ${USRLOGDIR}/${DATESTR}.txt # goaccessログ記録 goaccess ${LOGFILE} –log-format=COMMON -o ${FILEDIR}/${DATESTR}.csv |
CentOSの初期画面を非表示にする # cd /etc/httpd/conf.d # cp welcome.conf welcome.conf.org # vi welcome.conf(変更内容) # diff welcome.conf welcome.conf.org 8,11c8,11 < #<LocationMatch “^/+$”> < # Options -Indexes < # ErrorDocument 403 /.noindex.html < #</LocationMatch>—> <LocationMatch “^/+$”> > Options -Indexes > ErrorDocument 403 /.noindex.html > </LocationMatch>フォルダ一覧を非表示にする # cd /etc/httpd/conf # cp httpd.conf httpd.conf.org # vi httpd.conf (変更内容) # diff httpd.conf httpd.conf.org 144c144 < Options FollowSymLinks— > Options Indexes FollowSymLinks (上記設定の反映) # systemctl reload httpd.service |