Skip to content

Commit

Permalink
Validate monitoring header overrides at parse time (#47848)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann committed Nov 4, 2019
1 parent 7903b8c commit 10fc118
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,23 @@ public Iterator<Setting<?>> settings() {
*/
public static final Setting.AffixSetting<Settings> HEADERS_SETTING =
Setting.affixKeySetting("xpack.monitoring.exporters.","headers",
(key) -> Setting.groupSetting(key + ".", Property.Dynamic, Property.NodeScope));
(key) -> Setting.groupSetting(
key + ".",
settings -> {
final Set<String> names = settings.names();
for (String name : names) {
final String fullSetting = key + "." + name;
if (HttpExporter.BLACKLISTED_HEADERS.contains(name)) {
throw new SettingsException("header cannot be overwritten via [" + fullSetting + "]");
}
final List<String> values = settings.getAsList(name);
if (values.isEmpty()) {
throw new SettingsException("headers must have values, missing for setting [" + fullSetting + "]");
}
}
},
Property.Dynamic,
Property.NodeScope));
/**
* Blacklist of headers that the user is not allowed to set.
* <p>
Expand Down Expand Up @@ -539,16 +555,7 @@ private static void configureHeaders(final RestClientBuilder builder, final Conf

// record and validate each header as best we can
for (final String name : names) {
if (BLACKLISTED_HEADERS.contains(name)) {
throw new SettingsException("header cannot be overwritten via [" + concreteSetting.getKey() + name + "]");
}

final List<String> values = headerSettings.getAsList(name);

if (values.isEmpty()) {
throw new SettingsException("headers must have values, missing for setting [" + concreteSetting.getKey() + name + "]");
}

// add each value as a separate header; they literally appear like:
//
// Warning: abc
Expand Down

0 comments on commit 10fc118

Please sign in to comment.