From f582998a220893f35f9c8cf1e270aff7aaa8dcc2 Mon Sep 17 00:00:00 2001 From: Siddhant <86899184+Siddhanttimeline@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:40:49 +0530 Subject: [PATCH] fix: Mask email password (#19120) --- .../org/openmetadata/service/jdbi3/SystemRepository.java | 7 +++++++ .../service/resources/system/SystemResourceTest.java | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java index 01b7d76d12f9..fbcd2118163d 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java @@ -42,6 +42,7 @@ import org.openmetadata.service.search.SearchRepository; import org.openmetadata.service.secrets.SecretsManager; import org.openmetadata.service.secrets.SecretsManagerFactory; +import org.openmetadata.service.secrets.masker.PasswordEntityMasker; import org.openmetadata.service.security.JwtFilter; import org.openmetadata.service.security.auth.LoginAttemptCache; import org.openmetadata.service.util.JsonUtils; @@ -108,6 +109,12 @@ public Settings getConfigWithKey(String key) { return null; } + if (fetchedSettings.getConfigType() == SettingsType.EMAIL_CONFIGURATION) { + SmtpSettings emailConfig = (SmtpSettings) fetchedSettings.getConfigValue(); + emailConfig.setPassword(PasswordEntityMasker.PASSWORD_MASK); + fetchedSettings.setConfigValue(emailConfig); + } + return fetchedSettings; } catch (Exception ex) { LOG.error("Error while trying fetch Settings ", ex); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java index 686de7c1bd3a..d7cc9d04cddd 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java @@ -81,6 +81,7 @@ import org.openmetadata.service.resources.teams.TeamResourceTest; import org.openmetadata.service.resources.teams.UserResourceTest; import org.openmetadata.service.resources.topics.TopicResourceTest; +import org.openmetadata.service.secrets.masker.PasswordEntityMasker; import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.TestUtils; @@ -190,10 +191,10 @@ void testSystemConfigs() throws HttpResponseException { // Test Email Config Settings emailSettings = getSystemConfig(SettingsType.EMAIL_CONFIGURATION); SmtpSettings smtp = JsonUtils.convertValue(emailSettings.getConfigValue(), SmtpSettings.class); - // Password for Email is encrypted using fernet + // Password for Email is always sent in hidden SmtpSettings expected = config.getSmtpSettings(); - expected.setPassword(smtp.getPassword()); - assertEquals(config.getSmtpSettings(), smtp); + expected.setPassword(PasswordEntityMasker.PASSWORD_MASK); + assertEquals(expected, smtp); // Test Custom Ui Theme Preference Config Settings uiThemeConfigWrapped = getSystemConfig(SettingsType.CUSTOM_UI_THEME_PREFERENCE);