リバース プロキシされた Tomcat コンテキスト上のコンテキストへのアクセスを制限するにはどうすればよいでしょうか?

リバース プロキシされた Tomcat コンテキスト上のコンテキストへのアクセスを制限するにはどうすればよいでしょうか?

私はApacheリバースプロキシでTomcatアプリケーションを実行しています。私はアクセスを制限しようとしていますマネージャーそしてホストマネージャーローカルホストからのコンテキストのみ。

そこで、両方のコンテキストの context.xml ファイルで次の行のコメントを解除しました。

<!--
Remove the comment markers from around the Valve below to limit access to
the manager application to clients connecting from localhost
-->
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
     allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

しかし、ローカルホストからこれらのコンテキストにアクセスしようとすると、常にエラー 403 ページが表示されます。

私はd+許可する属性なので私も試してみました許可="127\.0\.0\.1|::1|0:0:0:0:0:0:0:0:1"運が悪かった。

context.xml の設定に何か問題がありますか?

Apacheのmod_proxyを通過する接続をフィルタリングする場合、動作は異なりますか?(プロキシパス ajp://localhost:8009)?

ありがとう

答え1

ここでは、コンテキストへのアクセスを制限するメカニズム ( を使用して実行RemoteAddrValve) と、 に組み込まれている RBAC という2 つの異なるメカニズムが機能しますserver.xml

<Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />

以下は を使用してテストされていますtomcat-8.0.23:

ファイルを変更してバルブのコメントを削除することにより、localhostコンテキストへのアクセスを制限するためだけに修正された標準構成:managerapache-tomcat-8.0.23/webapps/manager/META-INF/context.xml

<Valve className="org.apache.catalina.valves.RemoteAddrValve"
      allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> 

さらに変更を加えないと、コンテキストにアクセスしようとすると 401 HTTP エラーで失敗します。

$ curl -v -L localhost:8080/manager/
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /manager/ HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=F3F2A25463ED1CD49E154FA5428B853A; Path=/manager/; HttpOnly
< Location: http://localhost:8080/manager/html;jsessionid=F3F2A25463ED1CD49E154FA5428B853A?org.apache.catalina.filters.CSRF_NONCE=B5CB272DF379F59A8158583826850550
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 0
< Date: Sun, 14 Jun 2015 08:47:27 GMT
<
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:8080/manager/html;jsessionid=F3F2A25463ED1CD49E154FA5428B853A?org.apache.catalina.filters.CSRF_NONCE=B5CB272DF379F59A8158583826850550'
* Found bundle for host localhost: 0x256e460
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (::1) port 8080 (#0)
> GET /manager/html;jsessionid=F3F2A25463ED1CD49E154FA5428B853A?org.apache.catalina.filters.CSRF_NONCE=B5CB272DF379F59A8158583826850550 HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Server: Apache-Coyote/1.1
< Cache-Control: private
< Expires: Thu, 01 Jan 1970 01:00:00 GMT
< WWW-Authenticate: Basic realm="Tomcat Manager Application"
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 2474
< Date: Sun, 14 Jun 2015 08:47:27 GMT

ファイルを変更してapache-tomcat-8.0.23/conf/tomcat-users.xml次の内容を追加します。

<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>

そして、今度は認証を使用してコンテキストにアクセスしようとすると、成功します。

$ curl -v -L -utomcat:tomcat localhost:8080/manager/
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'tomcat'
> GET /manager/ HTTP/1.1
> Authorization: Basic dG9tY2F0OnRvbWNhdA==
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=7890CA71EC221A152BDB4F04B66BE49E; Path=/manager/; HttpOnly
< Location: http://localhost:8080/manager/html;jsessionid=7890CA71EC221A152BDB4F04B66BE49E?org.apache.catalina.filters.CSRF_NONCE=92DAD506CB8E9E24E8454BBA94567F84
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 0
< Date: Sun, 14 Jun 2015 08:48:09 GMT
<
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:8080/manager/html;jsessionid=7890CA71EC221A152BDB4F04B66BE49E?org.apache.catalina.filters.CSRF_NONCE=92DAD506CB8E9E24E8454BBA94567F84'
* Found bundle for host localhost: 0x69e4c0
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'tomcat'
> GET /manager/html;jsessionid=7890CA71EC221A152BDB4F04B66BE49E?org.apache.catalina.filters.CSRF_NONCE=92DAD506CB8E9E24E8454BBA94567F84 HTTP/1.1
> Authorization: Basic dG9tY2F0OnRvbWNhdA==
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Cache-Control: private
< Expires: Thu, 01 Jan 1970 01:00:00 GMT
< Set-Cookie: JSESSIONID=42B0B26688726A802B665B0B33D1690B; Path=/manager/; HttpOnly
< Content-Type: text/html;charset=utf-8
< Transfer-Encoding: chunked
< Date: Sun, 14 Jun 2015 08:48:09 GMT

ここで、別のインターフェースを使用してリクエストを実行しようとすると (つまり、 ではない場合localhost)、認証を使用するかどうかに関係なく、403 HTTP エラーが発生します。

$ curl --interface wlp6s0 -v -L -utomcat:tomcat localhost:8080/manager/
*   Trying ::1...
*   Trying 127.0.0.1...
* Local Interface wlp6s0 is ip 192.168.1.187 using address family 2
* SO_BINDTODEVICE wlp6s0 failed with errno 1: Operation not permitted; will do regular bind
* Local port: 0
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'tomcat'
> GET /manager/ HTTP/1.1
> Authorization: Basic dG9tY2F0OnRvbWNhdA==
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=2F3ADE627300D4D264478927D1F0BBFC; Path=/manager/; HttpOnly
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 3196
< Date: Sun, 14 Jun 2015 09:06:52 GMT
<

アクセスを のみ に制限しているため、これは予想どおりですlocalhost

つまり、403 エラー応答を受け取った場合は、Tomcat がリッスンしているインターフェースを確認してください。

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

$ ss -tulpan | grep LISTEN.*8080

リクエストに使用しているインターフェース。

  tcp    LISTEN     0      100                   :::8080                 :::*      users:(("java",pid=32490,fd=48))

答え2

したがって、リクエストがサーバーのパブリック IP から送信されていることを知って、context.xml を次のように変更しました。

<Valve className="org.apache.catalina.valves.RemoteAddrValve"
 allow="xxx\.xxx\.xxx\.xxx|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

どこxxx.xxx.xxx.xxxサーバーのパブリック IP です。現在動作しています。

助けてくれてありがとう

関連情報