diff --git a/plugin/build.gradle b/plugin/build.gradle index 4975e643b97..783352678ae 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -27,11 +27,13 @@ dependencyLicenses { mapping from: /bc.*/, to: 'bouncycastle' mapping from: /owasp-java-html-sanitizer.*/, to: 'owasp-java-html-sanitizer' mapping from: /transport-netty.*/, to: 'elasticsearch' + mapping from: /tribe.*/, to: 'elasticsearch' mapping from: /elasticsearch-rest-client.*/, to: 'elasticsearch' mapping from: /http.*/, to: 'httpclient' // pulled in by rest client mapping from: /commons-.*/, to: 'commons' // pulled in by rest client ignoreSha 'elasticsearch-rest-client' ignoreSha 'transport-netty4' + ignoreSha 'tribe' ignoreSha 'elasticsearch-rest-client-sniffer' } @@ -54,6 +56,7 @@ configurations { dependencies { // security deps + compile project(path: ':modules:tribe', configuration: 'runtime') compile project(path: ':modules:transport-netty4', configuration: 'runtime') compile 'com.unboundid:unboundid-ldapsdk:3.2.0' compile 'org.bouncycastle:bcprov-jdk15on:1.55' diff --git a/plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java b/plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java index 66e0b15a544..fad87f0713b 100644 --- a/plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java +++ b/plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.license; -import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.AbstractNamedDiffable; import org.elasticsearch.cluster.NamedDiff; import org.elasticsearch.cluster.metadata.MetaData; @@ -14,7 +13,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.License.OperationMode; -import org.elasticsearch.tribe.TribeService; +import org.elasticsearch.cluster.MergableCustomMetaData; import java.io.IOException; import java.util.EnumSet; @@ -23,7 +22,7 @@ import java.util.EnumSet; * Contains metadata about registered licenses */ class LicensesMetaData extends AbstractNamedDiffable implements MetaData.Custom, - TribeService.MergableCustomMetaData { + MergableCustomMetaData { public static final String TYPE = "licenses"; diff --git a/plugin/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/plugin/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 0bb4601167b..9f415947016 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.env.Environment; +import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.index.IndexModule; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -266,7 +267,8 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I @Override public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, - NamedXContentRegistry xContentRegistry) { + NamedXContentRegistry xContentRegistry, Environment environment, + NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) { List components = new ArrayList<>(); components.add(sslService); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java b/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java index 48a5ab3a3dd..e854b42c2e1 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -659,6 +659,10 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin { for (Map.Entry tribeSettings : tribesSettings.entrySet()) { String tribePrefix = "tribe." + tribeSettings.getKey() + "."; + if (TribeService.TRIBE_SETTING_KEYS.stream().anyMatch(s -> s.startsWith(tribePrefix))) { + continue; + } + final String tribeEnabledSetting = tribePrefix + XPackSettings.SECURITY_ENABLED.getKey(); if (settings.get(tribeEnabledSetting) != null) { boolean enabled = XPackSettings.SECURITY_ENABLED.get(tribeSettings.getValue()); diff --git a/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java b/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java index 864bece20d0..7a7572262b2 100644 --- a/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java +++ b/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.discovery.zen.UnicastZenPing; +import org.elasticsearch.env.Environment; import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; @@ -31,6 +32,7 @@ import org.elasticsearch.test.NodeConfigurationSource; import org.elasticsearch.test.TestCluster; import org.elasticsearch.test.discovery.TestZenDiscovery; import org.elasticsearch.transport.MockTcpTransportPlugin; +import org.elasticsearch.tribe.TribePlugin; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.ml.MachineLearning; @@ -42,6 +44,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.function.Function; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.anyOf; @@ -71,8 +74,45 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { } @Override - protected final Collection> nodePlugins() { - return Collections.>singletonList(XPackPlugin.class); + protected boolean addTestZenDiscovery() { + return false; + } + + public static class TribeAwareTestZenDiscoveryPlugin extends TestZenDiscovery.TestPlugin { + + public TribeAwareTestZenDiscoveryPlugin(Settings settings) { + super(settings); + } + + @Override + public Settings additionalSettings() { + if (settings.getGroups("tribe", true).isEmpty()) { + return super.additionalSettings(); + } else { + return Settings.EMPTY; + } + } + } + + public static class MockTribePlugin extends TribePlugin { + + public MockTribePlugin(Settings settings) { + super(settings); + } + + protected Function nodeBuilder(Path configPath) { + return settings -> new MockNode(new Environment(settings, configPath), internalCluster().getPlugins()); + } + + } + + @Override + protected Collection> nodePlugins() { + ArrayList> plugins = new ArrayList<>(); + plugins.add(MockTribePlugin.class); + plugins.add(TribeAwareTestZenDiscoveryPlugin.class); + plugins.add(XPackPlugin.class); + return plugins; } @Override @@ -158,8 +198,8 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME) .build(); - final List> mockPlugins = Arrays.asList(TestZenDiscovery.TestPlugin.class, MockTcpTransportPlugin.class, - XPackPlugin.class); + final List> mockPlugins = Arrays.asList(MockTribePlugin.class, TribeAwareTestZenDiscoveryPlugin.class, + MockTcpTransportPlugin.class, XPackPlugin.class); final Node tribeNode = new MockNode(merged, mockPlugins).start(); Client tribeClient = tribeNode.client(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringPluginTests.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringPluginTests.java index d94777dcda6..1e697884b07 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringPluginTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringPluginTests.java @@ -8,12 +8,23 @@ package org.elasticsearch.xpack.monitoring; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.node.MockNode; +import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginInfo; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.test.discovery.TestZenDiscovery; +import org.elasticsearch.tribe.TribePlugin; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.function.Function; + import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; import static org.hamcrest.Matchers.equalTo; @@ -30,6 +41,47 @@ public class MonitoringPluginTests extends MonitoringIntegTestCase { // do nothing as monitoring is sometime unbound } + @Override + protected boolean addTestZenDiscovery() { + return false; + } + + public static class TribeAwareTestZenDiscoveryPlugin extends TestZenDiscovery.TestPlugin { + + public TribeAwareTestZenDiscoveryPlugin(Settings settings) { + super(settings); + } + + @Override + public Settings additionalSettings() { + if (settings.getGroups("tribe", true).isEmpty()) { + return super.additionalSettings(); + } else { + return Settings.EMPTY; + } + } + } + + public static class MockTribePlugin extends TribePlugin { + + public MockTribePlugin(Settings settings) { + super(settings); + } + + protected Function nodeBuilder(Path configPath) { + return settings -> new MockNode(new Environment(settings, configPath), internalCluster().getPlugins()); + } + + } + + @Override + protected Collection> nodePlugins() { + ArrayList> plugins = new ArrayList<>(super.nodePlugins()); + plugins.add(MockTribePlugin.class); + plugins.add(TribeAwareTestZenDiscoveryPlugin.class); + return plugins; + } + @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() diff --git a/plugin/src/test/java/org/elasticsearch/xpack/persistent/TestPersistentTasksPlugin.java b/plugin/src/test/java/org/elasticsearch/xpack/persistent/TestPersistentTasksPlugin.java index 432f3c9055f..218daa6f7f3 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/persistent/TestPersistentTasksPlugin.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/persistent/TestPersistentTasksPlugin.java @@ -37,6 +37,8 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptService; @@ -87,7 +89,8 @@ public class TestPersistentTasksPlugin extends Plugin implements ActionPlugin { @Override public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, - NamedXContentRegistry xContentRegistry) { + NamedXContentRegistry xContentRegistry, Environment environment, + NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) { InternalClient internalClient = new InternalClient(Settings.EMPTY, threadPool, client); PersistentTasksService persistentTasksService = new PersistentTasksService(Settings.EMPTY, clusterService, threadPool, internalClient); TestPersistentTasksExecutor testPersistentAction = new TestPersistentTasksExecutor(Settings.EMPTY, clusterService); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java b/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java index 4b5990873f7..2347288f54d 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java @@ -18,6 +18,7 @@ import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.node.MockNode; @@ -27,6 +28,8 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.NativeRealmIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; +import org.elasticsearch.test.discovery.TestZenDiscovery; +import org.elasticsearch.tribe.TribePlugin; import org.elasticsearch.xpack.security.action.role.GetRolesResponse; import org.elasticsearch.xpack.security.action.role.PutRoleResponse; import org.elasticsearch.xpack.security.action.user.PutUserResponse; @@ -37,7 +40,9 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -45,6 +50,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; +import java.util.function.Function; import java.util.function.Predicate; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @@ -82,6 +88,14 @@ public class SecurityTribeIT extends NativeRealmIntegTestCase { .put(NetworkModule.HTTP_ENABLED.getKey(), true) .build(); } + + @Override + public Collection> nodePlugins() { + ArrayList> plugins = new ArrayList<>(super.nodePlugins()); + plugins.add(MockTribePlugin.class); + plugins.add(TribeAwareTestZenDiscoveryPlugin.class); + return plugins; + } }; cluster2 = new InternalTestCluster(randomLong(), createTempDir(), true, true, 1, 2, @@ -149,6 +163,47 @@ public class SecurityTribeIT extends NativeRealmIntegTestCase { return false; } + @Override + protected boolean addTestZenDiscovery() { + return false; + } + + public static class TribeAwareTestZenDiscoveryPlugin extends TestZenDiscovery.TestPlugin { + + public TribeAwareTestZenDiscoveryPlugin(Settings settings) { + super(settings); + } + + @Override + public Settings additionalSettings() { + if (settings.getGroups("tribe", true).isEmpty()) { + return super.additionalSettings(); + } else { + return Settings.EMPTY; + } + } + } + + public static class MockTribePlugin extends TribePlugin { + + public MockTribePlugin(Settings settings) { + super(settings); + } + + protected Function nodeBuilder(Path configPath) { + return settings -> new MockNode(new Environment(settings, configPath), internalCluster().getPlugins()); + } + + } + + @Override + protected Collection> nodePlugins() { + ArrayList> plugins = new ArrayList<>(super.nodePlugins()); + plugins.add(MockTribePlugin.class); + plugins.add(TribeAwareTestZenDiscoveryPlugin.class); + return plugins; + } + private void setupTribeNode(Settings settings) throws Exception { SecuritySettingsSource cluster2SettingsSource = new SecuritySettingsSource(1, useGeneratedSSL, createTempDir(), Scope.TEST) { diff --git a/plugin/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java b/plugin/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java index 03b12a0e2b7..6c2877ff49a 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java @@ -15,10 +15,13 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.reindex.BulkByScrollResponse; import org.elasticsearch.index.reindex.ReindexAction; import org.elasticsearch.index.reindex.ReindexPlugin; @@ -112,7 +115,8 @@ public class IndexUpgradeTasksIT extends ESIntegTestCase { @Override public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, - NamedXContentRegistry xContentRegistry) { + NamedXContentRegistry xContentRegistry, Environment environment, + NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) { return Collections.singletonList(new IndexUpgradeService(settings, Collections.singletonList( new IndexUpgradeCheck("test", settings, new Function() {