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

Extend set of masked fields in ConfigXmlGenerator [HZ-2289] (5.0.z) #24307

Merged
merged 1 commit into from Apr 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -187,6 +187,9 @@ public String generate(Config config) {
}

private String getOrMaskValue(String value) {
if (value == null) {
return null;
}
return maskSensitiveFields ? MASK_FOR_SENSITIVE_DATA : value;
}

Expand Down Expand Up @@ -340,7 +343,7 @@ private static void tlsAuthenticationGenerator(XmlGenerator gen, TlsAuthenticati
.close();
}

private static void ldapAuthenticationGenerator(XmlGenerator gen, LdapAuthenticationConfig c) {
private void ldapAuthenticationGenerator(XmlGenerator gen, LdapAuthenticationConfig c) {
if (c == null) {
return;
}
Expand All @@ -357,7 +360,7 @@ private static void ldapAuthenticationGenerator(XmlGenerator gen, LdapAuthentica
.nodeIfContents("role-search-scope", c.getRoleSearchScope())
.nodeIfContents("user-name-attribute", c.getUserNameAttribute())
.nodeIfContents("system-user-dn", c.getSystemUserDn())
.nodeIfContents("system-user-password", c.getSystemUserPassword())
.nodeIfContents("system-user-password", getOrMaskValue(c.getSystemUserPassword()))
.nodeIfContents("system-authentication", c.getSystemAuthentication())
.nodeIfContents("security-realm", c.getSecurityRealm())
.nodeIfContents("password-attribute", c.getPasswordAttribute())
Expand All @@ -368,7 +371,7 @@ private static void ldapAuthenticationGenerator(XmlGenerator gen, LdapAuthentica
.close();
}

private static void kerberosAuthenticationGenerator(XmlGenerator gen, KerberosAuthenticationConfig c) {
private void kerberosAuthenticationGenerator(XmlGenerator gen, KerberosAuthenticationConfig c) {
if (c == null) {
return;
}
Expand All @@ -383,14 +386,14 @@ private static void kerberosAuthenticationGenerator(XmlGenerator gen, KerberosAu
kerberosGen.close();
}

private static void simpleAuthenticationGenerator(XmlGenerator gen, SimpleAuthenticationConfig c) {
private void simpleAuthenticationGenerator(XmlGenerator gen, SimpleAuthenticationConfig c) {
if (c == null) {
return;
}
XmlGenerator simpleGen = gen.open("simple");
addClusterLoginElements(simpleGen, c).nodeIfContents("role-separator", c.getRoleSeparator());
for (String username : c.getUsernames()) {
simpleGen.open("user", "username", username, "password", c.getPassword(username));
simpleGen.open("user", "username", username, "password", getOrMaskValue(c.getPassword(username)));
for (String role : c.getRoles(username)) {
simpleGen.node("role", role);
}
Expand Down
Expand Up @@ -122,17 +122,29 @@ public void testIfSensitiveDataIsMasked_whenMaskingEnabled() {
cfg.getNetworkConfig().setSymmetricEncryptionConfig(symmetricEncryptionConfig);
cfg.setLicenseKey("HazelcastLicenseKey");

cfg.getSecurityConfig().addRealmConfig("simple",
new RealmConfig().setSimpleAuthenticationConfig(new SimpleAuthenticationConfig().addUser("test", "pass"))
.setUsernamePasswordIdentityConfig("myidentity", "mypasswd"))
.addRealmConfig("ldap", new RealmConfig().setLdapAuthenticationConfig(
new LdapAuthenticationConfig().setSystemUserDn("cn=test").setSystemUserPassword("ldappass")));

Config newConfigViaXMLGenerator = getNewConfigViaXMLGenerator(cfg);
SSLConfig generatedSSLConfig = newConfigViaXMLGenerator.getNetworkConfig().getSSLConfig();
SecurityConfig secCfg = newConfigViaXMLGenerator.getSecurityConfig();

assertEquals(generatedSSLConfig.getProperty("keyStorePassword"), MASK_FOR_SENSITIVE_DATA);
assertEquals(generatedSSLConfig.getProperty("trustStorePassword"), MASK_FOR_SENSITIVE_DATA);
assertEquals(MASK_FOR_SENSITIVE_DATA, generatedSSLConfig.getProperty("keyStorePassword"));
assertEquals(MASK_FOR_SENSITIVE_DATA, generatedSSLConfig.getProperty("trustStorePassword"));

String secPassword = newConfigViaXMLGenerator.getNetworkConfig().getSymmetricEncryptionConfig().getPassword();
String theSalt = newConfigViaXMLGenerator.getNetworkConfig().getSymmetricEncryptionConfig().getSalt();
assertEquals(secPassword, MASK_FOR_SENSITIVE_DATA);
assertEquals(theSalt, MASK_FOR_SENSITIVE_DATA);
assertEquals(newConfigViaXMLGenerator.getLicenseKey(), MASK_FOR_SENSITIVE_DATA);
assertEquals(MASK_FOR_SENSITIVE_DATA, secPassword);
assertEquals(MASK_FOR_SENSITIVE_DATA, theSalt);
assertEquals(MASK_FOR_SENSITIVE_DATA, newConfigViaXMLGenerator.getLicenseKey());
RealmConfig simpleRealm = secCfg.getRealmConfig("simple");
assertEquals(MASK_FOR_SENSITIVE_DATA, simpleRealm.getSimpleAuthenticationConfig().getPassword("test"));
assertEquals(MASK_FOR_SENSITIVE_DATA, simpleRealm.getUsernamePasswordIdentityConfig().getPassword());
assertEquals(MASK_FOR_SENSITIVE_DATA,
secCfg.getRealmConfig("ldap").getLdapAuthenticationConfig().getSystemUserPassword());
}

@Test
Expand All @@ -159,17 +171,17 @@ public void testIfSensitiveDataIsNotMasked_whenMaskingDisabled() {
Config newConfigViaXMLGenerator = getNewConfigViaXMLGenerator(cfg, false);
SSLConfig generatedSSLConfig = newConfigViaXMLGenerator.getNetworkConfig().getSSLConfig();

assertEquals(generatedSSLConfig.getProperty("keyStorePassword"), password);
assertEquals(generatedSSLConfig.getProperty("trustStorePassword"), password);
assertEquals(password, generatedSSLConfig.getProperty("keyStorePassword"));
assertEquals(password, generatedSSLConfig.getProperty("trustStorePassword"));

String secPassword = newConfigViaXMLGenerator.getNetworkConfig().getSymmetricEncryptionConfig().getPassword();
String theSalt = newConfigViaXMLGenerator.getNetworkConfig().getSymmetricEncryptionConfig().getSalt();
assertEquals(secPassword, password);
assertEquals(theSalt, salt);
assertEquals(newConfigViaXMLGenerator.getLicenseKey(), licenseKey);
assertEquals(password, secPassword);
assertEquals(salt, theSalt);
assertEquals(licenseKey, newConfigViaXMLGenerator.getLicenseKey());
SecurityConfig securityConfig = newConfigViaXMLGenerator.getSecurityConfig();
RealmConfig realmConfig = securityConfig.getRealmConfig(securityConfig.getMemberRealm());
assertEquals(realmConfig.getUsernamePasswordIdentityConfig().getPassword(), password);
assertEquals(password, realmConfig.getUsernamePasswordIdentityConfig().getPassword());
}

private MemberAddressProviderConfig getMemberAddressProviderConfig(Config cfg) {
Expand Down Expand Up @@ -618,7 +630,7 @@ public void testLdapConfig() {
SecurityConfig expectedConfig = new SecurityConfig().setClientRealmConfig("ldapRealm", realmConfig);
cfg.setSecurityConfig(expectedConfig);

SecurityConfig actualConfig = getNewConfigViaXMLGenerator(cfg).getSecurityConfig();
SecurityConfig actualConfig = getNewConfigViaXMLGenerator(cfg, false).getSecurityConfig();
assertEquals(expectedConfig, actualConfig);
}

Expand Down Expand Up @@ -676,7 +688,7 @@ public void testSimpleAuthenticationConfig() {
);
SecurityConfig expectedConfig = new SecurityConfig().setMemberRealmConfig("simpleRealm", realmConfig);
cfg.setSecurityConfig(expectedConfig);
SecurityConfig actualConfig = getNewConfigViaXMLGenerator(cfg).getSecurityConfig();
SecurityConfig actualConfig = getNewConfigViaXMLGenerator(cfg, false).getSecurityConfig();
assertEquals(expectedConfig, actualConfig);
}

Expand Down