Disallow creating indices starting with '-' or '+'
Previously this was possible, which was problematic when issuing a request like `DELETE /-myindex`, which was interpretted as "delete everything except for myindex". Resolves #19800
This commit is contained in:
parent
066afcf3c3
commit
6030acb43b
|
@ -144,7 +144,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
this.activeShardsObserver = new ActiveShardsObserver(settings, clusterService, threadPool);
|
||||
}
|
||||
|
||||
public void validateIndexName(String index, ClusterState state) {
|
||||
public static void validateIndexName(String index, ClusterState state) {
|
||||
if (state.routingTable().hasIndex(index)) {
|
||||
throw new IndexAlreadyExistsException(state.routingTable().index(index).getIndex());
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
if (index.contains("#")) {
|
||||
throw new InvalidIndexNameException(index, "must not contain '#'");
|
||||
}
|
||||
if (index.charAt(0) == '_') {
|
||||
throw new InvalidIndexNameException(index, "must not start with '_'");
|
||||
if (index.charAt(0) == '_' || index.charAt(0) == '-' || index.charAt(0) == '+') {
|
||||
throw new InvalidIndexNameException(index, "must not start with '_', '-', or '+'");
|
||||
}
|
||||
if (!index.toLowerCase(Locale.ROOT).equals(index)) {
|
||||
throw new InvalidIndexNameException(index, "must be lowercase");
|
||||
|
|
|
@ -257,7 +257,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
if (currentIndexMetaData == null) {
|
||||
// Index doesn't exist - create it and start recovery
|
||||
// Make sure that the index we are about to create has a validate name
|
||||
createIndexService.validateIndexName(renamedIndexName, currentState);
|
||||
MetaDataCreateIndexService.validateIndexName(renamedIndexName, currentState);
|
||||
createIndexService.validateIndexSettings(renamedIndexName, snapshotIndexMetaData.getSettings());
|
||||
IndexMetaData.Builder indexMdBuilder = IndexMetaData.builder(snapshotIndexMetaData).state(IndexMetaData.State.OPEN).index(renamedIndexName);
|
||||
indexMdBuilder.settings(Settings.builder().put(snapshotIndexMetaData.getSettings()).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()));
|
||||
|
|
|
@ -191,7 +191,9 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase {
|
|||
|
||||
validateIndexName("index#name", "must not contain '#'");
|
||||
|
||||
validateIndexName("_indexname", "must not start with '_'");
|
||||
validateIndexName("_indexname", "must not start with '_', '-', or '+'");
|
||||
validateIndexName("-indexname", "must not start with '_', '-', or '+'");
|
||||
validateIndexName("+indexname", "must not start with '_', '-', or '+'");
|
||||
|
||||
validateIndexName("INDEXNAME", "must be lowercase");
|
||||
|
||||
|
@ -201,7 +203,7 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase {
|
|||
|
||||
private void validateIndexName(String indexName, String errorMessage) {
|
||||
InvalidIndexNameException e = expectThrows(InvalidIndexNameException.class,
|
||||
() -> getCreateIndexService().validateIndexName(indexName, ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING
|
||||
() -> MetaDataCreateIndexService.validateIndexName(indexName, ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING
|
||||
.getDefault(Settings.EMPTY)).build()));
|
||||
assertThat(e.getMessage(), endsWith(errorMessage));
|
||||
}
|
||||
|
|
|
@ -49,3 +49,11 @@ CPU usage can be obtained from `OsStats.Cpu#getPercent`.
|
|||
|
||||
Suggest stats exposed through `suggest` in indices stats has been merged
|
||||
with `search` stats. `suggest` stats is exposed as part of `search` stats.
|
||||
|
||||
==== Creating indices starting with '-' or '+'
|
||||
|
||||
Elasticsearch no longer allows indices to be created started with '-' or '+', so
|
||||
that the multi-index matching and expansion is not confused. It was previously
|
||||
possible (but a really bad idea) to create indices starting with a hyphen or
|
||||
plus sign. Any index already existing with these preceding characters will
|
||||
continue to work normally.
|
||||
|
|
Loading…
Reference in New Issue