Skip to content

Commit 54e9eda

Browse files
authored
SOLR-17864: Migrate System Properties to modern equivalents. (#3500)
* Migrate authentication.plugin and basicauth to modern equivalents. * Be more generic in what we filter. Do not show credentials. * Batch more of conversions. Removed deprecated solr.redaction.system.pattern. * Migrate to EnvUtils
1 parent 0ebe0a1 commit 54e9eda

File tree

16 files changed

+43
-38
lines changed

16 files changed

+43
-38
lines changed

solr/bin/solr.in.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ REM Settings for authentication
175175
REM Please configure only one of SOLR_AUTHENTICATION_CLIENT_BUILDER or SOLR_AUTH_TYPE parameters
176176
REM set SOLR_AUTHENTICATION_CLIENT_BUILDER=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory
177177
REM set SOLR_AUTH_TYPE=basic
178-
REM set SOLR_AUTHENTICATION_OPTS=-Dbasicauth=solr:SolrRocks
178+
REM set SOLR_AUTHENTICATION_OPTS=-Dsolr.security.auth.basicauth.credentials=solr:SolrRocks
179179

180180
REM Settings for ZK ACL
181181
REM set SOLR_ZK_CREDS_AND_ACLS=-DzkACLProvider=org.apache.solr.common.cloud.DigestZkACLProvider ^

solr/bin/solr.in.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
# Please configure only one of SOLR_AUTHENTICATION_CLIENT_BUILDER or SOLR_AUTH_TYPE parameters
192192
#SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory"
193193
#SOLR_AUTH_TYPE="basic"
194-
#SOLR_AUTHENTICATION_OPTS="-Dbasicauth=solr:SolrRocks"
194+
#SOLR_AUTHENTICATION_OPTS="-Dsolr.security.auth.basicauth.credentials=solr:SolrRocks"
195195

196196
# Settings for ZK ACL
197197
#SOLR_ZK_CREDS_AND_ACLS="-DzkACLProvider=org.apache.solr.common.cloud.DigestZkACLProvider \

solr/core/src/java/org/apache/solr/cli/AuthTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ private void printAuthEnablingInstructions(String username, String password) {
343343
"\nAdd the following lines to the solr.in.cmd file so that the solr.cmd script can use subsequently.\n");
344344
CLIO.out(
345345
"set SOLR_AUTH_TYPE=basic\n"
346-
+ "set SOLR_AUTHENTICATION_OPTS=\"-Dbasicauth="
346+
+ "set SOLR_AUTHENTICATION_OPTS=\"-Dsolr.security.auth.basicauth.credentials="
347347
+ username
348348
+ ":"
349349
+ password
@@ -353,7 +353,7 @@ private void printAuthEnablingInstructions(String username, String password) {
353353
"\nAdd the following lines to the solr.in.sh file so that the ./solr script can use subsequently.\n");
354354
CLIO.out(
355355
"SOLR_AUTH_TYPE=\"basic\"\n"
356-
+ "SOLR_AUTHENTICATION_OPTS=\"-Dbasicauth="
356+
+ "SOLR_AUTHENTICATION_OPTS=\"-Dsolr.security.auth.basicauth.credentials="
357357
+ username
358358
+ ":"
359359
+ password

solr/core/src/java/org/apache/solr/core/NodeConfig.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.solr.common.SolrException;
4141
import org.apache.solr.common.SolrException.ErrorCode;
4242
import org.apache.solr.common.cloud.SolrZkClient;
43+
import org.apache.solr.common.util.EnvUtils;
4344
import org.apache.solr.common.util.StrUtils;
4445
import org.apache.solr.logging.LogWatcherConfig;
4546
import org.apache.solr.search.CacheConfig;
@@ -495,7 +496,7 @@ public boolean isSysPropHidden(String sysPropName) {
495496

496497
public static final String REDACTED_SYS_PROP_VALUE = "--REDACTED--";
497498

498-
/** Returns the a system property value, or "--REDACTED--" if the system property is hidden */
499+
/** Returns the system property value, or "--REDACTED--" if the system property is hidden */
499500
public String getRedactedSysPropValue(String sysPropName) {
500501
return hiddenSysPropPattern.test(sysPropName)
501502
? REDACTED_SYS_PROP_VALUE
@@ -619,7 +620,7 @@ public static class NodeConfigBuilder {
619620
private Set<Path> allowPaths = Collections.emptySet();
620621
private List<String> allowUrls = Collections.emptyList();
621622
private boolean hideStackTrace =
622-
!(Boolean.parseBoolean(System.getProperty("solr.responses.stacktrace.enabled", "true")));
623+
!EnvUtils.getPropertyAsBool("solr.responses.stacktrace.enabled", true);
623624

624625
private final Path solrHome;
625626
private final String nodeName;
@@ -648,7 +649,7 @@ public static class NodeConfigBuilder {
648649
Set.of(
649650
"javax\\.net\\.ssl\\.keyStorePassword",
650651
"javax\\.net\\.ssl\\.trustStorePassword",
651-
"basicauth",
652+
".*credentials",
652653
"zkDigestPassword",
653654
"zkDigestReadonlyPassword",
654655
"aws\\.secretKey", // AWS SDK v1
@@ -862,25 +863,17 @@ public NodeConfigBuilder setHiddenSysProps(String hiddenSysProps) {
862863
}
863864

864865
/**
865-
* Finds list of hiddenSysProps requested by system property or environment variable or the
866-
* default
866+
* Finds list of hiddenSysProps requested in priority of solr.xml, system properties or the
867+
* default set
867868
*
868-
* @return set of raw hidden sysProps, may be regex
869+
* @return set of raw hidden system properties, may be regex
869870
*/
870-
private Set<String> resolveHiddenSysPropsFromSysPropOrEnvOrDefault(String hiddenSysProps) {
871-
// Fall back to sysprop and env.var if nothing configured through solr.xml
871+
private Set<String> resolveHiddenSysProps(String hiddenSysProps) {
872+
// Fall back to system properties if nothing configured through solr.xml
872873
if (!StrUtils.isNotNullOrEmpty(hiddenSysProps)) {
873-
String fromProps = System.getProperty("solr.hiddenSysProps");
874-
// Back-compat for solr 9x
875-
// DEPRECATED: Remove in 10.0
876-
if (StrUtils.isNotNullOrEmpty(fromProps)) {
877-
fromProps = System.getProperty("solr.redaction.system.pattern");
878-
}
879-
String fromEnv = System.getenv("SOLR_HIDDEN_SYS_PROPS");
874+
String fromProps = EnvUtils.getProperty("solr.responses.hidden.sys.props");
880875
if (StrUtils.isNotNullOrEmpty(fromProps)) {
881876
hiddenSysProps = fromProps;
882-
} else if (StrUtils.isNotNullOrEmpty(fromEnv)) {
883-
hiddenSysProps = fromEnv;
884877
}
885878
}
886879
Set<String> hiddenSysPropSet = Collections.emptySet();
@@ -939,7 +932,7 @@ public NodeConfig build() {
939932
hideStackTrace,
940933
configSetServiceClass,
941934
modules,
942-
resolveHiddenSysPropsFromSysPropOrEnvOrDefault(hiddenSysProps));
935+
resolveHiddenSysProps(hiddenSysProps));
943936
}
944937

945938
public NodeConfigBuilder setSolrResourceLoader(SolrResourceLoader resourceLoader) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
public abstract class AuthenticationPlugin implements SolrInfoBean {
4040

41-
public static final String AUTHENTICATION_PLUGIN_PROP = "authenticationPlugin";
41+
public static final String AUTHENTICATION_PLUGIN_PROP = "solr.security.auth.plugin";
4242
public static final String HTTP_HEADER_X_SOLR_AUTHDATA = "X-Solr-AuthData";
4343

4444
// Metrics

solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void setupCluster() throws Exception {
5050
System.setProperty(
5151
HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
5252
"org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory");
53-
System.setProperty("basicauth", SecurityJson.USER_PASS);
53+
System.setProperty("solr.security.auth.basicauth.credentials", SecurityJson.USER_PASS);
5454
}
5555

5656
cluster =

solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void setUp() throws Exception {
5858

5959
private void setupAuthenticationPlugin() {
6060
System.setProperty(
61-
"authenticationPlugin",
61+
"solr.security.auth.plugin",
6262
"org.apache.solr.cloud.TestAuthenticationFramework$MockAuthenticationPlugin");
6363
MockAuthenticationPlugin.expectedUsername = null;
6464
MockAuthenticationPlugin.expectedPassword = null;
@@ -85,7 +85,7 @@ public void testBasics() throws Exception {
8585

8686
@Override
8787
public void tearDown() throws Exception {
88-
System.clearProperty("authenticationPlugin");
88+
System.clearProperty("solr.security.auth.plugin");
8989
shutdownCluster();
9090
super.tearDown();
9191
}

solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private String suggestedCollectionName() {
8989

9090
@BeforeClass
9191
public static void createTestCluster() throws Exception {
92-
System.setProperty("cloudSolrClientMaxStaleRetries", "1");
92+
System.setProperty("solr.solrj.cloud.max.stale.retries", "1");
9393
System.setProperty("zkReaderGetLeaderRetryTimeoutMs", "1000");
9494

9595
configureCluster(2) // 2 + random().nextInt(3)
@@ -99,7 +99,7 @@ public static void createTestCluster() throws Exception {
9999

100100
@AfterClass
101101
public static void tearDownCluster() {
102-
System.clearProperty("cloudSolrClientMaxStaleRetries");
102+
System.clearProperty("solr.solrj.cloud.max.stale.retries");
103103
System.clearProperty("zkReaderGetLeaderRetryTimeoutMs");
104104
TestInjection.reset();
105105
}

solr/core/src/test/org/apache/solr/handler/admin/PropertiesRequestHandlerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public static void beforeClass() throws Exception {
3939
public void testRedaction() throws Exception {
4040
for (String propName :
4141
new String[] {
42-
"some.password", "javax.net.ssl.trustStorePassword", "basicauth", "some.Secret"
42+
"some.password",
43+
"javax.net.ssl.trustStorePassword",
44+
"solr.security.auth.basicauth.credentials",
45+
"some.Secret"
4346
}) {
4447
System.setProperty(propName, PASSWORD);
4548
NamedList<Object> properties = readProperties();

solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public void testAltBufferPoolMetricSet() {
8585

8686
@Test
8787
public void testSystemProperties() {
88-
if (System.getProperty("basicauth") == null) {
88+
if (System.getProperty("solr.security.auth.basicauth.credentials") == null) {
8989
// make sure it's set
90-
System.setProperty("basicauth", "foo:bar");
90+
System.setProperty("solr.security.auth.basicauth.credentials", "foo:bar");
9191
}
9292
SolrMetricManager metricManager = getJetty().getCoreContainer().getMetricManager();
9393
Map<String, Metric> metrics = metricManager.registry("solr.jvm").getMetrics();
@@ -101,6 +101,9 @@ public void testSystemProperties() {
101101
(k, v) -> {
102102
if (NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS.contains(k)) {
103103
assertNull("hidden property " + k + " present!", values.get(k));
104+
} else if (k == "solr.security.auth.basicauth.credentials") {
105+
// DEFAULT_HIDDEN_SYS_PROPS.contains doesn't match a partial pattern.
106+
assertNull("hidden property " + k + " present!", values.get(k));
104107
} else {
105108
assertEquals(v, values.get(String.valueOf(k)));
106109
}

0 commit comments

Comments
 (0)