nginxおよびHTTP Negotiateを介したドメインユーザーのWeb認証

先日、タスクが発生しました-CRMでのドメインユーザーの透過的な承認を確保するために、Microsoft自身はこれらの目的のためにNegotiate HTTP認証方法を開発してきました。 nginx になる方法



ネットワークには、WindowsベースのApache2およびAD用の同様のスキームを編成することに関する膨大な情報がありますが、nginxユーザーは少しずつすべてを収集する必要があり、情報は叫びました。 基本的なNginxパッケージにはそのような機能はありません。 幸いにも、人々は心を失いませんでした。物語は2009年にnginxメーリングリストで始まりました。オハイオ州のアメリカ人の友人がRentACoderの開発者を雇って同様の機能を持つモジュールを提出しました。 彼らはApache用の同様のモジュールをフォークし、nginxにねじ込み、githubで作業の結果を投稿しました。モジュールは時々異なる人々によって更新され、最終的にロボットの外観になりました。 最新バージョンはgithubで入手できます




このガイドでは、nginxをSPNEGOモジュールとsamba4で動作させる方法を説明します。




最初に必要なことは、必要なモジュールでnginxをビルドすることです。 たとえば、Ubuntu 16.04が使用されます。



開始するには、nginxを配置します

apt-get install nginx -V
      
      





次に、公式サイトからソースの最新バージョンをダウンロードします。

 wget http://nginx.org/download/nginx-1.11.2.tar.gz
      
      





わかりました、ソースフォルダーを解凍し、spnego-http-auth-nginx-moduleをそこに入れます

 tar xvzf nginx-1.11.2.tar.gz cd nginx-1.11.2 git clone https://github.com/stnoonan/spnego-http-auth-nginx-module
      
      





私たちは現在、ベースデリバリーからnginxを組み立てたオプションを見て、フットクロスを取得します

 root@dc1:~# nginx -V nginx version: nginx/1.11.1 built by gcc 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1) built with OpenSSL 1.0.2g-fips 1 Mar 2016 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-debug --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed'
      
      





フットクロスをノートブックにコピーして、どこかに追加します

 --add-module=spnego-http-auth-nginx-module
      
      





必要なパラメーターの使用を開始する

 ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --add-module=spnego-http-auth-nginx-module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-debug --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed'
      
      





当然、アセンブリのユーティリティをシステムにインストールし、nginxを削除する必要があります。

 make make install
      
      





手順が完了すると、必要なモジュールを備えた動作可能な自己組み立てnginxがようやく得られます。 これも確認できます-nginx -Vおよびパラメーターのモジュールの存在を確認します。




たとえば、承認にURLを使用しますtest.intranet.com、ドメインintranet.com




Sambaを少し操作して、Kerberosを介した承認のためにサービスプリンシパル名(spn)をハングさせるユーザーを追加します。

 samba-tool user add HTTP samba-tool user setexpiry HTTP --noexpiry samba-tool spn add HTTP/test.intranet.com HTTP samba-tool spn add host/test.intranet.com HTTP
      
      





nginxのKerberosキータブファイルを作成する

 samba-tool domain exportkeytab /etc/http.keytab --principal=HTTP/test.intranet.com samba-tool domain exportkeytab /etc/http.keytab --principal=host/test.intranet.com
      
      





生成されたキータブを確認する

 klist -ke /etc/http.keytab Keytab name: FILE:/etc/http.keytab KVNO Principal ---- -------------------------------------------------------------------------- 1 host/test.intranet.com@INTRANET.COM (des-cbc-crc) 1 host/test.intranet.com@INTRANET.COM (des-cbc-md5) 1 host/test.intranet.com@INTRANET.COM (arcfour-hmac) 1 HTTP/test.intranet.com@INTRANET.COM (des-cbc-crc) 1 HTTP/test.intranet.com@INTRANET.COM (des-cbc-md5) 1 HTTP/test.intranet.com@INTRANET.COM (arcfour-hmac)
      
      





Kerberosを介してドメインコントローラーで承認されています。

 kinit administrator Password for administrator@INTRANET.COM: Warning: Your password will expire in 39 days on  30  2016 11:23:11
      
      





keytabファイルを使用して、spnという名前でドメインの承認を確認します。

 kinit -V -k -t /etc/http.keytab HTTP/test.intranet.com@INTRANET.COM Using default cache: /tmp/krb5cc_0 Using principal: HTTP/test.intranet.com@INTRANET.COM Using keytab: /etc/http.keytab Authenticated to Kerberos v5
      
      





この段階で問題が発生しました。認証は通過したくありませんでした。 エラーは次のとおりです。

kinit:初期資格情報を取得中にKerberosデータベースでクライアントが見つかりません
私はインターネットを介して調べた結果、解決策が見つかりましたが、Microsoftが意図したとおりにsamba-toolがうまくいかなかったことが判明しました、予想外でしたね?

この問題を解決するには、Windowsマシンに移動し、Active Directory-Users and Computers管理コンソールを使用してHTTPユーザーを編集します。つまり、ユーザーログイン名フィールドをHTTP / test.intranet.comに編集します。

この手順の後、すべてが機能します。



それはnginx設定に行く時間です、私の仮想ホスト設定を見てください

  server { listen *:443 ssl; server_name test.intranet.com; # error_log /var/log/nginx/debug.log debug; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; location / { proxy_pass http://********/$request_uri; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; auth_gss on; auth_gss_realm INTRANET.COM; auth_gss_keytab /etc/http.keytab; auth_gss_service_name HTTP/test.intranet.com; # auth_gss_allow_basic_fallback off; } }
      
      







パラメーターauth_gss_allow_basic_fallback off; 何かがうまくいかなかった場合、基本認証リクエストをオフにできます。ユーザーがドメインにいないとしましょう。




透過的な許可が機能するためには、いくつかの条件が満たされている必要があります。




IEのイントラネットセキュリティゾーンにURL-test.intranet.comを追加し、リンクをたどろうとすると、マシン上に残ります。 すべてが正しく構成されている場合、nginxはユーザーを透過的にサイトにスキップします。 接続を実際にプロキシするサーバー側では、次の情報がパケットヘッダーで捕捉されます。

[PHP_AUTH_USER] =>管理者[PHP_AUTH_PW] => bogus_auth_gss_passwd
透過的な認証のための小さなWebアプリケーションを完成させることは残っていますが、それはすでにWebプログラマーです...



他のブラウザでは、このメカニズムはわずかな変更でも機能します。





実際、それがセットアッププロセス全体です。私は彼を数日殺し、それを一般に公開することにしました。 このメカニズムにより、オフィス内のユーザーが内部Webアプリケーションにアクセスするときにユーザー名/パスワードを入力する必要がなくなります。



All Articles