Skip to content

Commit

Permalink
Validate non-secure settings are not in keystore (#42209)
Browse files Browse the repository at this point in the history
Secure settings currently error if they exist inside elasticsearch.yml.
This commit adds validation that non-secure settings do not exist inside
the keystore.

closes #41831
  • Loading branch information
rjernst authored May 20, 2019
1 parent fdcbf05 commit da5abe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ public final String getRaw(final Settings settings) {
* @return the raw string representation of the setting value
*/
String innerGetRaw(final Settings settings) {
SecureSettings secureSettings = settings.getSecureSettings();
if (secureSettings != null && secureSettings.getSettingNames().contains(getKey())) {
throw new IllegalArgumentException("Setting [" + getKey() + "] is a non-secure setting" +
" and must be stored inside elasticsearch.yml, but was found inside the Elasticsearch keystore");
}
return settings.get(getKey(), defaultValue.apply(settings));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,4 +964,13 @@ public void testAffixMapUpdateWithNullSettingValue() {
assertEquals("", value);
}

public void testNonSecureSettingInKeystore() {
MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("foo", "bar");
final Settings settings = Settings.builder().setSecureSettings(secureSettings).build();
Setting<String> setting = Setting.simpleString("foo", Property.NodeScope);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> setting.get(settings));
assertThat(e.getMessage(), containsString("must be stored inside elasticsearch.yml"));
}

}

0 comments on commit da5abe2

Please sign in to comment.