From 2102b6b2dcfe1f445f78ce6367a72ce552375eeb Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 17 Aug 2017 14:57:26 -0600 Subject: [PATCH] Disallow : in cluster and index/alias names (#26247) We use `:` for cross-cluster search (eg `cluster:index`), therefore, we should not allow the ambiguity when allowing cluster or index names. Relates to #23892 --- .../main/java/org/elasticsearch/cluster/ClusterName.java | 7 +++++++ .../cluster/metadata/MetaDataCreateIndexService.java | 8 ++++++++ .../cluster/metadata/MetaDataCreateIndexServiceTests.java | 3 +++ 3 files changed, 18 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterName.java b/core/src/main/java/org/elasticsearch/cluster/ClusterName.java index 36676300954e7..720d81d82c0a3 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterName.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterName.java @@ -22,6 +22,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -30,10 +32,15 @@ public class ClusterName implements Writeable { + private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(ClusterName.class)); + public static final Setting CLUSTER_NAME_SETTING = new Setting<>("cluster.name", "elasticsearch", (s) -> { if (s.isEmpty()) { throw new IllegalArgumentException("[cluster.name] must not be empty"); } + if (s.contains(":")) { + deprecationLogger.deprecated("[cluster.name] containing ':' is deprecated and will not be supported in Elasticsearch 7.0+"); + } return new ClusterName(s); }, Setting.Property.NodeScope); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index 07a97b4f320cb..b76d6d758d6a1 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -56,6 +56,8 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; @@ -106,6 +108,8 @@ */ public class MetaDataCreateIndexService extends AbstractComponent { + private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(MetaDataCreateIndexService.class)); + public static final int MAX_INDEX_NAME_BYTES = 255; private final ClusterService clusterService; @@ -165,6 +169,10 @@ public static void validateIndexOrAliasName(String index, BiFunction