Skip to content

Commit 3b0f826

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 2ba468e commit 3b0f826

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));
@@ -110,6 +114,7 @@ public EmailService(Settings settings, @Nullable CryptoService cryptoService, Cl
110114
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_TIMEOUT, (s, o) -> {}, (s, o) -> {});
111115
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_CONNECTION_TIMEOUT, (s, o) -> {}, (s, o) -> {});
112116
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_WRITE_TIMEOUT, (s, o) -> {}, (s, o) -> {});
117+
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_SSL_TRUST_ADDRESS, (s, o) -> {}, (s, o) -> {});
113118
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_LOCAL_ADDRESS, (s, o) -> {}, (s, o) -> {});
114119
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_LOCAL_PORT, (s, o) -> {}, (s, o) -> {});
115120
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_SEND_PARTIAL, (s, o) -> {}, (s, o) -> {});
@@ -167,7 +172,7 @@ public static List<Setting<?>> getSettings() {
167172
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_PROFILE, SETTING_EMAIL_DEFAULTS, SETTING_SMTP_AUTH, SETTING_SMTP_HOST,
168173
SETTING_SMTP_PASSWORD, SETTING_SMTP_PORT, SETTING_SMTP_STARTTLS_ENABLE, SETTING_SMTP_USER, SETTING_SMTP_STARTTLS_REQUIRED,
169174
SETTING_SMTP_TIMEOUT, SETTING_SMTP_CONNECTION_TIMEOUT, SETTING_SMTP_WRITE_TIMEOUT, SETTING_SMTP_LOCAL_ADDRESS,
170-
SETTING_SMTP_LOCAL_PORT, SETTING_SMTP_SEND_PARTIAL, SETTING_SMTP_WAIT_ON_QUIT);
175+
SETTING_SMTP_LOCAL_PORT, SETTING_SMTP_SEND_PARTIAL, SETTING_SMTP_WAIT_ON_QUIT, SETTING_SMTP_SSL_TRUST_ADDRESS);
171176
}
172177

173178
}

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
@@ -68,6 +68,7 @@ public void testAccountSmtpPropertyConfiguration() {
6868
.put("xpack.notification.email.account.account4.smtp.local_port", "1025")
6969
.put("xpack.notification.email.account.account5.smtp.host", "localhost")
7070
.put("xpack.notification.email.account.account5.smtp.wait_on_quit", true)
71+
.put("xpack.notification.email.account.account5.smtp.ssl.trust", "host1,host2,host3")
7172
.build();
7273
EmailService emailService = new EmailService(settings, null,
7374
new ClusterSettings(Settings.EMPTY, new HashSet<>(EmailService.getSettings())));
@@ -100,5 +101,6 @@ public void testAccountSmtpPropertyConfiguration() {
100101
Account account5 = emailService.getAccount("account5");
101102
Properties properties5 = account5.getConfig().smtp.properties;
102103
assertThat(properties5, hasEntry("mail.smtp.quitwait", "true"));
104+
assertThat(properties5, hasEntry("mail.smtp.ssl.trust", "host1,host2,host3"));
103105
}
104106
}

0 commit comments

Comments
 (0)