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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
- Fixed blank screen in Kibana 7.10.2 [#3700](https://github.com/wazuh/wazuh-kibana-app/pull/3700)

## Wazuh v4.2.4 - Kibana 7.10.2 , 7.12.1, 7.13.4, 7.14.2 - Revision 4206
Expand Down
3 changes: 1 addition & 2 deletions server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = SecurityObj(context.wazuh.plugins);
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));

Expand Down
38 changes: 26 additions & 12 deletions server/lib/security-factory/security-factory.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
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 {
export async function SecurityObj(
{ security, opendistroSecurityKibana }: PluginSetup,
context?: RequestHandlerContext
): Promise<ISecurityFactory> {
const params = {
path: `/_security/user`,
method: 'GET',
};
if (!!security) {
return new XpackFactory(security);
} else if (!!opendistroSecurityKibana) {
return new OpendistroFactory(opendistroSecurityKibana);
try {
const responseCurl = await context.core.elasticsearch.client.asInternalUser.transport.request(
params
);
return new XpackFactory(security);
} catch (error) {
return new DefaultFactory();
}
} else {
return new DefaultFactory();
return !!opendistroSecurityKibana
? new OpendistroFactory(opendistroSecurityKibana)
: new DefaultFactory();
}
}
}
5 changes: 3 additions & 2 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ 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