Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds missing default security config lines when updating opensearch.yml #3734

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.security.tools.democonfig;

/**
* Enum for demo certificates
*/
public enum Certificates {
ADMIN_CERT(

Check warning on line 18 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L17-L18

Added lines #L17 - L18 were not covered by tests
"kirk.pem",
"-----BEGIN CERTIFICATE-----\n"
+ "MIIEmDCCA4CgAwIBAgIUZjrlDPP8azRDPZchA/XEsx0X2iYwDQYJKoZIhvcNAQEL\n"
Expand Down Expand Up @@ -34,7 +45,7 @@
+ "RGr6JbdHXc96zsLTL3saJQ8AWEfu1gbTVrwyRA==\n"
+ "-----END CERTIFICATE-----"
),
ADMIN_CERT_KEY(

Check warning on line 48 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L48

Added line #L48 was not covered by tests
"kirk-key.pem",
"-----BEGIN PRIVATE KEY-----\n"
+ "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCVXDgEJQorgfXp\n"
Expand Down Expand Up @@ -65,7 +76,7 @@
+ "/AHmo368d4PSNRMMzLHw8Q==\n"
+ "-----END PRIVATE KEY-----"
),
NODE_CERT(

Check warning on line 79 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L79

Added line #L79 was not covered by tests
"esnode.pem",
"-----BEGIN CERTIFICATE-----\n"
+ "MIIEPDCCAySgAwIBAgIUZjrlDPP8azRDPZchA/XEsx0X2iIwDQYJKoZIhvcNAQEL\n"
Expand Down Expand Up @@ -93,7 +104,7 @@
+ "zYkEOUF8Y25J6WeY88Yfnc0iigI+Pnz5NK8R9GL7TYo=\n"
+ "-----END CERTIFICATE-----"
),
NODE_KEY(

Check warning on line 107 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L107

Added line #L107 was not covered by tests
"esnode-key.pem",
"-----BEGIN PRIVATE KEY-----\n"
+ "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCm93kXteDQHMAv\n"
Expand Down Expand Up @@ -124,7 +135,7 @@
+ "bg/ch9Rhxbq22yrVgWHh6epp\n"
+ "-----END PRIVATE KEY-----"
),
ROOT_CA(

Check warning on line 138 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L138

Added line #L138 was not covered by tests
"root-ca.pem",
"-----BEGIN CERTIFICATE-----\n"
+ "MIIExjCCA66gAwIBAgIUd+SvPvzan5P2TQbEZ4zj4Gt6FYowDQYJKoZIhvcNAQEL\n"
Expand Down Expand Up @@ -159,16 +170,16 @@
private final String fileName;
private final String content;

Certificates(String fileName, String content) {
this.fileName = fileName;
this.content = content;
}

Check warning on line 176 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L173-L176

Added lines #L173 - L176 were not covered by tests

public String getFileName() {
return fileName;

Check warning on line 179 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L179

Added line #L179 was not covered by tests
}

public String getContent() {
return content;

Check warning on line 183 in src/main/java/org/opensearch/security/tools/democonfig/Certificates.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/Certificates.java#L183

Added line #L183 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.security.tools.democonfig;

/**
* The environment in which the demo config installation script is being executed
*/
public enum ExecutionEnvironment {
DEMO, // default value
TEST // to be used only for tests

Check warning on line 19 in src/main/java/org/opensearch/security/tools/democonfig/ExecutionEnvironment.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/ExecutionEnvironment.java#L17-L19

Added lines #L17 - L19 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* This class updates the security related configuration, as needed.
*/
public class SecuritySettingsConfigurer extends Installer {

Check warning on line 37 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L37

Added line #L37 was not covered by tests

/**
* Configures security related changes to the opensearch configuration
Expand All @@ -43,40 +43,40 @@
* 3. Write the security config to opensearch.yml
*/
public void configureSecuritySettings() {
checkIfSecurityPluginIsAlreadyConfigured();
updateAdminPassword();
writeSecurityConfigToOpenSearchYML();
}

Check warning on line 49 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L46-L49

Added lines #L46 - L49 were not covered by tests

/**
* Replaces the admin password in internal_users.yml with the custom or generated password
*/
static void updateAdminPassword() {
String ADMIN_PASSWORD = "";
String initialAdminPassword = System.getenv("initialAdminPassword");
String ADMIN_PASSWORD_FILE_PATH = OPENSEARCH_CONF_DIR + "initialAdminPassword.txt";
String INTERNAL_USERS_FILE_PATH = OPENSEARCH_CONF_DIR + "opensearch-security" + File.separator + "internal_users.yml";
boolean shouldValidatePassword = environment.equals(ExecutionEnvironment.DEMO);

Check warning on line 59 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L55-L59

Added lines #L55 - L59 were not covered by tests
try {
final PasswordValidator passwordValidator = PasswordValidator.of(
Settings.builder()
.put(SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX, "(?=.*[A-Z])(?=.*[^a-zA-Z\\\\d])(?=.*[0-9])(?=.*[a-z]).{8,}")
.put(SECURITY_RESTAPI_PASSWORD_MIN_LENGTH, 8)
.build()

Check warning on line 65 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L61-L65

Added lines #L61 - L65 were not covered by tests
);

// Read custom password
if (initialAdminPassword != null && !initialAdminPassword.isEmpty()) {
ADMIN_PASSWORD = initialAdminPassword;

Check warning on line 70 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L70

Added line #L70 was not covered by tests
} else {
File adminPasswordFile = new File(ADMIN_PASSWORD_FILE_PATH);

Check warning on line 72 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L72

Added line #L72 was not covered by tests
if (adminPasswordFile.exists() && adminPasswordFile.length() > 0) {
try (BufferedReader br = new BufferedReader(new FileReader(ADMIN_PASSWORD_FILE_PATH, StandardCharsets.UTF_8))) {
ADMIN_PASSWORD = br.readLine();
} catch (IOException e) {
System.out.println("Error reading admin password from initialAdminPassword.txt.");
System.exit(-1);
}

Check warning on line 79 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L74-L79

Added lines #L74 - L79 were not covered by tests
}
}

Expand All @@ -84,32 +84,32 @@
if (shouldValidatePassword
&& !ADMIN_PASSWORD.isEmpty()
&& passwordValidator.validate("admin", ADMIN_PASSWORD) != RequestContentValidator.ValidationError.NONE) {
System.out.println("Password " + ADMIN_PASSWORD + " is weak. Please re-try with a stronger password.");
System.exit(-1);

Check warning on line 88 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L87-L88

Added lines #L87 - L88 were not covered by tests
}

// if ADMIN_PASSWORD is still an empty string, it implies no custom password was provided. We proceed with generating a new one.
if (ADMIN_PASSWORD.isEmpty()) {
System.out.println("No custom admin password found. Generating a new password now.");

Check warning on line 93 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L93

Added line #L93 was not covered by tests
// generate a new random password
// We always validate a generated password
while (passwordValidator.validate("admin", ADMIN_PASSWORD) != RequestContentValidator.ValidationError.NONE) {
ADMIN_PASSWORD = generatePassword();

Check warning on line 97 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L97

Added line #L97 was not covered by tests
}
}

// print the password to the logs
System.out.println("\t***************************************************");
System.out.println("\t\tADMIN PASSWORD SET TO: " + ADMIN_PASSWORD);
System.out.println("\t***************************************************");

Check warning on line 104 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L102-L104

Added lines #L102 - L104 were not covered by tests

writePasswordToInternalUsersFile(ADMIN_PASSWORD, INTERNAL_USERS_FILE_PATH);

Check warning on line 106 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L106

Added line #L106 was not covered by tests

} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
System.exit(-1);
}
}

Check warning on line 112 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L108-L112

Added lines #L108 - L112 were not covered by tests

/**
* Generate password hash and update it in the internal_users.yml file
Expand All @@ -118,35 +118,35 @@
* @throws IOException while reading, writing to files
*/
static void writePasswordToInternalUsersFile(String adminPassword, String internalUsersFile) throws IOException {
String hashedAdminPassword = Hasher.hash(adminPassword.toCharArray());

Check warning on line 121 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L121

Added line #L121 was not covered by tests

if (hashedAdminPassword.isEmpty()) {
System.out.println("Hash the admin password failure, see console for details");
System.exit(-1);

Check warning on line 125 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L124-L125

Added lines #L124 - L125 were not covered by tests
}

Path tempFilePath = Paths.get(internalUsersFile + ".tmp");
Path internalUsersPath = Paths.get(internalUsersFile);

Check warning on line 129 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L128-L129

Added lines #L128 - L129 were not covered by tests

try (
BufferedReader reader = new BufferedReader(new FileReader(internalUsersFile, StandardCharsets.UTF_8));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFilePath.toFile(), StandardCharsets.UTF_8))

Check warning on line 133 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L132-L133

Added lines #L132 - L133 were not covered by tests
) {
String line;
while ((line = reader.readLine()) != null) {
if (line.matches(" *hash: *\"\\$2a\\$12\\$VcCDgh2NDk07JGN0rjGbM.Ad41qVR/YFJcgHp0UGns5JDymv..TOG\"")) {
line = line.replace(

Check warning on line 138 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L138

Added line #L138 was not covered by tests
"\"$2a$12$VcCDgh2NDk07JGN0rjGbM.Ad41qVR/YFJcgHp0UGns5JDymv..TOG\"",
"\"" + hashedAdminPassword + "\""
);
}
writer.write(line + System.lineSeparator());

Check warning on line 143 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L143

Added line #L143 was not covered by tests
}
} catch (IOException e) {
throw new IOException("Unable to update the internal users file with the hashed password.");
}
Files.move(tempFilePath, internalUsersPath, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}

Check warning on line 149 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L145-L149

Added lines #L145 - L149 were not covered by tests

/**
* Checks if security plugin is already configured. If so, the script execution will not continue.
Expand All @@ -154,83 +154,87 @@
static void checkIfSecurityPluginIsAlreadyConfigured() {
// Check if the configuration file contains the 'plugins.security' string
if (OPENSEARCH_CONF_FILE != null && new File(OPENSEARCH_CONF_FILE).exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8))) {

Check warning on line 157 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L157

Added line #L157 was not covered by tests
String line;
while ((line = br.readLine()) != null) {
if (line.toLowerCase().contains("plugins.security")) {
System.out.println(OPENSEARCH_CONF_FILE + " seems to be already configured for Security. Quit.");
System.exit(skip_updates);

Check warning on line 162 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L161-L162

Added lines #L161 - L162 were not covered by tests
}
}
} catch (IOException e) {
System.err.println("Error reading configuration file.");
System.exit(-1);
}

Check warning on line 168 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L165-L168

Added lines #L165 - L168 were not covered by tests
} else {
System.err.println("OpenSearch configuration file does not exist. Quit.");
System.exit(-1);

Check warning on line 171 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L170-L171

Added lines #L170 - L171 were not covered by tests
}
}

Check warning on line 173 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L173

Added line #L173 was not covered by tests

/**
* Update opensearch.yml with security configuration information
*/
static void writeSecurityConfigToOpenSearchYML() {
String securityConfig = buildSecurityConfigString();

Check warning on line 179 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L179

Added line #L179 was not covered by tests

try (FileWriter writer = new FileWriter(OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8, true)) {
writer.write(securityConfig);
} catch (IOException e) {
System.err.println("Exception writing security configuration to opensearch.yml.");
System.exit(-1);
}
}

Check warning on line 187 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L181-L187

Added lines #L181 - L187 were not covered by tests

/**
* Helper method to build security configuration to append to opensearch.yml
* @return the configuration string to be written to opensearch.yml
*/
static String buildSecurityConfigString() {
StringBuilder securityConfigLines = new StringBuilder();

Check warning on line 194 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L194

Added line #L194 was not covered by tests

securityConfigLines.append("\n")
.append("######## Start OpenSearch Security Demo Configuration ########\n")
.append("# WARNING: revise all the lines below before you go into production\n")
.append("plugins.security.ssl.transport.pemcert_filepath: esnode.pem\n")
.append("plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem\n")
.append("plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem\n")
.append("plugins.security.ssl.transport.enforce_hostname_verification: false\n")
.append("plugins.security.ssl.http.enabled: true\n")
.append("plugins.security.ssl.http.pemcert_filepath: esnode.pem\n")
.append("plugins.security.ssl.http.pemkey_filepath: esnode-key.pem\n")
.append("plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem\n")
.append("plugins.security.allow_unsafe_democertificates: true\n");

Check warning on line 207 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L196-L207

Added lines #L196 - L207 were not covered by tests

if (initsecurity) {
securityConfigLines.append("plugins.security.allow_default_init_securityindex: true\n");

Check warning on line 210 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L210

Added line #L210 was not covered by tests
}

securityConfigLines.append("plugins.security.authcz.admin_dn:\n - CN=kirk,OU=client,O=client,L=test, C=de\n\n");

Check warning on line 213 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L213

Added line #L213 was not covered by tests

securityConfigLines.append("plugins.security.system_indices.enabled: true\n" + "plugins.security.system_indices.indices: [")
.append(SYSTEM_INDICES)
.append("]\n");
securityConfigLines.append("plugins.security.audit.type: internal_opensearch\n");
securityConfigLines.append("plugins.security.enable_snapshot_restore_privilege: true\n");
securityConfigLines.append("plugins.security.check_snapshot_restore_write_privileges: true\n");
securityConfigLines.append("plugins.security.restapi.roles_enabled: [\"all_access\", \"security_rest_api_access\"]\n");

Check warning on line 218 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L215-L218

Added lines #L215 - L218 were not covered by tests

securityConfigLines.append("plugins.security.system_indices.enabled: true\n");
securityConfigLines.append("plugins.security.system_indices.indices: [").append(SYSTEM_INDICES).append("]\n");

Check warning on line 221 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L220-L221

Added lines #L220 - L221 were not covered by tests

if (!isNetworkHostAlreadyPresent(OPENSEARCH_CONF_FILE)) {
if (cluster_mode) {
securityConfigLines.append("network.host: 0.0.0.0\n");
securityConfigLines.append("node.name: smoketestnode\n");
securityConfigLines.append("cluster.initial_cluster_manager_nodes: smoketestnode\n");

Check warning on line 227 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L225-L227

Added lines #L225 - L227 were not covered by tests
}
}

if (!isNodeMaxLocalStorageNodesAlreadyPresent(OPENSEARCH_CONF_FILE)) {
securityConfigLines.append("node.max_local_storage_nodes: 3\n");

Check warning on line 232 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L232

Added line #L232 was not covered by tests
}

securityConfigLines.append("######## End OpenSearch Security Demo Configuration ########\n");

Check warning on line 235 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L235

Added line #L235 was not covered by tests

return securityConfigLines.toString();

Check warning on line 237 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L237

Added line #L237 was not covered by tests
}

/**
Expand All @@ -240,10 +244,10 @@
*/
static boolean isNetworkHostAlreadyPresent(String filePath) {
try {
String searchString = "^network.host";
return isStringAlreadyPresentInFile(filePath, searchString);
} catch (IOException e) {
return false;

Check warning on line 250 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L247-L250

Added lines #L247 - L250 were not covered by tests
}
}

Expand All @@ -254,10 +258,10 @@
*/
static boolean isNodeMaxLocalStorageNodesAlreadyPresent(String filePath) {
try {
String searchString = "^node.max_local_storage_nodes";
return isStringAlreadyPresentInFile(filePath, searchString);
} catch (IOException e) {
return false;

Check warning on line 264 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L261-L264

Added lines #L261 - L264 were not covered by tests
}
}

Expand All @@ -269,15 +273,15 @@
* @throws IOException if there was exception reading the file
*/
static boolean isStringAlreadyPresentInFile(String filePath, String searchString) throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(filePath, StandardCharsets.UTF_8))) {

Check warning on line 276 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L276

Added line #L276 was not covered by tests
String line;
while ((line = reader.readLine()) != null) {
if (line.matches(searchString)) {
return true;

Check warning on line 280 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L280

Added line #L280 was not covered by tests
}
}
}
return false;

Check warning on line 284 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L283-L284

Added lines #L283 - L284 were not covered by tests
}

/**
Expand All @@ -289,31 +293,31 @@
void createSecurityAdminDemoScript(String securityAdminScriptPath, String securityAdminDemoScriptPath) throws IOException {
String[] securityAdminCommands;

String securityAdminExecutionPath = securityAdminScriptPath

Check warning on line 296 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L296

Added line #L296 was not covered by tests
+ "\" -cd \""
+ OPENSEARCH_CONF_DIR
+ "opensearch-security\" -icl -key \""
+ OPENSEARCH_CONF_DIR
+ Certificates.ADMIN_CERT_KEY.getFileName()

Check warning on line 301 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L301

Added line #L301 was not covered by tests
+ "\" -cert \""
+ OPENSEARCH_CONF_DIR
+ Certificates.ADMIN_CERT.getFileName()

Check warning on line 304 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L304

Added line #L304 was not covered by tests
+ "\" -cacert \""
+ OPENSEARCH_CONF_DIR
+ Certificates.ROOT_CA.getFileName()

Check warning on line 307 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L307

Added line #L307 was not covered by tests
+ "\" -nhnv";

if (OS.toLowerCase().contains("win")) {
securityAdminCommands = new String[] { "@echo off", "call \"" + securityAdminExecutionPath };

Check warning on line 311 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L311

Added line #L311 was not covered by tests
} else {
securityAdminCommands = new String[] { "#!/bin/bash", "sudo" + " \"" + securityAdminExecutionPath };

Check warning on line 313 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L313

Added line #L313 was not covered by tests
}

// Write securityadmin_demo script
FileWriter writer = new FileWriter(securityAdminDemoScriptPath, StandardCharsets.UTF_8);

Check warning on line 317 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L317

Added line #L317 was not covered by tests
for (String command : securityAdminCommands) {
writer.write(command + "\n");

Check warning on line 319 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L319

Added line #L319 was not covered by tests
}
writer.close();
}

Check warning on line 322 in src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java#L321-L322

Added lines #L321 - L322 were not covered by tests
}
Loading