mirror of https://github.com/apache/cassandra
FBUtilities.getJustLocalAddress falls back to lo ip on misconfigured nodes
patch by Berenguer Blasi; reviewed by Robert Stupp, Mick Semb Wever for CASSANDRA-15901
This commit is contained in:
parent
73691944c0
commit
4654ef09c1
|
|
@ -1,4 +1,5 @@
|
|||
4.0-alpha5
|
||||
* FBUtilities.getJustLocalAddress falls back to lo ip on misconfigured nodes (CASSANDRA-15901)
|
||||
* Close channel and reduce buffer allocation during entire sstable streaming with SSL (CASSANDRA-15900)
|
||||
* Prune expired messages less frequently in internode messaging (CASSANDRA-15700)
|
||||
* Fix Ec2Snitch handling of legacy mode for dc names matching both formats, eg "us-west-2" (CASSANDRA-15878)
|
||||
|
|
|
|||
|
|
@ -630,7 +630,8 @@ ssl_storage_port: 7001
|
|||
# Leaving it blank leaves it up to InetAddress.getLocalHost(). This
|
||||
# will always do the Right Thing _if_ the node is properly configured
|
||||
# (hostname, name resolution, etc), and the Right Thing is to use the
|
||||
# address associated with the hostname (it might not be).
|
||||
# address associated with the hostname (it might not be). If unresolvable
|
||||
# it will fall back to InetAddress.getLoopbackAddress(), which is wrong for production systems.
|
||||
#
|
||||
# Setting listen_address to 0.0.0.0 is always wrong.
|
||||
#
|
||||
|
|
|
|||
|
|
@ -130,16 +130,29 @@ public class FBUtilities
|
|||
public static InetAddress getJustLocalAddress()
|
||||
{
|
||||
if (localInetAddress == null)
|
||||
try
|
||||
{
|
||||
if (DatabaseDescriptor.getListenAddress() == null)
|
||||
{
|
||||
localInetAddress = DatabaseDescriptor.getListenAddress() == null
|
||||
? InetAddress.getLocalHost()
|
||||
: DatabaseDescriptor.getListenAddress();
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
try
|
||||
{
|
||||
localInetAddress = InetAddress.getLocalHost();
|
||||
logger.info("InetAddress.getLocalHost() was used to resolve listen_address to {}, double check this is "
|
||||
+ "correct. Please check your node's config and set the listen_address in cassandra.yaml accordingly if applicable.",
|
||||
localInetAddress);
|
||||
}
|
||||
catch(UnknownHostException e)
|
||||
{
|
||||
logger.info("InetAddress.getLocalHost() could not resolve the address for the hostname ({}), please "
|
||||
+ "check your node's config and set the listen_address in cassandra.yaml. Falling back to {}",
|
||||
e,
|
||||
InetAddress.getLoopbackAddress());
|
||||
// CASSANDRA-15901 fallback for misconfigured nodes
|
||||
localInetAddress = InetAddress.getLoopbackAddress();
|
||||
}
|
||||
}
|
||||
else
|
||||
localInetAddress = DatabaseDescriptor.getListenAddress();
|
||||
}
|
||||
return localInetAddress;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import javax.rmi.ssl.SslRMIClientSocketFactory;
|
|||
import javax.rmi.ssl.SslRMIServerSocketFactory;
|
||||
import javax.security.auth.Subject;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -63,7 +64,8 @@ public class JMXServerUtils
|
|||
* inaccessable.
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public static JMXConnectorServer createJMXServer(int port, boolean local)
|
||||
@VisibleForTesting
|
||||
public static JMXConnectorServer createJMXServer(int port, String hostname, boolean local)
|
||||
throws IOException
|
||||
{
|
||||
Map<String, Object> env = new HashMap<>();
|
||||
|
|
@ -120,7 +122,7 @@ public class JMXServerUtils
|
|||
(RMIClientSocketFactory) env.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE),
|
||||
(RMIServerSocketFactory) env.get(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE),
|
||||
env);
|
||||
JMXServiceURL serviceURL = new JMXServiceURL("rmi", null, rmiPort);
|
||||
JMXServiceURL serviceURL = new JMXServiceURL("rmi", hostname, rmiPort);
|
||||
RMIConnectorServer jmxServer = new RMIConnectorServer(serviceURL, env, server, ManagementFactory.getPlatformMBeanServer());
|
||||
|
||||
// If a custom authz proxy was created, attach it to the server now.
|
||||
|
|
@ -133,6 +135,12 @@ public class JMXServerUtils
|
|||
return jmxServer;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static JMXConnectorServer createJMXServer(int port, boolean local) throws IOException
|
||||
{
|
||||
return createJMXServer(port, null, local);
|
||||
}
|
||||
|
||||
private static Map<String, Object> configureJmxAuthentication()
|
||||
{
|
||||
Map<String, Object> env = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class JMXAuthTest extends CQLTester
|
|||
System.setProperty("java.security.auth.login.config", config);
|
||||
System.setProperty("cassandra.jmx.remote.login.config", "TestLogin");
|
||||
System.setProperty("cassandra.jmx.authorizer", NoSuperUserAuthorizationProxy.class.getName());
|
||||
jmxServer = JMXServerUtils.createJMXServer(9999, true);
|
||||
jmxServer = JMXServerUtils.createJMXServer(9999, "localhost", true);
|
||||
jmxServer.start();
|
||||
|
||||
JMXServiceURL jmxUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
|
||||
|
|
|
|||
Loading…
Reference in New Issue