Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kibana system index does not allow user templates to affect it #98696

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class KibanaPlugin extends Plugin implements SystemIndexPlugin {
.setAliasName(".kibana")
.setType(Type.EXTERNAL_UNMANAGED)
.setAllowedElasticProductOrigins(KIBANA_PRODUCT_ORIGIN)
.setAllowsTemplates()
.build();

public static final SystemIndexDescriptor REPORTING_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public abstract class AbstractFeatureMigrationIntegTest extends ESIntegTestCase
static final int EXTERNAL_UNMANAGED_FLAG_VALUE = 4;
static final String ASSOCIATED_INDEX_NAME = ".my-associated-idx";

public static final SystemIndexDescriptor KIBANA_MOCK_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder()
.setIndexPattern(".kibana_*")
.setDescription("Kibana saved objects system index")
.setAliasName(".kibana")
public static final SystemIndexDescriptor ALLOW_TEMPLATES_MOCK_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder()
.setIndexPattern(".allow_templates_*")
.setDescription("A system index that allows user templates")
.setAliasName(".allow_templates")
.setType(SystemIndexDescriptor.Type.EXTERNAL_UNMANAGED)
.setAllowedElasticProductOrigins(Collections.emptyList())
.setAllowedElasticProductOrigins(Collections.singletonList(ORIGIN))
Expand Down Expand Up @@ -281,7 +281,13 @@ public String getFeatureDescription() {

@Override
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) {
return Arrays.asList(INTERNAL_MANAGED, INTERNAL_UNMANAGED, EXTERNAL_MANAGED, EXTERNAL_UNMANAGED, KIBANA_MOCK_INDEX_DESCRIPTOR);
return Arrays.asList(
INTERNAL_MANAGED,
INTERNAL_UNMANAGED,
EXTERNAL_MANAGED,
EXTERNAL_UNMANAGED,
ALLOW_TEMPLATES_MOCK_INDEX_DESCRIPTOR
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ public void testBailOnMigrateWithTemplatesV1() throws Exception {
}

public void testMigrateWithTemplatesV1() throws Exception {
// this should pass for both, kibana allows templates, the unmanaged doesn't match the template
migrateWithTemplatesV1(".kibana", KIBANA_MOCK_INDEX_DESCRIPTOR, INTERNAL_UNMANAGED);
// this should pass for both, the first allows templates, the second INTERNAL_UNMANAGED doesn't match the template
migrateWithTemplatesV1(".allow_templates", ALLOW_TEMPLATES_MOCK_INDEX_DESCRIPTOR, INTERNAL_UNMANAGED);

assertBusy(() -> {
GetFeatureUpgradeStatusResponse statusResp = client().execute(
Expand Down Expand Up @@ -442,8 +442,8 @@ public void testBailOnMigrateWithTemplatesV2() throws Exception {
}

public void testMigrateWithTemplatesV2() throws Exception {
// this should pass for both, kibana allows templates, the unmanaged doesn't match the template
migrateWithTemplatesV2(".kibana", KIBANA_MOCK_INDEX_DESCRIPTOR, INTERNAL_UNMANAGED);
// this should pass for both, the first allows templates, the second INTERNAL_UNMANAGED doesn't match the template
migrateWithTemplatesV2(".allow_templates", ALLOW_TEMPLATES_MOCK_INDEX_DESCRIPTOR, INTERNAL_UNMANAGED);

assertBusy(() -> {
GetFeatureUpgradeStatusResponse statusResp = client().execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable<Sy
private final boolean isNetNew;

/**
* We typically don't want to apply user defined templates on system indices, since they may have unexpected
* behaviour when upgrading Elasticsearch versions. Currently, only the .kibana_ indices use templates, so we
* are making this property by default as false.
* Defaults to false as we typically don't want to apply user defined templates on system indices, since they may have unexpected
* behaviour when upgrading Elasticsearch versions.
*/
private final boolean allowsTemplates;

Expand Down Expand Up @@ -208,7 +207,7 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable<Sy
* indices
* @param priorSystemIndexDescriptors A list of system index descriptors that describe the same index in a way that is compatible with
* older versions of Elasticsearch
* @param allowsTemplates if this system index descriptor allows templates to affect its settings (e.g. .kibana_ indices)
* @param allowsTemplates if this system index descriptor allows templates to affect its settings
*/
protected SystemIndexDescriptor(
String indexPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private void migrateSingleIndex(ClusterState clusterState, Consumer<BulkByScroll
String newIndexName = migrationInfo.getNextIndexName();

/**
* This should be on for all System indices except for .kibana_ indices. See allowsTemplates in KibanaPlugin.java for more info.
* This is on for all system indices except when the system index explicitly opts out
*/
if (migrationInfo.allowsTemplates() == false) {
final String v2template = MetadataIndexTemplateService.findV2Template(clusterState.metadata(), newIndexName, false);
Expand Down