Skip to content

Commit be515d7

Browse files
committed
Validate non-secure settings are not in keystore (#42209)
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
1 parent 6ae6f57 commit be515d7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

server/src/main/java/org/elasticsearch/common/settings/Setting.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ public final String getRaw(final Settings settings) {
467467
* @return the raw string representation of the setting value
468468
*/
469469
String innerGetRaw(final Settings settings) {
470+
SecureSettings secureSettings = settings.getSecureSettings();
471+
if (secureSettings != null && secureSettings.getSettingNames().contains(getKey())) {
472+
throw new IllegalArgumentException("Setting [" + getKey() + "] is a non-secure setting" +
473+
" and must be stored inside elasticsearch.yml, but was found inside the Elasticsearch keystore");
474+
}
470475
return settings.get(getKey(), defaultValue.apply(settings));
471476
}
472477

server/src/test/java/org/elasticsearch/common/settings/SettingTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,4 +964,13 @@ public void testAffixMapUpdateWithNullSettingValue() {
964964
assertEquals("", value);
965965
}
966966

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

0 commit comments

Comments
 (0)