Move IfConfig.logIfNecessary call into bootstrap (#22455)
This is related to #22116. A logIfNecessary() call makes a call to NetworkInterface.getInterfaceAddresses() requiring SocketPermission connect privileges. By moving this to bootstrap the logging call can be made before installing the SecurityManager.
This commit is contained in:
parent
f24ca5188a
commit
b9c2c2f6f0
|
@ -40,6 +40,7 @@ import org.elasticsearch.common.logging.DeprecationLogger;
|
||||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||||
import org.elasticsearch.common.logging.LogConfigurator;
|
import org.elasticsearch.common.logging.LogConfigurator;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
|
import org.elasticsearch.common.network.IfConfig;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.transport.BoundTransportAddress;
|
import org.elasticsearch.common.transport.BoundTransportAddress;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
|
@ -207,6 +208,9 @@ final class Bootstrap {
|
||||||
throw new BootstrapException(e);
|
throw new BootstrapException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log ifconfig output before SecurityManager is installed
|
||||||
|
IfConfig.logIfNecessary();
|
||||||
|
|
||||||
// install SM after natives, shutdown hooks, etc.
|
// install SM after natives, shutdown hooks, etc.
|
||||||
try {
|
try {
|
||||||
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
|
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
|
||||||
|
|
|
@ -34,17 +34,17 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* Simple class to log {@code ifconfig}-style output at DEBUG logging.
|
* Simple class to log {@code ifconfig}-style output at DEBUG logging.
|
||||||
*/
|
*/
|
||||||
final class IfConfig {
|
public final class IfConfig {
|
||||||
|
|
||||||
private static final Logger logger = Loggers.getLogger(IfConfig.class);
|
private static final Logger logger = Loggers.getLogger(IfConfig.class);
|
||||||
private static final String INDENT = " ";
|
private static final String INDENT = " ";
|
||||||
|
|
||||||
/** log interface configuration at debug level, if its enabled */
|
/** log interface configuration at debug level, if its enabled */
|
||||||
static void logIfNecessary() {
|
public static void logIfNecessary() {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
try {
|
try {
|
||||||
doLogging();
|
doLogging();
|
||||||
} catch (IOException | SecurityException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("unable to gather network information", e);
|
logger.warn("unable to gather network information", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@ public class NetworkService extends AbstractComponent {
|
||||||
|
|
||||||
public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) {
|
public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) {
|
||||||
super(settings);
|
super(settings);
|
||||||
IfConfig.logIfNecessary();
|
|
||||||
this.customNameResolvers = customNameResolvers;
|
this.customNameResolvers = customNameResolvers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.SecureSM;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.SuppressForbidden;
|
import org.elasticsearch.common.SuppressForbidden;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
|
import org.elasticsearch.common.network.IfConfig;
|
||||||
import org.elasticsearch.plugins.PluginInfo;
|
import org.elasticsearch.plugins.PluginInfo;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
@ -89,6 +90,9 @@ public class BootstrapForTesting {
|
||||||
throw new RuntimeException("found jar hell in test classpath", e);
|
throw new RuntimeException("found jar hell in test classpath", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log ifconfig output before SecurityManager is installed
|
||||||
|
IfConfig.logIfNecessary();
|
||||||
|
|
||||||
// install security manager if requested
|
// install security manager if requested
|
||||||
if (systemPropertyAsBoolean("tests.security.manager", true)) {
|
if (systemPropertyAsBoolean("tests.security.manager", true)) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue