| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<!-- |
| 3 |
~ Copyright 2009-2013 Roland Huss |
| 4 |
~ |
| 5 |
~ Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
~ you may not use this file except in compliance with the License. |
| 7 |
~ You may obtain a copy of the License at |
| 8 |
~ |
| 9 |
~ http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
~ |
| 11 |
~ Unless required by applicable law or agreed to in writing, software |
| 12 |
~ distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
~ See the License for the specific language governing permissions and |
| 15 |
~ limitations under the License. |
| 16 |
--> |
| 17 |
|
| 18 |
<chapter id="proxy"> |
| 19 |
<title>Proxy Mode </title> |
| 20 |
|
| 21 |
<para> |
| 22 |
Using Jolokia in proxy mode enables for agentless operation |
| 23 |
on the target server. A dedicated agent deployment proxies by |
| 24 |
accepting Jolokia requests as input, translating them to JSR-160 |
| 25 |
requests for the target. This setup is described in <xref |
| 26 |
linkend="architecture"/>. As noted there, the real target is |
| 27 |
given within the original request, which must be sent as a POST |
| 28 |
request. |
| 29 |
</para> |
| 30 |
<para> |
| 31 |
Agents of all types support the proxy mode. However, since one |
| 32 |
has usually the free choice of platform for a dedicated Jolokia |
| 33 |
proxy, an environment optimized for HTTP communication should be |
| 34 |
used. These are either servlet container or Java EE server hosting |
| 35 |
the WAR agent or an OSGi runtime with an OSGi HttpService (which |
| 36 |
in turn is typically based on an embedded servlet container like |
| 37 |
Tomcat or Jetty). The two other agents, the Mule and JVM agents |
| 38 |
are not that well suited for this job and do not contain the proxy. |
| 39 |
</para> |
| 40 |
<para> |
| 41 |
Please note that the proxy mode is <emphasis>not</emphasis> switched on by default |
| 42 |
since version 1.5.0. You have to explicitly switch it on for the WAR or OSGI agent: |
| 43 |
</para> |
| 44 |
<itemizedlist> |
| 45 |
<listitem> |
| 46 |
Repackaging the <literal>jolokia.war</literal> and adapt <literal>web.xml</literal> to |
| 47 |
include the init option <literal>dispatcherClasses</literal> with a value <literal>org.jolokia.jsr160.Jsr160RequestDispatcher</literal>. |
| 48 |
</listitem> |
| 49 |
<listitem> |
| 50 |
Set the system property <literal>org.jolokia.jsr160ProxyEnabled</literal> to <literal>true</literal> |
| 51 |
</listitem> |
| 52 |
<listitem> |
| 53 |
Set the environment variable <literal>JOLOKIA_JSR160_PROXY_ENABLED</literal> to <literal>true</literal> |
| 54 |
</listitem> |
| 55 |
</itemizedlist> |
| 56 |
<para> |
| 57 |
The first option requires you to repackage the <literal>jolokia.war</literal> and add the following section to |
| 58 |
the <literal>web.xml</literal> descriptor: |
| 59 |
</para> |
| 60 |
<programlisting language="xml"><![CDATA[ |
| 61 |
<init-param> |
| 62 |
<description> |
| 63 |
Classnames (comma separated) of RequestDispatcher used in addition |
| 64 |
to the LocalRequestDispatcher |
| 65 |
</description> |
| 66 |
<param-name>dispatcherClasses</param-name> |
| 67 |
<param-value>org.jolokia.jsr160.Jsr160RequestDispatcher</param-value> |
| 68 |
</init-param> |
| 69 |
]]></programlisting> |
| 70 |
<para> |
| 71 |
The two other options by using a Java system property or an environment variable do not require a repackaging, so |
| 72 |
these are the recommended way. |
| 73 |
</para> |
| 74 |
<para> |
| 75 |
Additionally you can configured a white list with patterns for all allowed JMX service URL in a Jolokia Request. |
| 76 |
This white list is a plain text file which contains <ulink |
| 77 |
url="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Patterns</ulink> line by line. Lines starting with <literal>#</literal> are ignored. |
| 78 |
This file can be configured in various ways: |
| 79 |
</para> |
| 80 |
<itemizedlist> |
| 81 |
<listitem> |
| 82 |
Repackaging the <literal>jolokia.war</literal> and adapt <literal>web.xml</literal> to |
| 83 |
include the init option <literal>jsr160ProxyAllowedTargets</literal> with a file path to the white list. This should |
| 84 |
be an absolute path or a relative path if you know where your Java EE server sets the current directory. |
| 85 |
</listitem> |
| 86 |
<listitem> |
| 87 |
Set the system property <literal>org.jolokia.jsr160ProxyAllowedTargets</literal> to the path of the whitelist |
| 88 |
</listitem> |
| 89 |
<listitem> |
| 90 |
Set the environment variable <literal>JOLOKIA_JSR160_PROXY_ALLOWED_TARGETS</literal> to the path of the |
| 91 |
whitelist. |
| 92 |
</listitem> |
| 93 |
</itemizedlist> |
| 94 |
<para> |
| 95 |
By default the following patterns are disallowed, but you can re-enable them when providing them in the whitelist: |
| 96 |
</para> |
| 97 |
<programlisting><![CDATA[ |
| 98 |
# Disallow all JNDI lookups via LDAP |
| 99 |
service:jmx:rmi:///jndi/ldap:.* |
| 100 |
]]></programlisting> |
| 101 |
<para> |
| 102 |
In any case it is highly recommended to use a dedicated Java EE servlet server for the JSR-160 proxy which |
| 103 |
is secured by configuring the server authentication properly for this servlet. An unprotected Jolokia proxy can be |
| 104 |
tricked to execute local code by a malicious attacker. As said previously, the Jolokia proxy should be avoided if |
| 105 |
possible in favor of direct access over the Jolokia protocol. |
| 106 |
</para> |
| 107 |
<para> |
| 108 |
All client libraries (jmx4perl, Java and Javascript) support the |
| 109 |
usage of proxy mode in its API. |
| 110 |
</para> |
| 111 |
|
| 112 |
<section title="proxy-limitations"> |
| 113 |
<title>Limitations of proxy mode</title> |
| 114 |
<para> |
| 115 |
The proxy mode has some limitations compared to the direct |
| 116 |
agent mode, so it is recommended to use a |
| 117 |
direct agent deployment if possible. The limitations are: |
| 118 |
</para> |
| 119 |
<itemizedlist> |
| 120 |
<listitem> |
| 121 |
There is no automatic merging of JMX MBeanServers as in the case |
| 122 |
of the direct mode. Most application servers uses their own |
| 123 |
MBeanServer in addition to the |
| 124 |
<literal>PlatformMBeanServer</literal> (which is always |
| 125 |
present). Each MBean is registered only in one MBeanServer. The |
| 126 |
choice of which <literal>MBeanServer</literal> to use has to be |
| 127 |
given up front, usually as a part of the JMX Service URL. But even |
| 128 |
then (as it is the case for JBoss 5.1) you might run into problems |
| 129 |
when selecting the proper MBeanServer. |
| 130 |
</listitem> |
| 131 |
<listitem> |
| 132 |
Proxying adds an additional remote layer which causes |
| 133 |
additional problems. I.e. the complex operations like |
| 134 |
<constant>list</constant> might fail in the proxy mode |
| 135 |
because of serialization issues. E.g. for JBoss it happens |
| 136 |
that certain MBeanInfo objects requested for the list |
| 137 |
operation are not serializable. This is a bug of JBoss, but |
| 138 |
I expect similar limitations for other application servers |
| 139 |
as well. |
| 140 |
</listitem> |
| 141 |
<listitem> |
| 142 |
Certain workarounds (like the JBoss "<emphasis>can not find |
| 143 |
MXBeans before MBeanInfo has been fetched</emphasis>" bug) |
| 144 |
works only in agent mode. |
| 145 |
</listitem> |
| 146 |
<listitem> |
| 147 |
It is astonishingly hard to set up an application server for |
| 148 |
JSR-160 export. And there are even cases (combinations of |
| 149 |
JDK and AppServer Version) which don't work at all properly |
| 150 |
(e.g. JDK 1.5 and JBoss 5). |
| 151 |
</listitem> |
| 152 |
<listitem> |
| 153 |
The proxy mode can theoretically be exploited for local code execution if not secured properly. |
| 154 |
So its is highly recommended to not make the agent available without any authentication to any |
| 155 |
non trusted environment. Also the new whitelist feature prevents redirecting to arbitrary JMX Service URLs. |
| 156 |
</listitem> |
| 157 |
</itemizedlist> |
| 158 |
</section> |
| 159 |
</chapter> |