diff --git a/common/index.ts b/common/index.ts index 028d9d376f..d2c1120a81 100644 --- a/common/index.ts +++ b/common/index.ts @@ -49,6 +49,8 @@ export const GLOBAL_TENANT_RENDERING_TEXT = 'Global'; export const PRIVATE_TENANT_RENDERING_TEXT = 'Private'; export const globalTenantName = 'global_tenant'; +export const MAX_INTEGER = 2147483647; + export enum AuthType { BASIC = 'basicauth', OPEN_ID = 'openid', diff --git a/server/multitenancy/tenant_index.ts b/server/multitenancy/tenant_index.ts index 571ac45ce0..739de26b03 100644 --- a/server/multitenancy/tenant_index.ts +++ b/server/multitenancy/tenant_index.ts @@ -29,6 +29,7 @@ import { import { createIndexMap } from '../../../../src/core/server/saved_objects/migrations/core/build_index_map'; import { mergeTypes } from '../../../../src/core/server/saved_objects/migrations/opensearch_dashboards/opensearch_dashboards_migrator'; import { SecurityClient } from '../backend/opensearch_security_client'; +import { MAX_INTEGER } from '../../common'; export async function setupIndexTemplate( esClient: OpenSearchClient, @@ -41,6 +42,8 @@ export async function setupIndexTemplate( await esClient.indices.putTemplate({ name: 'tenant_template', body: { + // Setting order to the max value to avoid being overridden by custom templates. + order: MAX_INTEGER, index_patterns: [ opensearchDashboardsIndex + '_-*_*', opensearchDashboardsIndex + '_0*_*', diff --git a/server/multitenancy/test/tenant_index.test.ts b/server/multitenancy/test/tenant_index.test.ts new file mode 100644 index 0000000000..cc295f7875 --- /dev/null +++ b/server/multitenancy/test/tenant_index.test.ts @@ -0,0 +1,43 @@ +/* + * Copyright OpenSearch Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +import { MAX_INTEGER } from '../../../common'; + +describe('Tenant index template', () => { + const mockOpenSearchClient = { + indices: { + putTemplate: jest.fn().mockImplementation((template) => { + return template; + }), + }, + }; + + const order = MAX_INTEGER; + + it('put template', () => { + const result = mockOpenSearchClient.indices.putTemplate({ + name: 'test_index_template_a', + body: { + order, + index_patterns: 'test_index_patterns_a', + mappings: { + dynamic: 'strict', + properties: { baz: { type: 'text' } }, + }, + }, + }); + expect(result.body.order).toEqual(order); + }); +});