HTTP Digest 認証

説明

ngx_http_auth_digest - NGINXのための HTTP Digest 認証。

注意

このモジュールはNGINXのソースと一緒に配布されません。 インストレーションの説明を見てください。

状態

モジュールはRFCに関しては機能を満たしていますが、プロダクションで使うのに安全だと見なされるには広いテストが必要です。警告の現在のセットのために bugs.txt ファイルとgithub issue trackerを見てください。

概要

以下の行をNGINX設定ファイルの中のserver セクションに以下の行を追加することでディレクトリツリーへのアクセスを制限することができます。

auth_digest_user_file /opt/httpd/conf/passwd.digest; # a file created with htdigest
location /private {
    auth_digest 'this is not for you'; # set the realm for this location block
}

他のディレクティブは認証セッションのためのデフォルトのライフスパンを制御します。 以下は以前の例と等価ですが、全てのディレクティブを明示します:

auth_digest_user_file /opt/httpd/conf/passwd.digest;
auth_digest_shm_size 4m;   # the storage space allocated for tracking active sessions

location /private {
    auth_digest 'this is not for you';
    auth_digest_timeout 60s; # allow users to wait 1 minute between receiving the
                             # challenge and hitting send in the browser dialog box
    auth_digest_expires 10s; # after a successful challenge/response, let the client
                             # continue to use the same nonce for additional requests
                             # for 10 seconds before generating a new challenge
    auth_digest_replays 20;  # also generate a new challenge if the client uses the
                             # same nonce more than 20 times before the expire time limit
}

locationへのダイジェスト認証への追加はブロックに一致する全てのuriに影響するでしょう。uriの特定のサブブランチへの認証を無効にするには、auth_digestoffに設定します:

location / {
    auth_digest 'this is not for you';
    location /pub {
        auth_digest off; # this sub-tree will be accessible without authentication
    }
}

ディレクティブ

auth_digest

構文:auth_digest [ realm-name | off ]
デフォルト:off
コンテキスト:server, location

serverあるいはlocationブロックのダイジェスト認証を有効または無効にします。realm 名はuserファイルの中で使われるrealmに対応しなければなりません。そのrealm内の全てのユーザは認証のあとでファイルにアクセスすることができるでしょう。

保護されたuri構造の中で認証を選択的に無効にするには、もっと特定なlocationブロックの中でauth_digest を "off"に設定します (例を見てください)。

auth_digest_user_file

構文:auth_digest_user_file /path/to/passwd/file
デフォルト:none
コンテキスト:server, location

パスワードファイルはapacheのhtdigestコマンド(あるいは htdigest.py スクリプト)で生成された形でなければなりません。ファイルの各行は、ユーザ名、realm、および名前、realmとパスワードを結合したmd5ハッシュから構成されたコロン区切りのリストです。例えば:

joi:enfield:ef25e85b34208c246cfd09ab76b01db7

auth_digest_timeout

構文:auth_digest_timeout delay-time
デフォルト:60s
コンテキスト:server, location

クライアントが最初に保護されたページをリクエストすると、サーバはWWW-Authenticate ヘッダの中にチャレンジと一緒に401ステータスコードを返します。

この時点でほとんどのブラウザはユーザにログインを促すためのダイアログボックスを表示するでしょう。このディレクティブはどれだけ長くチャレンジが有効であるかを定義します。ユーザが名前とパスワードを提出する前にこの時間より長く待つ場合は、チャレンジは'stale'とみなされ、再びログインを促されるでしょう。

auth_digest_expires

構文:auth_digest_expires lifetime-in-seconds
デフォルト:10s
コンテキスト:server, location

一度クライアントによってダイジェストのチェレンジが首尾よく回答されると、続くリクエストは元のチャレンジから'nonce'値を再利用しようとするでしょう。MitM アタックを困難にするには、キャッシュされたnonceが受け付けられる回数を制限するのが良いでしょう。このディレクティブは最初の成功した認証後のこの再利用期間の持続期間を設定します。

auth_digest_replays

構文:auth_digest_replays number-of-uses
デフォルト:20
コンテキスト:server, location

Nonce の再利用もリクエストの固定数に制限されなければなりません。この値を増加することはメモリの比例的な増加を引き起こすことになり、shm_sizeはダイジェストで保護されたlocationブロック内の大きなトラフィックに負けないでついていくために適応される必要があるかも知れません。

auth_digest_shm_size

構文:auth_digest_shm_size size-in-bytes
デフォルト:4096k
コンテキスト:server

モジュールは認証されたリクエスト間の状態を保持するためにアクティブなダイジェストセッションの固定サイズのキャッシュを保持します。このキャッシュが一旦溢れると、アクティブなセッションが有効期限切れになるまでそれ以上の認証はできないでしょう。

結果として、有効期限に関係するディレクティブに設定された値に依存するため、適切なサイズの選択は少し手の込んだものになります。保存された各チャレンジは 48 + ceil(auth_digest_replays/8) バイトを占め、auth_digest_timeout + auth_digest_expires 秒まで生存するでしょう。デフォルトのモジュール設定を使う場合、これは各70秒ごとの約82kの返答無しのリクエストを許容することに言い換えられます。

ソースリポジトリ

Available on github at atomx/nginx-http-auth-digest.

Author

Atomx <https://www.atomx.com/> Christian Swinehart / Samizdat Drafting Co.

TOP
inserted by FC2 system