Skip to content

Commit 709fa32

Browse files
authored
SOLR-17864: Migrating system properties to modern name. (#3690)
* Migrating to solr.security.allow.urls.enabled from solr.disable.allowUrls. Removes old whitelist terminology. * Remove old deprecated language checks. * Bring ClusteringComponentDistributedTest into line to how other tests set the allow list variable
1 parent cb6dd31 commit 709fa32

19 files changed

+50
-55
lines changed

solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.apache.solr.metrics.SolrMetricProducer;
5959
import org.apache.solr.metrics.SolrMetricsContext;
6060
import org.apache.solr.request.SolrQueryRequest;
61-
import org.apache.solr.security.AllowListUrlChecker;
6261
import org.apache.solr.security.HttpClientBuilderPlugin;
6362
import org.apache.solr.update.UpdateShardHandlerConfig;
6463
import org.apache.solr.util.stats.InstrumentedHttpListenerFactory;
@@ -261,12 +260,6 @@ public void init(PluginInfo info) {
261260
sb);
262261
this.accessPolicy = getParameter(args, INIT_FAIRNESS_POLICY, accessPolicy, sb);
263262

264-
if (args != null && args.get("shardsWhitelist") != null) {
265-
log.warn(
266-
"Property 'shardsWhitelist' is deprecated, please use '{}' instead.",
267-
AllowListUrlChecker.URL_ALLOW_LIST);
268-
}
269-
270263
// magic sysprop to make tests reproducible: set by SolrTestCaseJ4.
271264
String v = System.getProperty("tests.shardhandler.randomSeed");
272265
if (v != null) {

solr/core/src/java/org/apache/solr/security/AllowListUrlChecker.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,25 @@
3030
import java.util.stream.Collectors;
3131
import org.apache.solr.common.SolrException;
3232
import org.apache.solr.common.cloud.ClusterState;
33+
import org.apache.solr.common.util.EnvUtils;
3334
import org.apache.solr.core.NodeConfig;
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
3637

37-
/** Validates URLs based on an allow list or a {@link ClusterState} in SolrCloud. */
38+
/** Validates URLs using an allow-list or a {@link ClusterState} in SolrCloud. */
3839
public class AllowListUrlChecker {
3940

4041
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
4142

4243
/** {@link org.apache.solr.core.SolrXmlConfig} property to configure the allowed URLs. */
4344
public static final String URL_ALLOW_LIST = "allowUrls";
4445

45-
/** System property to disable URL checking and {@link #ALLOW_ALL} instead. */
46-
public static final String DISABLE_URL_ALLOW_LIST = "solr.disable." + URL_ALLOW_LIST;
46+
/** System property to enable URL checking against an allow-list and ignore {@link #ALLOW_ALL}. */
47+
public static final String ENABLE_URL_ALLOW_LIST = "solr.security.allow.urls.enabled";
4748

4849
/** Clue given in URL-forbidden exceptions messages. */
4950
public static final String SET_SOLR_DISABLE_URL_ALLOW_LIST_CLUE =
50-
"Set -D" + DISABLE_URL_ALLOW_LIST + "=true to disable URL allow-list checks.";
51+
"Set -D" + ENABLE_URL_ALLOW_LIST + "=false to disable URL allow-list checks.";
5152

5253
/** Singleton checker which allows all URLs. {@link #isEnabled()} returns false. */
5354
public static final AllowListUrlChecker ALLOW_ALL;
@@ -83,7 +84,9 @@ public String toString() {
8384
*/
8485
private static final Pattern PROTOCOL_PATTERN = Pattern.compile("(\\w+)(://.*)");
8586

86-
/** Allow list of hosts. Elements in the list will be host:port (no protocol or context). */
87+
/**
88+
* Allow list of hosts. Elements in the list are formatted as host:port (no protocol or context).
89+
*/
8790
private final Set<String> hostAllowList;
8891

8992
private volatile Set<String> liveHostUrlsCache;
@@ -94,7 +97,7 @@ public String toString() {
9497
* tolerated. An empty list means there is no explicit allow-list of URLs, in this case no URL
9598
* is allowed unless a {@link ClusterState} is provided in {@link #checkAllowList(List,
9699
* ClusterState)}.
97-
* @throws MalformedURLException If an URL is invalid.
100+
* @throws MalformedURLException If a URL is invalid.
98101
*/
99102
public AllowListUrlChecker(List<String> urlAllowList) throws MalformedURLException {
100103
hostAllowList = parseHostPorts(urlAllowList);
@@ -104,12 +107,8 @@ public AllowListUrlChecker(List<String> urlAllowList) throws MalformedURLExcepti
104107
* Creates a URL checker based on the {@link NodeConfig} property to configure the allowed URLs.
105108
*/
106109
public static AllowListUrlChecker create(NodeConfig config) {
107-
if (Boolean.getBoolean(DISABLE_URL_ALLOW_LIST)) {
110+
if (!EnvUtils.getPropertyAsBool(ENABLE_URL_ALLOW_LIST, true)) {
108111
return AllowListUrlChecker.ALLOW_ALL;
109-
} else if (System.getProperty("solr.disable.shardsWhitelist") != null) {
110-
log.warn(
111-
"Property 'solr.disable.shardsWhitelist' is deprecated, please use '{}' instead.",
112-
DISABLE_URL_ALLOW_LIST);
113112
}
114113
try {
115114
return new AllowListUrlChecker(config.getAllowUrls());
@@ -134,8 +133,8 @@ public void checkAllowList(List<String> urls) throws MalformedURLException {
134133
*
135134
* @param urls The list of urls to check.
136135
* @param clusterState The up to date {@link ClusterState}, can be null in case of non-cloud mode.
137-
* @throws MalformedURLException If an URL is invalid.
138-
* @throws SolrException If an URL is not present in the allow-list or in the provided {@link
136+
* @throws MalformedURLException If a URL is invalid.
137+
* @throws SolrException If a URL is not present in the allow-list or in the provided {@link
139138
* ClusterState}.
140139
*/
141140
public void checkAllowList(List<String> urls, ClusterState clusterState)

solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.solr.common.SolrInputDocument;
2828
import org.apache.solr.common.params.ShardParams;
2929
import org.apache.solr.common.util.NamedList;
30-
import org.apache.solr.security.AllowListUrlChecker;
3130
import org.apache.solr.util.SolrJettyTestRule;
3231
import org.apache.solr.util.ThreadCpuTimer;
3332
import org.junit.BeforeClass;
@@ -45,7 +44,6 @@ public class TestCpuTimeSearch extends SolrTestCaseJ4 {
4544
@BeforeClass
4645
public static void setupSolr() throws Exception {
4746
System.setProperty(ThreadCpuTimer.ENABLE_CPU_TIME, "true");
48-
System.setProperty(AllowListUrlChecker.DISABLE_URL_ALLOW_LIST, "true");
4947

5048
Path configSet = createTempDir("configSet");
5149
copyMinConf(configSet);

solr/core/src/test/org/apache/solr/TestTolerantSearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static Path createSolrHome() throws Exception {
5858

5959
@BeforeClass
6060
public static void createThings() throws Exception {
61-
systemSetPropertySolrDisableUrlAllowList("true");
61+
systemSetPropertyEnableUrlAllowList(false);
6262
Path solrHome = createSolrHome();
6363
createAndStartJetty(solrHome);
6464
String url = getBaseUrl();
@@ -109,7 +109,7 @@ public static void destroyThings() throws Exception {
109109
collection2 = null;
110110
}
111111
resetExceptionIgnores();
112-
systemClearPropertySolrDisableUrlAllowList();
112+
systemClearPropertySolrEnableUrlAllowList();
113113
}
114114

115115
@SuppressWarnings("unchecked")

solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class TestHealthCheckHandlerLegacyMode extends SolrTestCaseJ4 {
5151
public void setUp() throws Exception {
5252
super.setUp();
5353

54-
systemSetPropertySolrDisableUrlAllowList("true");
54+
systemSetPropertyEnableUrlAllowList(false);
5555

5656
leader = new ReplicationTestHelper.SolrInstance(createTempDir("solr-instance"), "leader", null);
5757
leader.setUp();

solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
107107
@Before
108108
public void setUp() throws Exception {
109109
super.setUp();
110-
systemSetPropertySolrDisableUrlAllowList("true");
110+
systemSetPropertyEnableUrlAllowList(false);
111111
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
112112
// For manual testing only
113113
// useFactory(null); // force an FS factory.
@@ -140,7 +140,7 @@ public void clearIndexWithReplication() throws Exception {
140140
@After
141141
public void tearDown() throws Exception {
142142
super.tearDown();
143-
systemClearPropertySolrDisableUrlAllowList();
143+
systemClearPropertySolrEnableUrlAllowList();
144144
if (null != leaderJetty) {
145145
leaderJetty.stop();
146146
leaderJetty = null;
@@ -255,7 +255,7 @@ public void doTestHandlerPathUnchanged() {
255255
public void testUrlAllowList() throws Exception {
256256
// Run another test with URL allow-list enabled and allow-list is empty.
257257
// Expect an exception because the leader URL is not allowed.
258-
systemClearPropertySolrDisableUrlAllowList();
258+
systemClearPropertySolrEnableUrlAllowList();
259259
SolrException e = expectThrows(SolrException.class, this::doTestDetails);
260260
assertTrue(
261261
e.getMessage()

solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class TestUserManagedReplicationWithAuth extends SolrTestCaseJ4 {
7474
@Before
7575
public void setUp() throws Exception {
7676
super.setUp();
77-
systemSetPropertySolrDisableUrlAllowList("true");
77+
systemSetPropertyEnableUrlAllowList(false);
7878
// leader with Basic auth enabled via security.json
7979
leader = new ReplicationTestHelper.SolrInstance(createTempDir("solr-instance"), "leader", null);
8080
leader.setUp();

solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static Path createSolrHome() throws Exception {
5858

5959
@BeforeClass
6060
public static void createThings() throws Exception {
61-
systemSetPropertySolrDisableUrlAllowList("true");
61+
systemSetPropertyEnableUrlAllowList(false);
6262
Path solrHome = createSolrHome();
6363
createAndStartJetty(solrHome);
6464
String url = getBaseUrl();
@@ -102,7 +102,7 @@ public static void destroyThings() throws Exception {
102102
collection2 = null;
103103
}
104104
resetExceptionIgnores();
105-
systemClearPropertySolrDisableUrlAllowList();
105+
systemClearPropertySolrEnableUrlAllowList();
106106
}
107107

108108
@Test

solr/core/src/test/org/apache/solr/search/TestSmileRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class TestSmileRequest extends SolrTestCaseJ4 {
4242

4343
@BeforeClass
4444
public static void beforeTests() throws Exception {
45-
systemSetPropertySolrDisableUrlAllowList("true");
45+
systemSetPropertyEnableUrlAllowList(false);
4646
System.setProperty("solr.requests.streaming.body.enabled", "true");
4747
JSONTestUtil.failRepeatedKeys = true;
4848
initCore("solrconfig-tlog.xml", "schema_latest.xml");
@@ -61,7 +61,7 @@ public static void afterTests() throws Exception {
6161
servers.stop();
6262
servers = null;
6363
}
64-
systemClearPropertySolrDisableUrlAllowList();
64+
systemClearPropertySolrEnableUrlAllowList();
6565
}
6666

6767
@Test

solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class TestJsonFacetErrors extends SolrTestCaseHS {
3434
@SuppressWarnings("deprecation")
3535
@BeforeClass
3636
public static void beforeTests() throws Exception {
37-
systemSetPropertySolrDisableUrlAllowList("true");
37+
systemSetPropertyEnableUrlAllowList(false);
3838
JSONTestUtil.failRepeatedKeys = true;
3939

4040
// we need DVs on point fields to compute stats & facets
@@ -54,7 +54,7 @@ public static void initServers() throws Exception {
5454
@SuppressWarnings("deprecation")
5555
@AfterClass
5656
public static void afterTests() throws Exception {
57-
systemClearPropertySolrDisableUrlAllowList();
57+
systemClearPropertySolrEnableUrlAllowList();
5858
JSONTestUtil.failRepeatedKeys = false;
5959
if (servers != null) {
6060
servers.stop();

0 commit comments

Comments
 (0)