-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Add secure setting for watcher email password #31620
Changes from 1 commit
d6e9578
bb27bba
4bbba31
d75f16f
aaaa7fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
|
||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.SpecialPermission; | ||
import org.elasticsearch.common.settings.SecureSetting; | ||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.settings.SettingsException; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
@@ -28,6 +31,8 @@ | |
public class Account { | ||
|
||
static final String SMTP_PROTOCOL = "smtp"; | ||
static final String SMTP_PASSWORD = "password"; | ||
private static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_" + SMTP_PASSWORD, null); | ||
|
||
static { | ||
SecurityManager sm = System.getSecurityManager(); | ||
|
@@ -204,13 +209,30 @@ static class Smtp { | |
|
||
Smtp(Settings settings) { | ||
host = settings.get("host", settings.get("localaddress", settings.get("local_address"))); | ||
|
||
port = settings.getAsInt("port", settings.getAsInt("localport", settings.getAsInt("local_port", 25))); | ||
user = settings.get("user", settings.get("from", null)); | ||
String passStr = settings.get("password", null); | ||
String passStr = getNullableSetting(SMTP_PASSWORD, settings, SECURE_PASSWORD_SETTING); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about storing the password as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
password = passStr != null ? passStr.toCharArray() : null; | ||
properties = loadSmtpProperties(settings); | ||
} | ||
|
||
/** | ||
* Finds a setting, and then a secure setting if the setting is null, or returns null if one does not exist. This differs | ||
* from other getSetting calls in that it allows for null whereas the other methods throw an exception. | ||
*/ | ||
private static String getNullableSetting(String settingName, Settings settings, Setting<SecureString> secureSetting) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name is not too descriptive but I dont have a good alternative at the moment either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea was only cuz the other classes have a method like this called |
||
String value = settings.get(settingName); | ||
if (value == null) { | ||
SecureString secureString = secureSetting.get(settings); | ||
if (secureString != null && secureString.length() > 0) { | ||
value = secureString.toString(); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
* loads the standard Java Mail properties as settings from the given account settings. | ||
* The standard settings are not that readable, therefore we enabled the user to configure | ||
|
@@ -232,7 +254,10 @@ static Properties loadSmtpProperties(Settings settings) { | |
settings = builder.build(); | ||
Properties props = new Properties(); | ||
for (String key : settings.keySet()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
props.setProperty(SMTP_SETTINGS_PREFIX + key, settings.get(key)); | ||
// Secure strings can not be retreived out of a settings object and should be handled differently | ||
if (key.startsWith("secure_") == false) { | ||
props.setProperty(SMTP_SETTINGS_PREFIX + key, settings.get(key)); | ||
} | ||
} | ||
return props; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be made private?