From b05ad20cba37db01fa67044b864964a7c69a7e2f Mon Sep 17 00:00:00 2001 From: Giuseppe Santoro Date: Mon, 22 May 2023 12:49:06 +0100 Subject: [PATCH] Add flags to give permissions to write to any dataset and namespace (#157897) Add flags to give permissions to reroute events from an input package to other datastreams with the same type but different dataset and namespace. ``` elasticsearch.dynamic_dataset: true elasticsearch.dynamic_namespace: true, ``` --- .../fleet/common/services/policy_template.test.ts | 4 ++++ .../plugins/fleet/common/services/policy_template.ts | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/common/services/policy_template.test.ts b/x-pack/plugins/fleet/common/services/policy_template.test.ts index 7e8212b62d38a..078dac911f842 100644 --- a/x-pack/plugins/fleet/common/services/policy_template.test.ts +++ b/x-pack/plugins/fleet/common/services/policy_template.test.ts @@ -229,6 +229,10 @@ describe('getNormalizedDataStreams', () => { { type: 'foo', dataset: 'nginx.bar', + elasticsearch: { + dynamic_dataset: true, + dynamic_namespace: true, + }, title: expect.any(String), release: 'ga', package: 'nginx', diff --git a/x-pack/plugins/fleet/common/services/policy_template.ts b/x-pack/plugins/fleet/common/services/policy_template.ts index 7ca16850e5008..717e020fc3259 100644 --- a/x-pack/plugins/fleet/common/services/policy_template.ts +++ b/x-pack/plugins/fleet/common/services/policy_template.ts @@ -87,7 +87,7 @@ export const getNormalizedDataStreams = ( release: packageInfo.release || 'ga', package: packageInfo.name, path: packageInfo.name, - elasticsearch: packageInfo.elasticsearch, + elasticsearch: packageInfo.elasticsearch || {}, streams: [ { input: policyTemplate.input, @@ -100,6 +100,16 @@ export const getNormalizedDataStreams = ( ], }; + if (packageInfo.type === 'input') { + dataStream.elasticsearch = { + ...dataStream.elasticsearch, + ...{ + dynamic_dataset: true, + dynamic_namespace: true, + }, + }; + } + return dataStream; }); };