Skip to content

Commit 4328470

Browse files
authored
Watcher: Ensure correct method is used to read secure settings (#31753)
As SecureSetting is extended from Setting, you can easily accidentally use `SecureSetting.simpleString()` to read a secure setting instead of `SecureSetting.secureString()`. This commit changes this behaviour in some watcher notification services.
1 parent 7919372 commit 4328470

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/hipchat/HipChatService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.common.settings.ClusterSettings;
99
import org.elasticsearch.common.settings.SecureSetting;
10+
import org.elasticsearch.common.settings.SecureString;
1011
import org.elasticsearch.common.settings.Setting;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.common.settings.SettingsException;
@@ -35,10 +36,9 @@ public class HipChatService extends NotificationService<HipChatAccount> {
3536
(key) -> Setting.simpleString(key, Setting.Property.Dynamic, Setting.Property.NodeScope, Setting.Property.Filtered,
3637
Setting.Property.Deprecated));
3738

38-
private static final Setting.AffixSetting<String> SETTING_AUTH_TOKEN_SECURE =
39+
private static final Setting.AffixSetting<SecureString> SETTING_AUTH_TOKEN_SECURE =
3940
Setting.affixKeySetting("xpack.notification.hipchat.account.", "secure_auth_token",
40-
(key) -> SecureSetting.simpleString(key, Setting.Property.Dynamic, Setting.Property.NodeScope,
41-
Setting.Property.Filtered));
41+
(key) -> SecureSetting.secureString(key, null));
4242

4343
private static final Setting.AffixSetting<String> SETTING_PROFILE =
4444
Setting.affixKeySetting("xpack.notification.hipchat.account.", "profile",

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/jira/JiraService.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package org.elasticsearch.xpack.watcher.notification.jira;
77

88
import org.elasticsearch.common.settings.ClusterSettings;
9+
import org.elasticsearch.common.settings.SecureSetting;
10+
import org.elasticsearch.common.settings.SecureString;
911
import org.elasticsearch.common.settings.Setting;
1012
import org.elasticsearch.common.settings.Setting.Property;
1113
import org.elasticsearch.common.settings.Settings;
@@ -41,17 +43,17 @@ public class JiraService extends NotificationService<JiraAccount> {
4143
Setting.affixKeySetting("xpack.notification.jira.account.", "password",
4244
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered, Property.Deprecated));
4345

44-
private static final Setting.AffixSetting<String> SETTING_SECURE_USER =
46+
private static final Setting.AffixSetting<SecureString> SETTING_SECURE_USER =
4547
Setting.affixKeySetting("xpack.notification.jira.account.", "secure_user",
46-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
48+
(key) -> SecureSetting.secureString(key, null));
4749

48-
private static final Setting.AffixSetting<String> SETTING_SECURE_URL =
50+
private static final Setting.AffixSetting<SecureString> SETTING_SECURE_URL =
4951
Setting.affixKeySetting("xpack.notification.jira.account.", "secure_url",
50-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
52+
(key) -> SecureSetting.secureString(key, null));
5153

52-
private static final Setting.AffixSetting<String> SETTING_SECURE_PASSWORD =
54+
private static final Setting.AffixSetting<SecureString> SETTING_SECURE_PASSWORD =
5355
Setting.affixKeySetting("xpack.notification.jira.account.", "secure_password",
54-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
56+
(key) -> SecureSetting.secureString(key, null));
5557

5658
private static final Setting.AffixSetting<Settings> SETTING_DEFAULTS =
5759
Setting.affixKeySetting("xpack.notification.jira.account.", "issue_defaults",

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/pagerduty/PagerDutyService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.common.settings.ClusterSettings;
99
import org.elasticsearch.common.settings.SecureSetting;
10+
import org.elasticsearch.common.settings.SecureString;
1011
import org.elasticsearch.common.settings.Setting;
1112
import org.elasticsearch.common.settings.Setting.Property;
1213
import org.elasticsearch.common.settings.Settings;
@@ -28,9 +29,9 @@ public class PagerDutyService extends NotificationService<PagerDutyAccount> {
2829
Setting.affixKeySetting("xpack.notification.pagerduty.account.", "service_api_key",
2930
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered, Property.Deprecated));
3031

31-
private static final Setting.AffixSetting<String> SETTING_SECURE_SERVICE_API_KEY =
32+
private static final Setting.AffixSetting<SecureString> SETTING_SECURE_SERVICE_API_KEY =
3233
Setting.affixKeySetting("xpack.notification.pagerduty.account.", "secure_service_api_key",
33-
(key) -> SecureSetting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
34+
(key) -> SecureSetting.secureString(key, null));
3435

3536
private static final Setting.AffixSetting<Settings> SETTING_DEFAULTS =
3637
Setting.affixKeySetting("xpack.notification.pagerduty.account.", "event_defaults",

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/SlackService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.common.settings.ClusterSettings;
99
import org.elasticsearch.common.settings.SecureSetting;
10+
import org.elasticsearch.common.settings.SecureString;
1011
import org.elasticsearch.common.settings.Setting;
1112
import org.elasticsearch.common.settings.Setting.Property;
1213
import org.elasticsearch.common.settings.Settings;
@@ -28,9 +29,9 @@ public class SlackService extends NotificationService<SlackAccount> {
2829
Setting.affixKeySetting("xpack.notification.slack.account.", "url",
2930
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered, Property.Deprecated));
3031

31-
private static final Setting.AffixSetting<String> SETTING_URL_SECURE =
32+
private static final Setting.AffixSetting<SecureString> SETTING_URL_SECURE =
3233
Setting.affixKeySetting("xpack.notification.slack.account.", "secure_url",
33-
(key) -> SecureSetting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
34+
(key) -> SecureSetting.secureString(key, null));
3435

3536
private static final Setting.AffixSetting<Settings> SETTING_DEFAULTS =
3637
Setting.affixKeySetting("xpack.notification.slack.account.", "message_defaults",

0 commit comments

Comments
 (0)