Skip to content

Commit 0c93bee

Browse files
committed
Watcher: Add ssl.trust email account setting (#31684)
In order to allow users to specify hosts, where SSL is always trusted, this setting is exposed. Otherwise the system keystore needs to be configured properly. For more info see https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
1 parent 49416db commit 0c93bee

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/email/EmailService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public class EmailService extends NotificationService<Account> {
7979
Setting.affixKeySetting("xpack.notification.email.account.", "smtp.local_address",
8080
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope));
8181

82+
private static final Setting.AffixSetting<String> SETTING_SMTP_SSL_TRUST_ADDRESS =
83+
Setting.affixKeySetting("xpack.notification.email.account.", "smtp.ssl.trust",
84+
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope));
85+
8286
private static final Setting.AffixSetting<Integer> SETTING_SMTP_LOCAL_PORT =
8387
Setting.affixKeySetting("xpack.notification.email.account.", "smtp.local_port",
8488
(key) -> Setting.intSetting(key, 25, Property.Dynamic, Property.NodeScope));
@@ -111,6 +115,7 @@ public EmailService(Settings settings, @Nullable CryptoService cryptoService, Cl
111115
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_TIMEOUT, (s, o) -> {}, (s, o) -> {});
112116
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_CONNECTION_TIMEOUT, (s, o) -> {}, (s, o) -> {});
113117
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_WRITE_TIMEOUT, (s, o) -> {}, (s, o) -> {});
118+
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_SSL_TRUST_ADDRESS, (s, o) -> {}, (s, o) -> {});
114119
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_LOCAL_ADDRESS, (s, o) -> {}, (s, o) -> {});
115120
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_LOCAL_PORT, (s, o) -> {}, (s, o) -> {});
116121
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_SEND_PARTIAL, (s, o) -> {}, (s, o) -> {});
@@ -168,7 +173,7 @@ public static List<Setting<?>> getSettings() {
168173
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_PROFILE, SETTING_EMAIL_DEFAULTS, SETTING_SMTP_AUTH, SETTING_SMTP_HOST,
169174
SETTING_SMTP_PASSWORD, SETTING_SMTP_PORT, SETTING_SMTP_STARTTLS_ENABLE, SETTING_SMTP_USER, SETTING_SMTP_STARTTLS_REQUIRED,
170175
SETTING_SMTP_TIMEOUT, SETTING_SMTP_CONNECTION_TIMEOUT, SETTING_SMTP_WRITE_TIMEOUT, SETTING_SMTP_LOCAL_ADDRESS,
171-
SETTING_SMTP_LOCAL_PORT, SETTING_SMTP_SEND_PARTIAL, SETTING_SMTP_WAIT_ON_QUIT);
176+
SETTING_SMTP_LOCAL_PORT, SETTING_SMTP_SEND_PARTIAL, SETTING_SMTP_WAIT_ON_QUIT, SETTING_SMTP_SSL_TRUST_ADDRESS);
172177
}
173178

174179
}

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailServiceTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void testAccountSmtpPropertyConfiguration() {
7171
.put("xpack.notification.email.account.account4.smtp.local_port", "1025")
7272
.put("xpack.notification.email.account.account5.smtp.host", "localhost")
7373
.put("xpack.notification.email.account.account5.smtp.wait_on_quit", true)
74+
.put("xpack.notification.email.account.account5.smtp.ssl.trust", "host1,host2,host3")
7475
.build();
7576
EmailService emailService = new EmailService(settings, null,
7677
new ClusterSettings(Settings.EMPTY, new HashSet<>(EmailService.getSettings())));
@@ -103,5 +104,6 @@ public void testAccountSmtpPropertyConfiguration() {
103104
Account account5 = emailService.getAccount("account5");
104105
Properties properties5 = account5.getConfig().smtp.properties;
105106
assertThat(properties5, hasEntry("mail.smtp.quitwait", "true"));
107+
assertThat(properties5, hasEntry("mail.smtp.ssl.trust", "host1,host2,host3"));
106108
}
107109
}

0 commit comments

Comments
 (0)