
Apache 역방향 프록시로 실행되는 Tomcat 응용 프로그램이 있습니다. 액세스를 제한하려고 합니다.관리자그리고호스트 관리자localhost의 컨텍스트만 가능합니다.
그래서 두 컨텍스트 모두에서 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" />
하지만 localhost에서 이러한 컨텍스트에 액세스하려고 하면 항상 오류 403 페이지가 표시됩니다.
나는 그것을 얻지 못했다디+안에 있는 것허용하다속성이므로 나도 시도했습니다.허용="127\.0\.0\.1|::1|0:0:0:0:0:0:0:1"그것도 운이 없이.
내 context.xml 구성에 문제가 있습니까?
Apache의 mod_proxy를 먼저 통과할 때 연결을 필터링할 때 다르게 동작합니까(ProxyPass ajp://localhost:8009)?
감사해요
답변1
여기에는 두 가지 서로 다른 메커니즘이 있습니다. 즉, 컨텍스트에 대한 액세스를 제한하고( 를 사용하여 수행됨 RemoteAddrValve
) 에 내장된 RBAC를 사용하는 것입니다 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
에 대한 액세스를 제한하도록 수정된 스톡 구성만 :manager
apache-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입니다. 이제 작동 중입니다.
도와 줘서 고맙다