Skip to content

Commit

Permalink
Fix creating PDF reports in x-pack without authentication context (#4358
Browse files Browse the repository at this point in the history
)

* Added default hashUsername to xpack without authContext

* changelog: add PR entry

Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
Co-authored-by: Antonio <34042064+Desvelao@users.noreply.github.com>
(cherry picked from commit 72af12c)
  • Loading branch information
asteriscos authored and github-actions[bot] committed Aug 4, 2022
1 parent 7564f72 commit 59ed124
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Fixed

- Fixed path in logo customization section [#4352](https://github.com/wazuh/wazuh-kibana-app/pull/4352)
- Fixed an error of an undefined username hash related to reporting when using Kibana with X-Pack and security was disabled [#4358](https://github.com/wazuh/wazuh-kibana-app/pull/4358)

## Wazuh v4.3.6 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4307

Expand Down
3 changes: 3 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,6 @@ export const UI_ORDER_AGENT_STATUS = [

// Documentation
export const DOCUMENTATION_WEB_BASE_URL = "https://documentation.wazuh.com";

// Default Elasticsearch user name context
export const ELASTIC_NAME = 'elastic';
7 changes: 4 additions & 3 deletions server/lib/security-factory/factories/default-factory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ISecurityFactory } from '../';
import { ELASTIC_NAME } from '../../../../common/constants';
import { KibanaRequest, RequestHandlerContext } from 'src/core/server';
import md5 from 'md5';

export class DefaultFactory implements ISecurityFactory{
platform: string = '';
async getCurrentUser(request: KibanaRequest, context?:RequestHandlerContext) {
return {
username: 'elastic',
authContext: { username: 'elastic' },
hashUsername: md5('elastic')
username: ELASTIC_NAME,
authContext: { username: ELASTIC_NAME },
hashUsername: md5(ELASTIC_NAME)
};
}
}
4 changes: 2 additions & 2 deletions server/lib/security-factory/factories/xpack-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ISecurityFactory } from '../'
import { SecurityPluginSetup } from 'x-pack/plugins/security/server';
import { KibanaRequest } from 'src/core/server';
import { WAZUH_SECURITY_PLUGIN_XPACK_SECURITY } from '../../../../common/constants';
import { WAZUH_SECURITY_PLUGIN_XPACK_SECURITY, ELASTIC_NAME } from '../../../../common/constants';
import md5 from 'md5';

export class XpackFactory implements ISecurityFactory {
Expand All @@ -11,7 +11,7 @@ export class XpackFactory implements ISecurityFactory {
async getCurrentUser(request: KibanaRequest) {
try {
const authContext = await this.security.authc.getCurrentUser(request);
if(!authContext) return {username: 'elastic', authContext: { username: 'elastic'}};
if(!authContext) return {hashUsername: md5(ELASTIC_NAME), username: ELASTIC_NAME, authContext: { username: ELASTIC_NAME}};
const username = this.getUserName(authContext);
return { username, authContext, hashUsername: md5(username) };
} catch (error) {
Expand Down

0 comments on commit 59ed124

Please sign in to comment.