epugh commented on code in PR #5107:
URL: https://github.com/apache/solr/pull/5107#discussion_r4444352836
##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -602,19 +632,343 @@ void initDirs(
+ " is not a directory!");
}
+ private static String[] withCredentials(String[] args, String credentials) {
+ if (credentials == null) return args;
+ List<String> result = new ArrayList<>(Arrays.asList(args));
+ result.add("--credentials");
+ result.add(credentials);
+ return result.toArray(String[]::new);
+ }
+
+ @SuppressWarnings("unchecked")
+ void runSecureExample(StartSolrParams start, int port, boolean noPrompt,
String scriptInputs)
+ throws Exception {
+ for (String file : List.of("solr.xml", "zoo.cfg")) {
+ Path target = solrHomeDir.resolve(file);
+ if (!Files.exists(target))
Files.copy(serverDir.resolve("solr").resolve(file), target);
+ }
+ echo("Welcome to the secure SolrCloud example!");
+ echo(
+ "This example uses demonstration credentials. Change them before using
it outside your local environment.");
+ usingScriptInputs = scriptInputs != null;
+ Scanner input =
+ new Scanner(
+ usingScriptInputs
+ ? new
ByteArrayInputStream(scriptInputs.getBytes(StandardCharsets.UTF_8))
+ : userInput,
+ StandardCharsets.UTF_8);
+ if (usingScriptInputs) input.useDelimiter(",");
+ secureExampleInput = input;
+ secureExampleNoPrompt = noPrompt;
+ secureHttpsVerificationShown = false;
+ Map<String, Object> httpsNodeStatus = null;
+ SecureExampleCredentials accounts = new
SecureExampleCredentials(solrHomeDir);
+ boolean existingAccounts = accounts.exists();
+ if (start.credentials() != null)
accounts.setAdministrator(start.credentials());
+ secureSSL = new SecureExampleSSL(solrHomeDir, runtime);
+ boolean existingHttps = secureSSL.isConfigured();
+ if (!existingHttps) configureSecureExampleSSL(input, start, noPrompt);
+ else echo("Reusing the example's HTTPS configuration.");
+ SecureExampleZk secureZk = new SecureExampleZk(solrHomeDir);
+ boolean changePasswords = false;
+ if (!existingAccounts || !secureZk.isConfigured()) {
+ echo("The solr, index, search, zk-admin, and zk-readonly accounts use
SolrRocks by default.");
+ String choice = noPrompt ? "n" : prompt(input, "Change account
passwords? [y/N]: ", "n");
+ while (!Set.of("y", "n").contains(choice.toLowerCase(Locale.ROOT))) {
+ choice = prompt(input, "Enter y to change passwords or n to use the
defaults [y/N]: ", "n");
+ }
+ changePasswords = choice.equalsIgnoreCase("y");
+ }
+ if (!existingAccounts && changePasswords) {
+ for (String account : List.of("admin", "index", "search")) {
+ String username = "admin".equals(account) ? accounts.adminUsername() :
account;
+ accounts.setPassword(
+ account,
+ promptPassword(input, "Password for " + username + " [SolrRocks]:
", username));
+ }
+ }
+ if (secureZk.isConfigured()) {
+ echo("Reusing the example's ZooKeeper credentials and ACL
configuration.");
+ } else {
+ echo("Protecting ZooKeeper with separate digest accounts and ACLs.");
+ String zkAdminPassword =
+ changePasswords
+ ? promptPassword(input, "Password for zk-admin [SolrRocks]: ",
"zk-admin")
+ : "SolrRocks";
+ String zkReadonlyPassword =
+ changePasswords
+ ? promptPassword(input, "Password for zk-readonly [SolrRocks]:
", "zk-readonly")
+ : "SolrRocks";
+ secureZk.create(zkAdminPassword, zkReadonlyPassword);
Review Comment:
i wonder if this should be it's won `bin/solr auth` tool? or `bin/solr zk
auth` tool call? Probably `bin/solr auth`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]