I have a tomcat application running with an apache reverse proxy. I'm trying to restrict access to the manager and host-manager contexts from localhost only.
So I uncommented the following line on context.xml file from both contexts:
<!--
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" />
But when I try to access these contexts from localhost it always shows me the error 403 page.
I didn't get the d+ thing in the allow attribute so I also tried allow="127\.0\.0\.1|::1|0:0:0:0:0:0:0:1" too with no luck.
Is there something wrong in my context.xml configuration?
Does it behave different when filtering connections when they pass first through apache's mod_proxy (ProxyPass ajp://localhost:8009)?
Thanks
There are two different mechanisms in play here: restricting access to a context (which is done using the
RemoteAddrValve
) and the built-in RBAC inserver.xml
:The following has been tested using
tomcat-8.0.23
:A stock configuration only modified to restrict access from
localhost
to themanager
context by modifying theapache-tomcat-8.0.23/webapps/manager/META-INF/context.xml
file to remove the comments on the valve:Without further modifications, an attempt to access the context fails with a 401 HTTP error:
After modifying the
apache-tomcat-8.0.23/conf/tomcat-users.xml
file to add the following:and attempt to access the context, this time using authentication, succeeds:
Now, if you try to use a different interface to perform the request (i.e. not
localhost
), you will hit a 403 HTTP error, regardless you use authentication or not:This is as expected, as we are restricting access from
localhost
only.In short, if you get a 403 error response, check the interface tomcat is listening to:
and the interface you are using for the request.
So, knowing that my requests were being sent from my server's public ip I changed my context.xml to:
Where xxx.xxx.xxx.xxx is the serve's public ip. It's now working.
Thanks for helping