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

Fixing error that shows we're using X-Pack when we have Basic #3692

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ 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

Expand Down
2 changes: 1 addition & 1 deletion server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: use the context.wazuh.security instead of create another security object.

const data = (await wazuhSecurity.getCurrentUser(request, context)).authContext;

const isWazuhDisabled = +(data.roles || []).some((role) => disabledRoles.includes(role));
Expand Down
39 changes: 25 additions & 14 deletions server/lib/security-factory/security-factory.ts
Original file line number Diff line number Diff line change
@@ -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<CurrentUser>
platform?: string;
getCurrentUser(request: KibanaRequest, context?: RequestHandlerContext): Promise<CurrentUser>;
}

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<ISecurityFactory> {
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();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: The request to check if X-Pack is enabled should be done only if security plugin is installed.

}
return new XpackFactory(security);
}
6 changes: 4 additions & 2 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
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: {
Expand Down