Skip to content

Commit 182858b

Browse files
committed
Tribe: Add error with secure settings copied to tribe
This commit adds a clear error message when tribe setup attempts to copy a secure setting into tribe settings. This behavior has never worked, but the previous error message was very confusing, complaining about a source key not being found later when trying to read the setting. closes #32117
1 parent 3a6992c commit 182858b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.common.regex.Regex;
3535
import org.elasticsearch.common.settings.ClusterSettings;
3636
import org.elasticsearch.common.settings.IndexScopedSettings;
37+
import org.elasticsearch.common.settings.SecureSettings;
3738
import org.elasticsearch.common.settings.Setting;
3839
import org.elasticsearch.common.settings.Setting.Property;
3940
import org.elasticsearch.common.settings.Settings;
@@ -786,11 +787,16 @@ private static void addTribeSettings(Settings settings, Settings.Builder setting
786787
}
787788

788789
// we passed all the checks now we need to copy in all of the x-pack security settings
789-
settings.keySet().forEach(k -> {
790+
SecureSettings secureSettings = Settings.builder().put(settings).getSecureSettings(); // hack to get at secure settings...
791+
Set<String> secureSettingKeys = secureSettings == null ? Collections.emptySet() : secureSettings.getSettingNames();
792+
for (String k : settings.keySet()) {
790793
if (k.startsWith("xpack.security.")) {
794+
if (secureSettingKeys.contains(k)) {
795+
throw new IllegalArgumentException("Secure setting [" + k + "] cannot be used with tribe client node");
796+
}
791797
settingsBuilder.copy(tribePrefix + k, k, settings);
792798
}
793-
});
799+
}
794800
}
795801

796802
Map<String, Settings> realmsSettings = settings.getGroups(SecurityField.setting("authc.realms"), true);

x-pack/qa/tribe-tests-with-security/src/test/java/org/elasticsearch/xpack/security/SecurityTribeTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,20 @@ public void testTribeSettingNames() throws Exception {
556556
s, anyOf(startsWith("tribe.blocks"), startsWith("tribe.name"), startsWith("tribe.on_conflict"))));
557557
}
558558

559+
public void testNoTribeSecureSettings() throws Exception {
560+
MockSecureSettings secureSettings = new MockSecureSettings();
561+
Path home = createTempDir();
562+
secureSettings.setString("xpack.security.http.ssl.keystore.secure_password", "dummypass");
563+
Settings settings = Settings.builder().setSecureSettings(secureSettings)
564+
.put("path.home", home)
565+
.put("tribe.t1.cluster.name", "foo")
566+
.put("xpack.security.enabled", true).build();
567+
Security security = new Security(settings, home.resolve("config"));
568+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, security::additionalSettings);
569+
assertThat(e.getMessage(),
570+
equalTo("Secure setting [xpack.security.http.ssl.keystore.secure_password] cannot be used with tribe client node"));
571+
}
572+
559573
private void assertTribeNodeHasAllIndices() throws Exception {
560574
assertBusy(() -> {
561575
Set<String> indices = new HashSet<>();

0 commit comments

Comments
 (0)