Skip to content

Commit

Permalink
Set order of tenant_template to the highest to avoid being overridden…
Browse files Browse the repository at this point in the history
… by custom templates (opensearch-project#1247) (opensearch-project#1250)

Signed-off-by: Chang Liu <[email protected]>
(cherry picked from commit dcf75c49543997e0e85dde9be314d5df81e60491)

Co-authored-by: Chang Liu <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and cliu123 authored Dec 10, 2022
1 parent 1c08cc1 commit 61f0014
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions server/multitenancy/tenant_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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*_*',
Expand Down
43 changes: 43 additions & 0 deletions server/multitenancy/test/tenant_index.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 61f0014

Please sign in to comment.