From 906ad5ee3fc168a41a91f846f39f92f24999e5da Mon Sep 17 00:00:00 2001 From: CPAlejandro Date: Wed, 24 Nov 2021 10:39:00 +0100 Subject: [PATCH 1/7] Fixing error that shows we're using X-Pack when we have Basic --- server/controllers/wazuh-api.ts | 2 +- .../lib/security-factory/security-factory.ts | 39 ++++++++++++------- server/plugin.ts | 6 ++- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/server/controllers/wazuh-api.ts b/server/controllers/wazuh-api.ts index 275ffefaa3..134bb4b30c 100644 --- a/server/controllers/wazuh-api.ts +++ b/server/controllers/wazuh-api.ts @@ -1060,7 +1060,7 @@ export class WazuhApiCtrl { const disabledRoles = ( await getConfiguration() )['disabled_roles'] || []; const logoSidebar = ( await getConfiguration() )['customization.logo.sidebar'] || 'icon_blue.png'; - const wazuhSecurity = SecurityObj(context.wazuh.plugins); + const wazuhSecurity = await SecurityObj(context.wazuh.plugins, context); const data = (await wazuhSecurity.getCurrentUser(request, context)).authContext; const isWazuhDisabled = +(data.roles || []).some((role) => disabledRoles.includes(role)); diff --git a/server/lib/security-factory/security-factory.ts b/server/lib/security-factory/security-factory.ts index 6b3340098e..21e4cabb1f 100644 --- a/server/lib/security-factory/security-factory.ts +++ b/server/lib/security-factory/security-factory.ts @@ -1,23 +1,34 @@ import { OpendistroFactory, XpackFactory, DefaultFactory } from './factories'; import { KibanaRequest, RequestHandlerContext } from 'src/core/server'; -import { PluginSetup } from '../../types' +import { PluginSetup } from '../../types'; type CurrentUser = { - username?: string - authContext: {[key:string]: any} -} + username?: string; + authContext: { [key: string]: any }; +}; export interface ISecurityFactory { - platform?: string - getCurrentUser(request: KibanaRequest, context?:RequestHandlerContext): Promise + platform?: string; + getCurrentUser(request: KibanaRequest, context?: RequestHandlerContext): Promise; } -export function SecurityObj({security, opendistroSecurityKibana}:PluginSetup): ISecurityFactory { - if (!!security) { - return new XpackFactory(security); - } else if (!!opendistroSecurityKibana) { - return new OpendistroFactory(opendistroSecurityKibana); - } else { - return new DefaultFactory(); +export async function SecurityObj( + { security, opendistroSecurityKibana }: PluginSetup, + context?: RequestHandlerContext +): Promise { + const params = { + path: `/_security/user`, + method: 'GET', + }; + + try { + const responseCurl = await context.core.elasticsearch.client.asInternalUser.transport.request( + params + ); + } catch (error) { + return !!opendistroSecurityKibana + ? new OpendistroFactory(opendistroSecurityKibana) + : new DefaultFactory(); } -} \ No newline at end of file + return new XpackFactory(security); +} diff --git a/server/plugin.ts b/server/plugin.ts index 4215de91b3..5bbc8fdece 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -68,10 +68,12 @@ export class WazuhPlugin implements Plugin { public async setup(core: CoreSetup, plugins: PluginSetup) { this.logger.debug('Wazuh-wui: Setup'); - const wazuhSecurity = SecurityObj(plugins); + const serverInfo = core.http.getServerInfo(); - core.http.registerRouteHandlerContext('wazuh', (context, request) => { + let wazuhSecurity; + core.http.registerRouteHandlerContext('wazuh', async(context, request) => { + !wazuhSecurity && (wazuhSecurity = await SecurityObj(plugins, context)); return { logger: this.logger, server: { From 516ebc95b47532b42a126c9264faa0ce68185846 Mon Sep 17 00:00:00 2001 From: CPAlejandro Date: Wed, 24 Nov 2021 10:43:23 +0100 Subject: [PATCH 2/7] Adding Changelog.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95adae0a49..afff73343a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ All notable changes to the Wazuh app project will be documented in this file. - Fixed handler of error on dev-tools [#3687](https://github.com/wazuh/wazuh-kibana-app/pull/3687) - Fixed compatibility wazuh 4.3 - kibana 7.13.4 [#3685](https://github.com/wazuh/wazuh-kibana-app/pull/3685) - Fixed breadcrumbs style compatibility for Kibana 7.14.2 [#3688](https://github.com/wazuh/wazuh-kibana-app/pull/3688) +- Fixed error that shows we're using X-Pack when we have Basic [#3692](https://github.com/wazuh/wazuh-kibana-app/pull/3692) + ## Wazuh v4.2.4 - Kibana 7.10.2 , 7.12.1, 7.13.4, 7.14.2 - Revision 4206 From f3bad3fe7689fae0b52086f3b79bec93c497fe43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Cu=C3=A9llar=20Peinado?= Date: Wed, 24 Nov 2021 10:45:12 +0100 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afff73343a..cea3a8a319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,7 +86,6 @@ All notable changes to the Wazuh app project will be documented in this file. - Fixed breadcrumbs style compatibility for Kibana 7.14.2 [#3688](https://github.com/wazuh/wazuh-kibana-app/pull/3688) - Fixed error that shows we're using X-Pack when we have Basic [#3692](https://github.com/wazuh/wazuh-kibana-app/pull/3692) - ## Wazuh v4.2.4 - Kibana 7.10.2 , 7.12.1, 7.13.4, 7.14.2 - Revision 4206 ### Added From a9740b66343e7acf1a11d49dee4150f0402e8a11 Mon Sep 17 00:00:00 2001 From: CPAlejandro Date: Wed, 24 Nov 2021 11:08:41 +0100 Subject: [PATCH 4/7] Resolving comments --- server/controllers/wazuh-api.ts | 3 +-- server/lib/security-factory/security-factory.ts | 17 ++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/controllers/wazuh-api.ts b/server/controllers/wazuh-api.ts index 134bb4b30c..f252b5df3d 100644 --- a/server/controllers/wazuh-api.ts +++ b/server/controllers/wazuh-api.ts @@ -1060,8 +1060,7 @@ export class WazuhApiCtrl { const disabledRoles = ( await getConfiguration() )['disabled_roles'] || []; const logoSidebar = ( await getConfiguration() )['customization.logo.sidebar'] || 'icon_blue.png'; - const wazuhSecurity = await SecurityObj(context.wazuh.plugins, context); - const data = (await wazuhSecurity.getCurrentUser(request, context)).authContext; + const data = (await context.wazuh.security.getCurrentUser(request, context)).authContext; const isWazuhDisabled = +(data.roles || []).some((role) => disabledRoles.includes(role)); diff --git a/server/lib/security-factory/security-factory.ts b/server/lib/security-factory/security-factory.ts index 21e4cabb1f..89d090210f 100644 --- a/server/lib/security-factory/security-factory.ts +++ b/server/lib/security-factory/security-factory.ts @@ -20,15 +20,18 @@ export async function SecurityObj( path: `/_security/user`, method: 'GET', }; - - try { - const responseCurl = await context.core.elasticsearch.client.asInternalUser.transport.request( - params - ); - } catch (error) { + if (!!security) { + try { + const responseCurl = await context.core.elasticsearch.client.asInternalUser.transport.request( + params + ); + return new XpackFactory(security); + } catch (error) { + return new DefaultFactory(); + } + } else { return !!opendistroSecurityKibana ? new OpendistroFactory(opendistroSecurityKibana) : new DefaultFactory(); } - return new XpackFactory(security); } From ede0bbe00060b2ad3ef551dcc7dbd040887a771e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Cu=C3=A9llar=20Peinado?= Date: Wed, 24 Nov 2021 11:11:06 +0100 Subject: [PATCH 5/7] Update plugin.ts --- server/plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/plugin.ts b/server/plugin.ts index 5bbc8fdece..e7bba3e48a 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -68,7 +68,6 @@ export class WazuhPlugin implements Plugin { public async setup(core: CoreSetup, plugins: PluginSetup) { this.logger.debug('Wazuh-wui: Setup'); - const serverInfo = core.http.getServerInfo(); let wazuhSecurity; From 65619a731bc0e06a5cad6f33a21752934f72c307 Mon Sep 17 00:00:00 2001 From: CPAlejandro Date: Wed, 24 Nov 2021 14:08:46 +0100 Subject: [PATCH 6/7] Fixing run failed --- server/lib/security-factory/security-factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/security-factory/security-factory.ts b/server/lib/security-factory/security-factory.ts index 89d090210f..61272d00bd 100644 --- a/server/lib/security-factory/security-factory.ts +++ b/server/lib/security-factory/security-factory.ts @@ -34,4 +34,4 @@ export async function SecurityObj( ? new OpendistroFactory(opendistroSecurityKibana) : new DefaultFactory(); } -} +} \ No newline at end of file From c7b8b7d80566f0c39f69a767e32df164b4a0949a Mon Sep 17 00:00:00 2001 From: CPAlejandro Date: Wed, 24 Nov 2021 14:13:30 +0100 Subject: [PATCH 7/7] Test --- server/lib/security-factory/security-factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/security-factory/security-factory.ts b/server/lib/security-factory/security-factory.ts index 61272d00bd..89d090210f 100644 --- a/server/lib/security-factory/security-factory.ts +++ b/server/lib/security-factory/security-factory.ts @@ -34,4 +34,4 @@ export async function SecurityObj( ? new OpendistroFactory(opendistroSecurityKibana) : new DefaultFactory(); } -} \ No newline at end of file +}