Changes between Initial Version and Version 1 of TipAndDoc/network/httpd/accesscontrol


Ignore:
Timestamp:
Dec 16, 2010 11:11:36 PM (13 years ago)
Author:
mitty
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TipAndDoc/network/httpd/accesscontrol

    v1 v1  
     1[[PageOutline]] 
     2 
     3 = Access control = 
     4 * see also wiki:TipAndDoc/project/trac#AccesscontrolwithApache 
     5 
     6 * 特定のメソッド以外制限する 
     7   * <LimitExcept METHOD> => http://httpd.apache.org/docs/2.2/mod/core.html#limitexcept 
     8 * アクセス条件を複数にする 
     9   * Satisfy All|Any => http://httpd.apache.org/docs/2.2/mod/core.html#satisfy 
     10   * see also [#ptifallonSatisfyany] 
     11 * Allow/Denyの適用順 
     12   * デフォルトでは「Order Deny,Allow」 => http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order 
     13     * Deny ディレクティブが Allow ディレクティブの前に評価されます。 アクセスはデフォルトで許可されます。Deny ディレクティブに合わないか、Allow ディレクティブに合うクライアントはアクセスを許可されます。 
     14   * '''使用例''' (サーバへのアクセスはデフォルトで禁止、/tracへのアクセスは許可。但し、GET以外は禁止) 
     15{{{ 
     16<Directory /> 
     17        Options FollowSymLinks 
     18        AllowOverride None 
     19        Order Deny,Allow 
     20        Deny from all 
     21</Directory> 
     22 
     23ScriptAlias /trac       /usr/share/trac/cgi-bin/trac.fcgi 
     24<Location /trac> 
     25        <LimitExcept GET> 
     26                Deny from all 
     27        </LimitExcept> 
     28</Location> 
     29}}} 
     30   * 省略されているOrderディレクティブ(デフォルトの「Order Deny,Allow」)は、<LimitExcept>の範囲ではなく、外の<Location>以下に適用されていると考えるのが妥当 
     31     * 設定の失敗例として、以下のように設定するとGETではないPOSTメソッド等も制限されなくなり、期待する動作(GET以外のメソッドを403にする)を取らなくなる 
     32{{{ 
     33<Directory /> 
     34        Options FollowSymLinks 
     35        AllowOverride None 
     36        Order Deny,Allow 
     37        Deny from all 
     38</Directory> 
     39 
     40ScriptAlias /trac       /usr/share/trac/cgi-bin/trac.fcgi 
     41<Location /trac> 
     42        Allow from all 
     43        <LimitExcept GET> 
     44                Deny from all 
     45        </LimitExcept> 
     46</Location> 
     47}}} 
     48     * <Location>全体で「Deny from all => Allow from all」の順で適用され、結果として全てのメソッドが制限されなくなっていると思われる 
     49   * '''使用例2''' localhost(127.0.0.1)からのみ、GET以外も許可する 
     50{{{ 
     51<Directory /> 
     52        Options FollowSymLinks 
     53        AllowOverride None 
     54        Order Deny,Allow 
     55        Deny from all 
     56</Directory> 
     57 
     58ScriptAlias /trac       /usr/share/trac/cgi-bin/trac.fcgi 
     59<Location /trac> 
     60        <LimitExcept GET> 
     61                Deny from all 
     62                Allow from 127.0.0.1 
     63        </LimitExcept> 
     64</Location> 
     65}}} 
     66     * 内部リバースプロキシなどに応用できる => #11 
     67 
     68 == ptifall on Satisfy any == 
     69 * 「Satisfy any」における落とし穴 
     70 * 目標 
     71   1. 特定のIPからは、認証せず見られる 
     72   1. 特定のIP以外からは、認証後見られる 
     73   1. 特定のディレクトリ(URL)は、認証に関係なく見られない 
     74     * ディレクトリごとに細かく設定するため.htaccessで制御したい 
     75 * 例としては内部向けpukiwikiなど 
     76 
     77 === 標準的な設定 === 
     78 * /etc/apache2/sites-enabled/some.vhost.conf 
     79{{{ 
     80<Directory /> 
     81        AllowOverride Limit 
     82         
     83        Satisfy any 
     84        Order deny,allow 
     85        Deny from all 
     86        Allow from XX.YY.ZZ.XYZ 
     87        AuthType Digest 
     88        AuthName "Authorized" 
     89        AuthUserFile /path/to/.htdigest 
     90        Require valid-user 
     91</Directory> 
     92}}} 
     93 
     94 * /path/to/www/wikiplus/attach/.htaccess 
     95{{{ 
     96Order allow,deny 
     97Deny from all 
     98}}} 
     99 
     100 === 問題点 === 
     101 * 上位設定(この場合some.vhost.conf)で「Satisfy any」としているため、.htaccessにおいて「deny from all」に'''関係なく'''valid-userであればアクセスできてしまう。 
     102 * wget -S --spider --user username --password password !http://example.jp/www/wikiplus/attach/index.html 
     103{{{ 
     104  HTTP/1.1 200 OK 
     105}}} 
     106 
     107 === solution === 
     108 * some.vhost.conf 
     109{{{ 
     110        AllowOverride Limit FileInfo AuthConfig 
     111}}} 
     112   * Satisfyを.htaccessで使うには「AuthConfig」が必要 
     113 * .htaccess 
     114{{{ 
     115Order allow,deny 
     116Deny from all 
     117Satisfy all 
     118}}} 
     119 
     120 * 全ての.htaccessを書き換える必要がありスマートでないので、conf側だけで収まる設定を模索中 
     121 
     122 = ドットから始まるファイル、ディレクトリにアクセス禁止 = 
     123 * [http://tm.root-n.com/server:apache:htaccess:redirectmatch apache :: ドットから始まるファイル、ディレクトリにアクセス禁止 (Tipsというかメモ)] 
     124{{{ 
     125#403 Forbidden 
     126RedirectMatch 403 /\. 
     127}}} 
     128 
     129 * /etc/apache2/conf.d/ に以下のような設定ファイルを作ると全体(全てのVirtualHostを含む)に適用することが出来る。 
     130{{{ 
     131# prevent files and directories started with 'dot' (ex: .svn/) 
     132# from being viewed 
     133 
     134<FilesMatch "^\."> 
     135        Order Allow,Deny 
     136        Deny from all 
     137</FilesMatch> 
     138 
     139<DirectoryMatch "/\."> 
     140        Order Allow,Deny 
     141        Deny from all 
     142</DirectoryMatch> 
     143}}} 
     144   * この場合、「Options +Indexes」となっていてもドットで始まるディレクトリはリスティングされない。また、ドットで始まるディレクトリ内のファイルも当然であるが403となる。 
     145   * ディレクトリorファイルが実際に存在するかどうかはエラー結果に影響しない(存在しないパスであっても404ではなく403エラーになる)。