Skip to content

Commit 6d2a009

Browse files
committed
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
1 parent 54bc57c commit 6d2a009

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

core/src/main/java/org/elasticsearch/cluster/ClusterName.java

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.elasticsearch.common.io.stream.StreamInput;
2323
import org.elasticsearch.common.io.stream.StreamOutput;
2424
import org.elasticsearch.common.io.stream.Writeable;
25+
import org.elasticsearch.common.logging.DeprecationLogger;
26+
import org.elasticsearch.common.logging.Loggers;
2527
import org.elasticsearch.common.settings.Setting;
2628
import org.elasticsearch.common.settings.Settings;
2729

@@ -30,10 +32,15 @@
3032

3133
public class ClusterName implements Writeable {
3234

35+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(ClusterName.class));
36+
3337
public static final Setting<ClusterName> CLUSTER_NAME_SETTING = new Setting<>("cluster.name", "elasticsearch", (s) -> {
3438
if (s.isEmpty()) {
3539
throw new IllegalArgumentException("[cluster.name] must not be empty");
3640
}
41+
if (s.contains(":")) {
42+
deprecationLogger.deprecated("[cluster.name] containing ':' is deprecated and will not be supported in Elasticsearch 7.0+");
43+
}
3744
return new ClusterName(s);
3845
}, Setting.Property.NodeScope);
3946

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
import org.elasticsearch.common.compress.CompressedXContent;
5757
import org.elasticsearch.common.inject.Inject;
5858
import org.elasticsearch.common.io.PathUtils;
59+
import org.elasticsearch.common.logging.DeprecationLogger;
60+
import org.elasticsearch.common.logging.Loggers;
5961
import org.elasticsearch.common.regex.Regex;
6062
import org.elasticsearch.common.settings.IndexScopedSettings;
6163
import org.elasticsearch.common.settings.Settings;
@@ -106,6 +108,8 @@
106108
*/
107109
public class MetaDataCreateIndexService extends AbstractComponent {
108110

111+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(MetaDataCreateIndexService.class));
112+
109113
public static final int MAX_INDEX_NAME_BYTES = 255;
110114

111115
private final ClusterService clusterService;
@@ -165,6 +169,10 @@ public static void validateIndexOrAliasName(String index, BiFunction<String, Str
165169
if (index.contains("#")) {
166170
throw exceptionCtor.apply(index, "must not contain '#'");
167171
}
172+
if (index.contains(":")) {
173+
deprecationLogger.deprecated("index or alias name [" + index +
174+
"] containing ':' is deprecated and will not be supported in Elasticsearch 7.0+");
175+
}
168176
if (index.charAt(0) == '_' || index.charAt(0) == '-' || index.charAt(0) == '+') {
169177
throw exceptionCtor.apply(index, "must not start with '_', '-', or '+'");
170178
}

core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ public void testValidateIndexName() throws Exception {
212212

213213
validateIndexName("..", "must not be '.' or '..'");
214214

215+
MetaDataCreateIndexService.validateIndexName("foo:bar", ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING
216+
.getDefault(Settings.EMPTY)).build());
217+
assertWarnings("index or alias name [foo:bar] containing ':' is deprecated and will not be supported in Elasticsearch 7.0+");
215218
}
216219

217220
private void validateIndexName(String indexName, String errorMessage) {

0 commit comments

Comments
 (0)