Skip to content

Commit

Permalink
Move IfConfig.logIfNecessary call into bootstrap (#22455)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks authored Jan 6, 2017
1 parent f24ca51 commit b9c2c2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.LogConfigurator;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.IfConfig;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.env.Environment;
Expand Down Expand Up @@ -207,6 +208,9 @@ public void run() {
throw new BootstrapException(e);
}

// Log ifconfig output before SecurityManager is installed
IfConfig.logIfNecessary();

// install SM after natives, shutdown hooks, etc.
try {
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
/**
* 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 String INDENT = " ";

/** log interface configuration at debug level, if its enabled */
static void logIfNecessary() {
public static void logIfNecessary() {
if (logger.isDebugEnabled()) {
try {
doLogging();
} catch (IOException | SecurityException e) {
} catch (IOException e) {
logger.warn("unable to gather network information", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public interface CustomNameResolver {

public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) {
super(settings);
IfConfig.logIfNecessary();
this.customNameResolvers = customNameResolvers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.IfConfig;
import org.elasticsearch.plugins.PluginInfo;
import org.junit.Assert;

Expand Down Expand Up @@ -89,6 +90,9 @@ public class BootstrapForTesting {
throw new RuntimeException("found jar hell in test classpath", e);
}

// Log ifconfig output before SecurityManager is installed
IfConfig.logIfNecessary();

// install security manager if requested
if (systemPropertyAsBoolean("tests.security.manager", true)) {
try {
Expand Down

0 comments on commit b9c2c2f

Please sign in to comment.