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

Changed user for sample data management #3795

Merged
merged 5 commits into from
Jan 13, 2022
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 @@ -65,6 +65,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Testing logs using the Ruletest Test don't display the rule information if not matching a rule. [#3446](https://github.com/wazuh/wazuh-kibana-app/pull/3446)
- Changed format permissions in FIM inventory [#3649](https://github.com/wazuh/wazuh-kibana-app/pull/3649)
- Changed of request for one that does not return data that is not necessary to optimize times. [#3686](https://github.com/wazuh/wazuh-kibana-app/pull/3686) [#3728](https://github.com/wazuh/wazuh-kibana-app/pull/3728)
- Changed user for sample data management [#3795](https://github.com/wazuh/wazuh-kibana-app/pull/3795)
- Changed agent install codeblock copy button and powershell terminal warning [#3792](https://github.com/wazuh/wazuh-kibana-app/pull/3792)

### Fixed
Expand Down
24 changes: 16 additions & 8 deletions public/components/add-modules-data/sample-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import React, { Component, Fragment } from 'react';
import { WzButtonPermissions } from '../../components/common/permissions/button';

import { EuiFlexItem, EuiCard, EuiFlexGrid, EuiFlexGroup } from '@elastic/eui';
import { EuiFlexItem, EuiCard, EuiFlexGrid, EuiFlexGroup, EuiCallOut, EuiSpacer } from '@elastic/eui';

import { getToasts } from '../../kibana-services';
import { WzRequest } from '../../react-services/wz-request';
Expand Down Expand Up @@ -70,6 +70,7 @@ export default class WzSampleData extends Component {
exists: false,
addDataLoading: false,
removeDataLoading: false,
havePermissions: false
};
});
}
Expand Down Expand Up @@ -127,7 +128,7 @@ export default class WzSampleData extends Component {
error: {
error: error,
message: error.message || error,
title: error.name || error,
title: 'Error checking sample data',
},
};
getErrorOrchestrator().handleError(options);
Expand Down Expand Up @@ -175,7 +176,7 @@ export default class WzSampleData extends Component {
error: {
error: error,
message: error.message || error,
title: `${error.name}: Error trying to add sample data`,
title: `Error trying to add sample data`,
},
};
getErrorOrchestrator().handleError(options);
Expand Down Expand Up @@ -215,7 +216,7 @@ export default class WzSampleData extends Component {
error: {
error: error,
message: error.message || error,
title: `${error.name}: Error trying to delete sample data`,
title: `Error trying to delete sample data`,
},
};
getErrorOrchestrator().handleError(options);
Expand Down Expand Up @@ -267,9 +268,16 @@ export default class WzSampleData extends Component {
}
render() {
return (
<EuiFlexGrid columns={3}>
{this.categories.map((category) => this.renderCard(category))}
</EuiFlexGrid>
<>
<EuiCallOut
title="These actions require permissions on the managed indices."
iconType="iInCircle"
/>
<EuiSpacer />
<EuiFlexGrid columns={3}>
{this.categories.map((category) => this.renderCard(category))}
</EuiFlexGrid>
</>
);
}
}
Expand All @@ -292,5 +300,5 @@ const PromiseAllRecursiveObject = function (obj) {
}
return value;
})
).then((result) => zipObject(keys, result));
).then((result) => zipObject(keys, result))
};
30 changes: 24 additions & 6 deletions server/controllers/wazuh-elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,9 @@ export class WazuhElasticCtrl {
'wazuh-elastic:haveSampleAlertsOfCategory',
`Error checking if there are sample alerts indices: ${error.message || error}`
);
return ErrorResponse(`Error checking if there are sample alerts indices: ${error.message || error}`, 1000, 500, response);

const [statusCode, errorMessage] = this.getErrorDetails(error);
return ErrorResponse(`Error checking if there are sample alerts indices: ${errorMessage || error}`, 1000, statusCode, response);
}
}
/**
Expand Down Expand Up @@ -705,7 +707,7 @@ export class WazuhElasticCtrl {
// Index alerts

// Check if wazuh sample alerts index exists
const existsSampleIndex = await context.core.elasticsearch.client.asInternalUser.indices.exists({
const existsSampleIndex = await context.core.elasticsearch.client.asCurrentUser.indices.exists({
index: sampleAlertsIndex
});
if (!existsSampleIndex.body) {
Expand All @@ -720,7 +722,7 @@ export class WazuhElasticCtrl {
}
};

await context.core.elasticsearch.client.asInternalUser.indices.create({
await context.core.elasticsearch.client.asCurrentUser.indices.create({
index: sampleAlertsIndex,
body: configuration
});
Expand All @@ -731,7 +733,7 @@ export class WazuhElasticCtrl {
);
}

await context.core.elasticsearch.client.asInternalUser.bulk({
await context.core.elasticsearch.client.asCurrentUser.bulk({
index: sampleAlertsIndex,
body: bulk
});
Expand All @@ -748,7 +750,10 @@ export class WazuhElasticCtrl {
'wazuh-elastic:createSampleAlerts',
`Error adding sample alerts to ${sampleAlertsIndex} index: ${error.message || error}`
);
return ErrorResponse(error.message || error, 1000, 500, response);

const [statusCode, errorMessage] = this.getErrorDetails(error);

return ErrorResponse(errorMessage || error, 1000, statusCode, response);
}
}
/**
Expand Down Expand Up @@ -809,7 +814,9 @@ export class WazuhElasticCtrl {
'wazuh-elastic:deleteSampleAlerts',
`Error deleting sample alerts of ${sampleAlertsIndex} index: ${error.message || error}`
);
return ErrorResponse(error.message || error, 1000, 500, response);
const [statusCode, errorMessage] = this.getErrorDetails(error);

return ErrorResponse(errorMessage || error, 1000, statusCode, response);
}
}

Expand Down Expand Up @@ -853,4 +860,15 @@ export class WazuhElasticCtrl {
return Promise.reject(error);
}
};

getErrorDetails(error){
const statusCode = error?.meta?.statusCode || 500;
let errorMessage = error.message;

if(statusCode === 403){
errorMessage = error?.meta?.body?.error?.reason || 'Permission denied';
}

return [statusCode, errorMessage];
}
}