Skip to content

Commit 5308746

Browse files
Remove Watcher Account "unsecure" settings (#36736)
Removes all sensitive settings (passwords, auth tokens, urls, etc...) for watcher notifications accounts. These settings were deprecated (and herein removed) in favor of their secure sibling that is set inside the elasticsearch keystore. For example: `xpack.notification.email.account.<id>.smtp.password` is no longer a valid setting, and it is replaced by `xpack.notification.email.account.<id>.smtp.secure_password`
1 parent fc99eb3 commit 5308746

File tree

28 files changed

+243
-226
lines changed

28 files changed

+243
-226
lines changed

docs/reference/migration/migrate_7_0/settings.asciidoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,26 @@ The removal of these default settings also removes the ability for a component t
131131
fallback to a default configuration when using TLS. Each component (realm, transport, http,
132132
http client, etc) must now be configured with their own settings for TLS if it is being
133133
used.
134+
135+
[float]
136+
[[watcher-notifications-account-settings]]
137+
==== Watcher notifications account settings
138+
139+
The following settings have been removed in favor of the secure variants.
140+
The <<secure-settings, secure settings>> have to be defined inside each cluster
141+
node's keystore, i.e., they are not to be specified via the cluster settings API.
142+
143+
- `xpack.notification.email.account.<id>.smtp.password`, instead use
144+
`xpack.notification.email.account.<id>.smtp.secure_password`
145+
- `xpack.notification.hipchat.account.<id>.auth_token`, instead use
146+
`xpack.notification.hipchat.account.<id>.secure_auth_token`
147+
- `xpack.notification.jira.account.<id>.url`, instead use
148+
`xpack.notification.jira.account.<id>.secure_url`
149+
- `xpack.notification.jira.account.<id>.user`, instead use
150+
`xpack.notification.jira.account.<id>.secure_user`
151+
- `xpack.notification.jira.account.<id>.password`, instead use
152+
`xpack.notification.jira.account.<id>.secure_password`
153+
- `xpack.notification.pagerduty.account.<id>.service_api_key`, instead use
154+
`xpack.notification.pagerduty.account.<id>.secure_service_api_key`
155+
- `xpack.notification.slack.account.<id>.url`, instead use
156+
`xpack.notification.slack.account.<id>.secure_url`

docs/reference/settings/notification-settings.asciidoc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ can specify the following email account attributes:
115115
`smtp.user` (<<cluster-update-settings,Dynamic>>);;
116116
The user name for SMTP. Required.
117117

118-
`smtp.password` (<<cluster-update-settings,Dynamic>>);;
118+
`smtp.secure_password` (<<secure-settings,Secure>>);;
119119
The password for the specified SMTP user.
120120

121121
`smtp.starttls.enable` (<<cluster-update-settings,Dynamic>>);;
@@ -222,9 +222,8 @@ via HipChat. You can specify the following HipChat account attributes:
222222
The HipChat account profile to use: `integration`,
223223
`user`, or `v1`. Required.
224224

225-
`auth_token`;;
226-
The authentication token to use to access
227-
the HipChat API. Required.
225+
`secure_auth_token` (<<secure-settings,Secure>>);;
226+
The authentication token to use to access the HipChat API. Required.
228227

229228
`host`;;
230229
The HipChat server hostname. Defaults to `api.hipchat.com`.
@@ -268,9 +267,8 @@ via Slack. You can specify the following Slack account attributes:
268267

269268
[[slack-account-attributes]]
270269

271-
`url`;;
272-
The Incoming Webhook URL to use to post
273-
messages to Slack. Required.
270+
`secure_url` (<<secure-settings,Secure>>);;
271+
The Incoming Webhook URL to use to post messages to Slack. Required.
274272

275273
`message_defaults.from`;;
276274
The sender name to display in the
@@ -309,13 +307,13 @@ issues in Jira. You can specify the following Jira account attributes:
309307

310308
[[jira-account-attributes]]
311309

312-
`url`;;
310+
`secure_url` (<<secure-settings,Secure>>);;
313311
The URL of the Jira Software server. Required.
314312

315-
`user`;;
313+
`secure_user` (<<secure-settings,Secure>>);;
316314
The name of the user to connect to the Jira Software server. Required.
317315

318-
`password`;;
316+
`secure_password` (<<secure-settings,Secure>>);;
319317
The password of the user to connect to the Jira Software server. Required.
320318

321319
`issue_defaults`;;
@@ -341,7 +339,7 @@ via PagerDuty. You can specify the following PagerDuty account attributes:
341339
A name for the PagerDuty account associated with the API key you
342340
are using to access PagerDuty. Required.
343341

344-
`service_api_key`;;
342+
`secure_service_api_key` (<<secure-settings,Secure>>);;
345343
The https://developer.pagerduty.com/documentation/rest/authentication[
346344
PagerDuty API key] to use to access PagerDuty. Required.
347345

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
public class Account {
3333

3434
static final String SMTP_PROTOCOL = "smtp";
35-
private static final String SMTP_PASSWORD = "password";
36-
private static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_" + SMTP_PASSWORD, null);
35+
public static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_password", null);
3736

3837
static {
3938
SecurityManager sm = System.getSecurityManager();
@@ -213,7 +212,7 @@ static class Smtp {
213212

214213
port = settings.getAsInt("port", settings.getAsInt("localport", settings.getAsInt("local_port", 25)));
215214
user = settings.get("user", settings.get("from", null));
216-
password = getSecureSetting(SMTP_PASSWORD, settings, SECURE_PASSWORD_SETTING);
215+
password = getSecureSetting(settings, SECURE_PASSWORD_SETTING);
217216
//password = passStr != null ? passStr.toCharArray() : null;
218217
properties = loadSmtpProperties(settings);
219218
}
@@ -225,17 +224,12 @@ static class Smtp {
225224
* Note: if your setting was not previously secure, than the string reference that is in the setting object is still
226225
* insecure. This is only constructing a new SecureString with the char[] of the insecure setting.
227226
*/
228-
private static SecureString getSecureSetting(String settingName, Settings settings, Setting<SecureString> secureSetting) {
229-
String value = settings.get(settingName);
230-
if (value == null) {
231-
SecureString secureString = secureSetting.get(settings);
232-
if (secureString != null && secureString.length() > 0) {
233-
return secureString;
234-
} else {
235-
return null;
236-
}
227+
private static SecureString getSecureSetting(Settings settings, Setting<SecureString> secureSetting) {
228+
SecureString secureString = secureSetting.get(settings);
229+
if (secureString != null && secureString.length() > 0) {
230+
return secureString;
237231
} else {
238-
return new SecureString(value.toCharArray());
232+
return null;
239233
}
240234
}
241235

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public class EmailService extends NotificationService<Account> {
6565
Setting.affixKeySetting("xpack.notification.email.account.", "smtp.user",
6666
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope));
6767

68-
private static final Setting.AffixSetting<String> SETTING_SMTP_PASSWORD =
69-
Setting.affixKeySetting("xpack.notification.email.account.", "smtp.password",
70-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
71-
7268
private static final Setting.AffixSetting<SecureString> SETTING_SECURE_PASSWORD =
7369
Setting.affixKeySetting("xpack.notification.email.account.", "smtp.secure_password",
7470
(key) -> SecureSetting.secureString(key, null));
@@ -122,7 +118,6 @@ public EmailService(Settings settings, @Nullable CryptoService cryptoService, Cl
122118
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_HOST, (s, o) -> {}, (s, o) -> {});
123119
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_PORT, (s, o) -> {}, (s, o) -> {});
124120
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_USER, (s, o) -> {}, (s, o) -> {});
125-
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_PASSWORD, (s, o) -> {}, (s, o) -> {});
126121
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_TIMEOUT, (s, o) -> {}, (s, o) -> {});
127122
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_CONNECTION_TIMEOUT, (s, o) -> {}, (s, o) -> {});
128123
clusterSettings.addAffixUpdateConsumer(SETTING_SMTP_WRITE_TIMEOUT, (s, o) -> {}, (s, o) -> {});
@@ -182,7 +177,7 @@ public Email email() {
182177

183178
private static List<Setting<?>> getDynamicSettings() {
184179
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_PROFILE, SETTING_EMAIL_DEFAULTS, SETTING_SMTP_AUTH, SETTING_SMTP_HOST,
185-
SETTING_SMTP_PASSWORD, SETTING_SMTP_PORT, SETTING_SMTP_STARTTLS_ENABLE, SETTING_SMTP_USER, SETTING_SMTP_STARTTLS_REQUIRED,
180+
SETTING_SMTP_PORT, SETTING_SMTP_STARTTLS_ENABLE, SETTING_SMTP_USER, SETTING_SMTP_STARTTLS_REQUIRED,
186181
SETTING_SMTP_TIMEOUT, SETTING_SMTP_CONNECTION_TIMEOUT, SETTING_SMTP_WRITE_TIMEOUT, SETTING_SMTP_LOCAL_ADDRESS,
187182
SETTING_SMTP_LOCAL_PORT, SETTING_SMTP_SEND_PARTIAL, SETTING_SMTP_WAIT_ON_QUIT, SETTING_SMTP_SSL_TRUST_ADDRESS);
188183
}

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
public abstract class HipChatAccount {
2525

26-
public static final String AUTH_TOKEN_SETTING = "auth_token";
2726
public static final String ROOM_SETTING = HipChatMessage.Field.ROOM.getPreferredName();
2827
public static final String DEFAULT_ROOM_SETTING = "message_defaults." + HipChatMessage.Field.ROOM.getPreferredName();
2928
public static final String DEFAULT_USER_SETTING = "message_defaults." + HipChatMessage.Field.USER.getPreferredName();
@@ -32,7 +31,7 @@ public abstract class HipChatAccount {
3231
public static final String DEFAULT_COLOR_SETTING = "message_defaults." + HipChatMessage.Field.COLOR.getPreferredName();
3332
public static final String DEFAULT_NOTIFY_SETTING = "message_defaults." + HipChatMessage.Field.NOTIFY.getPreferredName();
3433

35-
private static final Setting<SecureString> SECURE_AUTH_TOKEN_SETTING = SecureSetting.secureString("secure_" + AUTH_TOKEN_SETTING, null);
34+
static final Setting<SecureString> SECURE_AUTH_TOKEN_SETTING = SecureSetting.secureString("secure_auth_token", null);
3635

3736
protected final Logger logger;
3837
protected final String name;
@@ -52,16 +51,12 @@ protected HipChatAccount(String name, Profile profile, Settings settings, HipCha
5251
}
5352

5453
private static String getAuthToken(String name, Settings settings) {
55-
String authToken = settings.get(AUTH_TOKEN_SETTING);
56-
if (authToken == null || authToken.length() == 0) {
57-
SecureString secureString = SECURE_AUTH_TOKEN_SETTING.get(settings);
58-
if (secureString == null || secureString.length() < 1) {
59-
throw new SettingsException("hipchat account [" + name + "] missing required [" + AUTH_TOKEN_SETTING + "] setting");
60-
}
61-
authToken = secureString.toString();
54+
SecureString secureString = SECURE_AUTH_TOKEN_SETTING.get(settings);
55+
if (secureString == null || secureString.length() < 1) {
56+
throw new SettingsException(
57+
"hipchat account [" + name + "] missing required [" + SECURE_AUTH_TOKEN_SETTING.getKey() + "] secure setting");
6258
}
63-
64-
return authToken;
59+
return secureString.toString();
6560
}
6661

6762
public abstract String type();

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public class HipChatService extends NotificationService<HipChatAccount> {
3434
static final Setting<Integer> SETTING_DEFAULT_PORT =
3535
Setting.intSetting("xpack.notification.hipchat.port", 443, Setting.Property.Dynamic, Setting.Property.NodeScope);
3636

37-
private static final Setting.AffixSetting<String> SETTING_AUTH_TOKEN =
38-
Setting.affixKeySetting("xpack.notification.hipchat.account.", "auth_token",
39-
(key) -> Setting.simpleString(key, Setting.Property.Dynamic, Setting.Property.NodeScope, Setting.Property.Filtered,
40-
Setting.Property.Deprecated));
41-
4237
private static final Setting.AffixSetting<SecureString> SETTING_AUTH_TOKEN_SECURE =
4338
Setting.affixKeySetting("xpack.notification.hipchat.account.", "secure_auth_token",
4439
(key) -> SecureSetting.secureString(key, null));
@@ -75,7 +70,6 @@ public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings
7570
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
7671
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_HOST, (s) -> {});
7772
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_PORT, (s) -> {});
78-
clusterSettings.addAffixUpdateConsumer(SETTING_AUTH_TOKEN, (s, o) -> {}, (s, o) -> {});
7973
clusterSettings.addAffixUpdateConsumer(SETTING_PROFILE, (s, o) -> {}, (s, o) -> {});
8074
clusterSettings.addAffixUpdateConsumer(SETTING_ROOM, (s, o) -> {}, (s, o) -> {});
8175
clusterSettings.addAffixUpdateConsumer(SETTING_HOST, (s, o) -> {}, (s, o) -> {});
@@ -101,7 +95,7 @@ protected HipChatAccount createAccount(String name, Settings accountSettings) {
10195
}
10296

10397
private static List<Setting<?>> getDynamicSettings() {
104-
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_AUTH_TOKEN, SETTING_PROFILE, SETTING_ROOM, SETTING_MESSAGE_DEFAULTS,
98+
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_PROFILE, SETTING_ROOM, SETTING_MESSAGE_DEFAULTS,
10599
SETTING_DEFAULT_HOST, SETTING_DEFAULT_PORT, SETTING_HOST, SETTING_PORT);
106100
}
107101

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.elasticsearch.xpack.watcher.notification.jira;
77

88
import org.elasticsearch.common.Booleans;
9-
import org.elasticsearch.common.Strings;
109
import org.elasticsearch.common.bytes.BytesReference;
1110
import org.elasticsearch.common.settings.SecureSetting;
1211
import org.elasticsearch.common.settings.SecureString;
@@ -42,15 +41,12 @@ public class JiraAccount {
4241
**/
4342
public static final String DEFAULT_PATH = "/rest/api/2/issue";
4443

45-
static final String USER_SETTING = "user";
46-
static final String PASSWORD_SETTING = "password";
47-
static final String URL_SETTING = "url";
4844
static final String ISSUE_DEFAULTS_SETTING = "issue_defaults";
4945
static final String ALLOW_HTTP_SETTING = "allow_http";
5046

51-
private static final Setting<SecureString> SECURE_USER_SETTING = SecureSetting.secureString("secure_" + USER_SETTING, null);
52-
private static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_" + PASSWORD_SETTING, null);
53-
private static final Setting<SecureString> SECURE_URL_SETTING = SecureSetting.secureString("secure_" + URL_SETTING, null);
47+
public static final Setting<SecureString> SECURE_USER_SETTING = SecureSetting.secureString("secure_user", null);
48+
public static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_password", null);
49+
public static final Setting<SecureString> SECURE_URL_SETTING = SecureSetting.secureString("secure_url", null);
5450

5551
private final HttpClient httpClient;
5652
private final String name;
@@ -62,7 +58,7 @@ public class JiraAccount {
6258
public JiraAccount(String name, Settings settings, HttpClient httpClient) {
6359
this.httpClient = httpClient;
6460
this.name = name;
65-
String url = getSetting(name, URL_SETTING, settings, SECURE_URL_SETTING);
61+
String url = getSetting(name, settings, SECURE_URL_SETTING);
6662
try {
6763
URI uri = new URI(url);
6864
Scheme protocol = Scheme.parse(uri.getScheme());
@@ -71,16 +67,11 @@ public JiraAccount(String name, Settings settings, HttpClient httpClient) {
7167
}
7268
this.url = uri;
7369
} catch (URISyntaxException | IllegalArgumentException e) {
74-
throw new SettingsException("invalid jira [" + name + "] account settings. invalid [" + URL_SETTING + "] setting", e);
75-
}
76-
this.user = getSetting(name, USER_SETTING, settings, SECURE_USER_SETTING);
77-
if (Strings.isEmpty(this.user)) {
78-
throw requiredSettingException(name, USER_SETTING);
79-
}
80-
this.password = getSetting(name, PASSWORD_SETTING, settings, SECURE_PASSWORD_SETTING);
81-
if (Strings.isEmpty(this.password)) {
82-
throw requiredSettingException(name, PASSWORD_SETTING);
70+
throw new SettingsException(
71+
"invalid jira [" + name + "] account settings. invalid [" + SECURE_URL_SETTING.getKey() + "] setting", e);
8372
}
73+
this.user = getSetting(name, settings, SECURE_USER_SETTING);
74+
this.password = getSetting(name, settings, SECURE_PASSWORD_SETTING);
8475
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
8576
builder.startObject();
8677
settings.getAsSettings(ISSUE_DEFAULTS_SETTING).toXContent(builder, ToXContent.EMPTY_PARAMS);
@@ -95,17 +86,12 @@ public JiraAccount(String name, Settings settings, HttpClient httpClient) {
9586
}
9687
}
9788

98-
private static String getSetting(String accountName, String settingName, Settings settings, Setting<SecureString> secureSetting) {
99-
String value = settings.get(settingName);
100-
if (value == null) {
101-
SecureString secureString = secureSetting.get(settings);
102-
if (secureString == null || secureString.length() < 1) {
103-
throw requiredSettingException(accountName, settingName);
104-
}
105-
value = secureString.toString();
89+
private static String getSetting(String accountName, Settings settings, Setting<SecureString> secureSetting) {
90+
SecureString secureString = secureSetting.get(settings);
91+
if (secureString == null || secureString.length() < 1) {
92+
throw requiredSettingException(accountName, secureSetting.getKey());
10693
}
107-
108-
return value;
94+
return secureString.toString();
10995
}
11096

11197
public String getName() {

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ public class JiraService extends NotificationService<JiraAccount> {
3232
Setting.affixKeySetting("xpack.notification.jira.account.", "allow_http",
3333
(key) -> Setting.boolSetting(key, false, Property.Dynamic, Property.NodeScope));
3434

35-
private static final Setting.AffixSetting<String> SETTING_URL =
36-
Setting.affixKeySetting("xpack.notification.jira.account.", "url",
37-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
38-
39-
private static final Setting.AffixSetting<String> SETTING_USER =
40-
Setting.affixKeySetting("xpack.notification.jira.account.", "user",
41-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered));
42-
43-
private static final Setting.AffixSetting<String> SETTING_PASSWORD =
44-
Setting.affixKeySetting("xpack.notification.jira.account.", "password",
45-
(key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope, Property.Filtered, Property.Deprecated));
46-
4735
private static final Setting.AffixSetting<SecureString> SETTING_SECURE_USER =
4836
Setting.affixKeySetting("xpack.notification.jira.account.", "secure_user",
4937
(key) -> SecureSetting.secureString(key, null));
@@ -68,9 +56,6 @@ public JiraService(Settings settings, HttpClient httpClient, ClusterSettings clu
6856
// ensure logging of setting changes
6957
clusterSettings.addSettingsUpdateConsumer(SETTING_DEFAULT_ACCOUNT, (s) -> {});
7058
clusterSettings.addAffixUpdateConsumer(SETTING_ALLOW_HTTP, (s, o) -> {}, (s, o) -> {});
71-
clusterSettings.addAffixUpdateConsumer(SETTING_URL, (s, o) -> {}, (s, o) -> {});
72-
clusterSettings.addAffixUpdateConsumer(SETTING_USER, (s, o) -> {}, (s, o) -> {});
73-
clusterSettings.addAffixUpdateConsumer(SETTING_PASSWORD, (s, o) -> {}, (s, o) -> {});
7459
clusterSettings.addAffixUpdateConsumer(SETTING_DEFAULTS, (s, o) -> {}, (s, o) -> {});
7560
// do an initial load
7661
reload(settings);
@@ -82,7 +67,7 @@ protected JiraAccount createAccount(String name, Settings settings) {
8267
}
8368

8469
private static List<Setting<?>> getDynamicSettings() {
85-
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_ALLOW_HTTP, SETTING_URL, SETTING_USER, SETTING_PASSWORD, SETTING_DEFAULTS);
70+
return Arrays.asList(SETTING_DEFAULT_ACCOUNT, SETTING_ALLOW_HTTP, SETTING_DEFAULTS);
8671
}
8772

8873
private static List<Setting<?>> getSecureSettings() {

0 commit comments

Comments
 (0)