Skip to content

Commit

Permalink
Cloud 4.2.5 7.10.2 backport (#3734)
Browse files Browse the repository at this point in the history
* doc: update default package

* Fixed compatibility wazuh 4.2 - kibana 7.13.4 (#3653)

* Fixed compatibility wazuh 4.2 - kibana 7.13.4

* Changed xDomain in elastic chart

* Added await in getSearchRequestBody

* Updated CHANGELOG

Co-authored-by: Ibarra Maximiliano <[email protected]>
Co-authored-by: Franco Charriol <[email protected]>

* Fixed interative register windows agent screen error (#3654)

* Fixed interative register windows agent screen error

* Added toLowercase

* Updated CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Ibarra Maximiliano <[email protected]>
Co-authored-by: Franco Charriol <[email protected]>

* Update CHANGELOG.md

* fix: missing async

* Fix missing import on build for kibana 7.14 (#3665)

* changed import of saved searches

* local copy of legacy/vis_update_state

* Fixed breadcrumbs style compatibility for Kibana 7.14.2 (#3668)

* Parcial breadcrumb style fix

* Improved beadcrumb styling and text overflow

* Added changelog

* Fix remove token on logout kibana 7.13 (#3670)

* Fixing EuiPannels in Overview Sections and disabled text in WzMenu (#3674)

* Fixing EuiPannels in Overview Sections

* Fixing disabled text in Wz Menu

* Fix/3673 fixing double flyout clicking in a policy (#3676)

* Fixing disabled buttons in wz menu

* Fixing double flyout

* Fixed Group Configuration and Management configuration error after trying to going back after you save (#3672)

* Solving error

* Adding Changelog.md

* Fixing bug editting user

* Fixed kibana settings conflict on health check (#3678)

* [FIX] [Compatibility] Get the valid index patterns to use in the app in Kibana 7.10.2 - 7.13.4 (#3681)

* fix(compatibility): Manage how to get the index pattern data and refresh
the fields for Kibana 7.10.2 and Kibana >=7.11.0
  - Added a function to check if the Kibana version (`kibana.version`
property of `package.json`) satisfies a specific version.
  - Modified some logic when getting the index patterns or refreshing
them to be compatible with 7.10.2 and 7.13.4. An Kibana change modified
as getting the index pattern fields.
  - Added a toast when an unknown index pattern field is detected in
Kibana >7.10.2 in Modules/<MODULE>/(Dashboard/Events) and set its life
time to 5 minutes.

Note: tested with Kibana 7.10.2 and 7.13.4 but should works in Kibana
7.11.x and 7.12.x

* changelog: Add PR to changelog

* fix(compatibility): Replaced references from 7.10.2 to 7.11 in the fixes for the compatibility to get the index pattern data and their fields and refresh them

* bump: Wazuh 4.2.5

* Replaced window location after logout

* Updated CHANGELOG

* [FIX] [TELEMETRY] Hide the banner (#3709)

* fix(telemetry): Hide the telemetry banner
  - Hide the telemetry banner from UI and set a flag in the saved object
that controls if the banner was seen and dismissed
  - Changed the `wazuh` `public` `start` method to sync intead of
`async` function

* changelog: Add PR to changelog

* fix: Add semicolon

* fix(telemetry): Hide the telemetry banner when the app frontend is to be mounted.

  Note the requirement to access to the app to hide and dissmiss the
telemetry notice. This means the banner is visible while the user
doesn't open the Wazuh app if the notice wasn't dismissed.

* [FIX] [HEALH CHECK] Fix `listValidIndexPatterns.find is not a function` error (#3698)

* fix(health-check): Fix "listValidIndexPatterns.find is not a function" error
  - Ensure the `attributes.fields` exists in the index pattern data before parsing it
  - Removed returning with error message or error in `SavedObjects.getListOfIndexPatterns` and `SavedObjects.getListOfWazuhValidIndexPatterns`

* changelog: Add PR to changelog

* added delay into request deleteToken

Co-authored-by: Franco Charriol <[email protected]>
Co-authored-by: Maximiliano Ibarra <[email protected]>
Co-authored-by: Ibarra Maximiliano <[email protected]>
Co-authored-by: Franco Charriol <[email protected]>
Co-authored-by: Federico Rodriguez <[email protected]>
Co-authored-by: Alejandro Cuéllar Peinado <[email protected]>
Co-authored-by: Antonio <[email protected]>
Co-authored-by: Matias Ezequiel Moreno <[email protected]>
Co-authored-by: Matias Ezequiel Moreno <[email protected]>
  • Loading branch information
10 people authored Dec 16, 2021
1 parent c41a6be commit f5eeb79
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 73 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to the Wazuh app project will be documented in this file.

- Support for Kibana 7.13.4
- Support for Kibana 7.14.2
- Hide the `telemetry` banner [#3709](https://github.com/wazuh/wazuh-kibana-app/pull/3709)

### Fixed

Expand All @@ -20,6 +21,8 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixing double flyout clicking in a policy [#3676](https://github.com/wazuh/wazuh-kibana-app/pull/3676)
- Fixed error conflict setting kibana settings from the health check [#3678](https://github.com/wazuh/wazuh-kibana-app/pull/3678)
- Fixed compatibility to get the valid index patterns and refresh fields for Kibana 7.10.2-7.13.4 [3681](https://github.com/wazuh/wazuh-kibana-app/pull/3681)
- Fixed wrong redirect after login [3701](https://github.com/wazuh/wazuh-kibana-app/pull/3701)
- Fixed error getting the index pattern data when there is not `attributes.fields` in the saved object [3689](https://github.com/wazuh/wazuh-kibana-app/pull/3698)

## Wazuh v4.2.4 - Kibana 7.10.2, 7.11.2, 7.12.1 - Revision 4205

Expand Down Expand Up @@ -163,7 +166,6 @@ All notable changes to the Wazuh app project will be documented in this file.

- Conflict with the creation of the index pattern when performing the Health Check [#3223](https://github.com/wazuh/wazuh-kibana-app/pull/3223)
- Fixing mac os agents add command [#3207](https://github.com/wazuh/wazuh-kibana-app/pull/3207)

## Wazuh v4.1.5 - Kibana 7.10.0 , 7.10.2 - Revision 4106

- Adapt for Wazuh 4.1.5
Expand Down
4 changes: 2 additions & 2 deletions kibana.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"id": "wazuh",

"version": "4.2.5-4206-1",
"kibanaVersion": "kibana",
"configPath": [
Expand All @@ -18,7 +17,8 @@
"savedObjects",
"kibanaReact",
"kibanaUtils",
"securityOss"
"securityOss",
"telemetry"
],
"optionalPlugins": [
"security",
Expand Down
5 changes: 3 additions & 2 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ app.run([
* Set trigger for logout
*/
app.run(function ($rootElement) {
$rootElement.append(`
$rootElement.append(`
<div>
<div class="wazuhNotReadyYet"></div>
<div ng-view class="mainView"></div>
Expand All @@ -111,6 +111,7 @@ app.run(function ($rootElement) {
// Add plugin help links as extension to Kibana help menu
addHelpMenuToAppChrome();


const urlToLogout = window.location.origin + '/logout';

// Bind deleteExistentToken on Log out component.
Expand All @@ -129,7 +130,7 @@ app.run(function ($rootElement) {
console.error('[ERROR] - User token could not be deprecated - ', err);
})
.finally(() => {
window.location.replace(urlToLogout);
window.location = urlToLogout;
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const checkIndexPatternObjectService = async (appConfig, checkLogger: Ch
// show error
checkLogger.error(`Default index pattern not found`);
}
checkLogger.info(`Getting list of valid index patterns [${patternId}]...`);
checkLogger.info(`Getting list of valid index patterns...`);
listValidIndexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns(defaultIndexPatterns, HEALTH_CHECK);
checkLogger.info(`Valid index patterns found: ${listValidIndexPatterns.length || 0}`);
if(!AppState.getCurrentPattern()){
Expand Down
8 changes: 3 additions & 5 deletions public/controllers/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,9 @@ export class SettingsController {
// Get settings function
async getSettings() {
try {
const patternList = await SavedObject.getListOfWazuhValidIndexPatterns();

this.indexPatterns = patternList;

if (!this.indexPatterns.length) {
try{
this.indexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns();
}catch(error){
this.wzMisc.setBlankScr('Sorry but no valid index patterns were found');
this.$location.search('tab', null);
this.$location.path('/blank-screen');
Expand Down
14 changes: 12 additions & 2 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
public initializeInnerAngular?: () => void;
private innerAngularInitialized: boolean = false;
private stateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private hideTelemetryBanner?: () => void;

public setup(core: CoreSetup, plugins: WazuhSetupPlugins): WazuhSetup {

Expand All @@ -56,6 +57,11 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
if (!this.initializeInnerAngular) {
throw Error('Wazuh plugin method initializeInnerAngular is undefined');
}

// hide the telemetry banner.
// Set the flag in the telemetry saved object as the notice was seen and dismissed
this.hideTelemetryBanner && await this.hideTelemetryBanner();

setScopedHistory(params.history);
// Load application bundle
const { renderApp } = await import('./application');
Expand Down Expand Up @@ -105,12 +111,16 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
return {};
}

public async start(core: CoreStart, plugins: AppPluginStartDependencies): Promise<WazuhStart> {
public start(core: CoreStart, plugins: AppPluginStartDependencies): WazuhStart {
// hide security alert
if (plugins.securityOss) {
plugins.securityOss.insecureCluster.hideAlert(true);
}
};

if(plugins?.telemetry?.telemetryNotifications?.setOptedInNoticeSeen) {
// assign to a method to hide the telemetry banner used when the app is mounted
this.hideTelemetryBanner = () => plugins.telemetry.telemetryNotifications.setOptedInNoticeSeen();
};
// we need to register the application service at setup, but to render it
// there are some start dependencies necessary, for this reason
// initializeInnerAngular + initializeServices are assigned at start and used
Expand Down
96 changes: 38 additions & 58 deletions public/react-services/saved-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,30 @@ export class SavedObject {
* Returns the full list of index patterns
*/
static async getListOfIndexPatterns() {
try {
const savedObjects = await GenericRequest.request(
'GET',
`/api/saved_objects/_find?type=index-pattern&fields=title&fields=fields&per_page=9999`
const savedObjects = await GenericRequest.request(
'GET',
`/api/saved_objects/_find?type=index-pattern&fields=title&fields=fields&per_page=9999`
);
let indexPatterns = ((savedObjects || {}).data || {}).saved_objects || [];

let indexPatternsFields;
if(satisfyKibanaVersion('<7.11')){
indexPatternsFields = indexPatterns.map(indexPattern => JSON.parse(indexPattern.attributes.fields));
}else if(satisfyKibanaVersion('>=7.11')){
indexPatternsFields = await Promise.all(indexPatterns.map(async indexPattern => {
try{
const {data: {fields}} = await GenericRequest.request(
'GET',
`/api/index_patterns/_fields_for_wildcard?pattern=${indexPattern.attributes.title}`,
{}
);
return fields;
}catch(error){
return [];
}
}));
}
return indexPatterns.map((indexPattern, idx) => ({...indexPattern, _fields: indexPatternsFields[idx]}));
} catch (error) {
return ((error || {}).data || {}).message || false
? error.data.message
: error.message || error;
let indexPatternsFields;
if(satisfyKibanaVersion('<7.11')){
indexPatternsFields = indexPatterns.map(indexPattern => indexPattern?.attributes?.fields ? JSON.parse(indexPattern.attributes.fields) : []);
}else if(satisfyKibanaVersion('>=7.11')){
indexPatternsFields = await Promise.all(indexPatterns.map(async indexPattern => {
try{
const {data: {fields}} = await GenericRequest.request(
'GET',
`/api/index_patterns/_fields_for_wildcard?pattern=${indexPattern.attributes.title}`,
{}
);
return fields;
}catch(error){
return [];
}
}));
}
return indexPatterns.map((indexPattern, idx) => ({...indexPattern, _fields: indexPatternsFields[idx]}));
}

/**
Expand All @@ -66,30 +60,24 @@ export class SavedObject {
* An index is valid if its fields contain at least these 4 fields: 'timestamp', 'rule.groups', 'agent.id' and 'manager.name'
*/
static async getListOfWazuhValidIndexPatterns(defaultIndexPatterns, where) {
try {
let result = [];
if (where === HEALTH_CHECK) {
const list = await Promise.all(
defaultIndexPatterns.map(
async (pattern) => await SavedObject.getExistingIndexPattern(pattern)
)
);
result = this.validateIndexPatterns(list);
}

if (!result.length) {
const list = await this.getListOfIndexPatterns();
result = this.validateIndexPatterns(list);
}
let result = [];
if (where === HEALTH_CHECK) {
const list = await Promise.all(
defaultIndexPatterns.map(
async (pattern) => await SavedObject.getExistingIndexPattern(pattern)
)
);
result = this.validateIndexPatterns(list);
}

return result.map((item) => {
return { id: item.id, title: item.attributes.title };
});
} catch (error) {
return ((error || {}).data || {}).message || false
? error.data.message
: error.message || error;
if (!result.length) {
const list = await this.getListOfIndexPatterns();
result = this.validateIndexPatterns(list);
}

return result.map((item) => {
return { id: item.id, title: item.attributes.title };
});
}

static validateIndexPatterns(list) {
Expand All @@ -99,12 +87,7 @@ export class SavedObject {
'manager.name',
'agent.id',
];
return list.filter(item => {
if (item._fields) {
return requiredFields.every((reqField => item._fields.some(field => field.name === reqField)));
}
return false;
});
return list.filter(item => item && item._fields && requiredFields.every((reqField => item._fields.some(field => field.name === reqField))));
}

static async existsOrCreateIndexPattern(patternID) {
Expand Down Expand Up @@ -172,7 +155,7 @@ export class SavedObject {
);
let indexPatternFields;
if(satisfyKibanaVersion('<7.11')){
indexPatternFields = JSON.parse(indexPatternData.data.attributes.fields);
indexPatternFields = indexPatternData?.data?.attributes?.fields ? JSON.parse(indexPatternData.data.attributes.fields) : [];
}else if(satisfyKibanaVersion('>=7.11')){
try{
const {data: {fields}} = await GenericRequest.request(
Expand Down Expand Up @@ -227,7 +210,6 @@ export class SavedObject {
},
}
);
return;
} catch (error) {
return ((error || {}).data || {}).message || false
? error.data.message
Expand All @@ -249,8 +231,6 @@ export class SavedObject {
});

await this.refreshFieldsOfIndexPattern(pattern.id, pattern.title, fields);

return;
} catch (error) {
console.log(error)
return ((error || {}).data || {}).message || false
Expand Down
2 changes: 1 addition & 1 deletion public/react-services/wz-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class WzAuthentication {
*/
static async deleteExistentToken() {
try {
const response = await WzRequest.apiReq('DELETE', '/security/user/authenticate', {});
const response = await WzRequest.apiReq('DELETE', '/security/user/authenticate', {delay: 5000});

return ((response || {}).data || {}).data || {};
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/pub
import { UiActionsSetup } from '../../../src/plugins/ui_actions/public';
import { SecurityOssPluginStart } from '../../../src/plugins/security_oss/public/';
import { SavedObjectsStart } from '../../../src/plugins/saved_objects/public';
import { TelemetryPluginStart, TelemetryPluginSetup } from '../../../src/plugins/telemetry/public';

export interface AppPluginStartDependencies {
navigation: NavigationPublicPluginStart;
Expand All @@ -15,7 +16,8 @@ export interface AppPluginStartDependencies {
discover: DiscoverStart;
charts: ChartsPluginStart
securityOss: SecurityOssPluginStart,
savedObjects: SavedObjectsStart
savedObjects: SavedObjectsStart,
telemetry: TelemetryPluginStart
}
export interface AppDependencies {
core: CoreStart;
Expand All @@ -28,6 +30,7 @@ export type WazuhSetupPlugins = {
visualizations: VisualizationsSetup;
data: DataPublicPluginSetup;
navigation: NavigationPublicPluginStart;
telemetry: TelemetryPluginSetup;
}

export type WazuhStartPlugins = AppPluginStartDependencies;
Expand Down

0 comments on commit f5eeb79

Please sign in to comment.