Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-13158: DIH: Add System property toggle for use of dataConfig param

David Smiley325824cd391c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 562586ac4fa..646f204f2ae 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -257,6 +257,12 @@ Bug Fixes
* SOLR-13159: Fix atomic update encoding issue for UUID, enum, bool, and binary fields (Thomas Wockinger via Jason Gerlowski)
+Improvements
+----------------------
+
+* SOLR-13158: DataImportHandler: Added enable.dih.dataConfigParam system property to toggle whether the dataConfig param
+ is permitted. (David Smiley, janhoy, Tomás Fernández Löbbe)
+
================== 8.1.1 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java
index 71ee442ac22..50938e4c380 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java
@@ -80,6 +80,9 @@ public class DataImportHandler extends RequestHandlerBase implements
private static final String PARAM_WRITER_IMPL = "writerImpl";
private static final String DEFAULT_WRITER_NAME = "SolrWriter";
+ static final String ENABLE_DIH_DATA_CONFIG_PARAM = "enable.dih.dataConfigParam";
+
+ final boolean dataConfigParam_enabled = Boolean.getBoolean(ENABLE_DIH_DATA_CONFIG_PARAM);
public DataImporter getImporter() {
return this.importer;
@@ -134,7 +137,7 @@ public class DataImportHandler extends RequestHandlerBase implements
if (DataImporter.SHOW_CONF_CMD.equals(command)) {
String dataConfigFile = params.get("config");
- String dataConfig = params.get("dataConfig");
+ String dataConfig = params.get("dataConfig"); // needn't check dataConfigParam_enabled; we don't execute it
if(dataConfigFile != null) {
dataConfig = SolrWriter.getResourceAsString(req.getCore().getResourceLoader().openResource(dataConfigFile));
}
@@ -151,6 +154,12 @@ public class DataImportHandler extends RequestHandlerBase implements
return;
}
+ if (params.get("dataConfig") != null && dataConfigParam_enabled == false) {
+ throw new SolrException(SolrException.ErrorCode.FORBIDDEN,
+ "Use of the dataConfig param (DIH debug mode) requires the system property " +
+ ENABLE_DIH_DATA_CONFIG_PARAM + " because it's a security risk.");
+ }
+
rsp.add("initArgs", initArgs);
String message = "";
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
index 7b8ff8849e9..3674a3d58f1 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
@@ -39,7 +39,7 @@ import org.apache.solr.update.MergeIndexesCommand;
import org.apache.solr.update.RollbackUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
-import org.junit.Before;
+import org.junit.BeforeClass;
/**
* <p>
@@ -60,13 +60,10 @@ public abstract class AbstractDataImportHandlerTestCase extends
FileUtils.copyDirectory(getFile("dih/solr"), testHome);
initCore(config, schema, testHome.getAbsolutePath());
}
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- File home = createTempDir("dih-properties").toFile();
- System.setProperty("solr.solr.home", home.getAbsolutePath());
+
+ @BeforeClass
+ public static void baseBeforeClass() {
+ System.setProperty(DataImportHandler.ENABLE_DIH_DATA_CONFIG_PARAM, "true");
}
protected String loadDataConfig(String dataConfigFileName) {
diff --git a/solr/core/src/java/org/apache/solr/core/PluginBag.java b/solr/core/src/java/org/apache/solr/core/PluginBag.java
index 977a7e65e59..6088f5270b2 100644
--- a/solr/core/src/java/org/apache/solr/core/PluginBag.java
+++ b/solr/core/src/java/org/apache/solr/core/PluginBag.java
@@ -519,7 +519,7 @@ public class PluginBag<T> implements AutoCloseable {
}
public static boolean isEnabled() {
- return "true".equals(System.getProperty("enable.runtime.lib"));
+ return Boolean.getBoolean("enable.runtime.lib");
}
public String getName() {
diff --git a/solr/solr-ref-guide/src/uploading-structured-data-store-data-with-the-data-import-handler.adoc b/solr/solr-ref-guide/src/uploading-structured-data-store-data-with-the-data-import-handler.adoc
index 37c949a0f9e..b859d9573ca 100644
--- a/solr/solr-ref-guide/src/uploading-structured-data-store-data-with-the-data-import-handler.adoc
+++ b/solr/solr-ref-guide/src/uploading-structured-data-store-data-with-the-data-import-handler.adoc
@@ -116,7 +116,7 @@ This example shows how to extract fields from four tables defining a simple prod
Datasources can still be specified in `solrconfig.xml`. These must be specified in the defaults section of the handler in `solrconfig.xml`. However, these are not parsed until the main configuration is loaded.
-The entire configuration itself can be passed as a request parameter using the `dataConfig` parameter rather than using a file. When configuration errors are encountered, the error message is returned in XML format.
+The entire configuration itself can be passed as a request parameter using the `dataConfig` parameter rather than using a file. When configuration errors are encountered, the error message is returned in XML format. Due to security concerns, this only works if you start Solr with `-Denable.dih.dataConfigParam=true`.
A `reload-config` command is also supported, which is useful for validating a new configuration file, or if you want to specify a file, load it, and not have it reloaded again on import. If there is an `xml` mistake in the configuration a user-friendly message is returned in `xml` format. You can then fix the problem and do a `reload-config`.