Skip to content

Commit

Permalink
Disallow : in cluster and index/alias names (#26247)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dakrone committed Aug 17, 2017
1 parent a50fe31 commit 2102b6b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/org/elasticsearch/cluster/ClusterName.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,10 +32,15 @@

public class ClusterName implements Writeable {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(ClusterName.class));

public static final Setting<ClusterName> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -165,6 +169,10 @@ public static void validateIndexOrAliasName(String index, BiFunction<String, Str
if (index.contains("#")) {
throw exceptionCtor.apply(index, "must not contain '#'");
}
if (index.contains(":")) {
deprecationLogger.deprecated("index or alias name [" + index +
"] containing ':' is deprecated and will not be supported in Elasticsearch 7.0+");
}
if (index.charAt(0) == '_' || index.charAt(0) == '-' || index.charAt(0) == '+') {
throw exceptionCtor.apply(index, "must not start with '_', '-', or '+'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public void testValidateIndexName() throws Exception {

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

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

private void validateIndexName(String indexName, String errorMessage) {
Expand Down

0 comments on commit 2102b6b

Please sign in to comment.