Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tribe: Add error with secure settings copied to tribe #32298

Merged
merged 2 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.SecureSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -786,11 +787,16 @@ private static void addTribeSettings(Settings settings, Settings.Builder setting
}

// we passed all the checks now we need to copy in all of the x-pack security settings
settings.keySet().forEach(k -> {
SecureSettings secureSettings = Settings.builder().put(settings).getSecureSettings(); // hack to get at secure settings...
Set<String> secureSettingKeys = secureSettings == null ? Collections.emptySet() : secureSettings.getSettingNames();
for (String k : settings.keySet()) {
if (k.startsWith("xpack.security.")) {
if (secureSettingKeys.contains(k)) {
throw new IllegalArgumentException("Secure setting [" + k + "] cannot be used with tribe client node");
Copy link
Member

@jaymode jaymode Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about building a set of invalid keys and adding them all to the exception? This would be a little friendlier to a user with multiple secure settings

}
settingsBuilder.copy(tribePrefix + k, k, settings);
}
});
}
}

Map<String, Settings> realmsSettings = settings.getGroups(SecurityField.setting("authc.realms"), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,20 @@ public void testTribeSettingNames() throws Exception {
s, anyOf(startsWith("tribe.blocks"), startsWith("tribe.name"), startsWith("tribe.on_conflict"))));
}

public void testNoTribeSecureSettings() throws Exception {
MockSecureSettings secureSettings = new MockSecureSettings();
Path home = createTempDir();
secureSettings.setString("xpack.security.http.ssl.keystore.secure_password", "dummypass");
Settings settings = Settings.builder().setSecureSettings(secureSettings)
.put("path.home", home)
.put("tribe.t1.cluster.name", "foo")
.put("xpack.security.enabled", true).build();
Security security = new Security(settings, home.resolve("config"));
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, security::additionalSettings);
assertThat(e.getMessage(),
equalTo("Secure setting [xpack.security.http.ssl.keystore.secure_password] cannot be used with tribe client node"));
}

private void assertTribeNodeHasAllIndices() throws Exception {
assertBusy(() -> {
Set<String> indices = new HashSet<>();
Expand Down