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

[Fix] Wrong permissions on edit CDB #2665

Merged
merged 23 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3c825c5
Added new action and reducer to get status and context of server (clu…
gabiwassan Nov 27, 2020
23b6f1e
Added new method isClusterOrManager to get cluster status, set on red…
gabiwassan Nov 27, 2020
f2188c9
Fixed and replaced all permissions by contextConfigServer (cluster or…
gabiwassan Nov 27, 2020
acbb51c
Rollback, wrong change.
gabiwassan Nov 27, 2020
f1420b8
Request changes of validation null properties.
gabiwassan Nov 27, 2020
4ed8732
Added initial state of clusterStatus
gabiwassan Nov 27, 2020
f689408
Moved method isClusterOrManager to management-main.js to distribute t…
gabiwassan Nov 30, 2020
9cd4472
Fixed permissions to edit and export to csv.
gabiwassan Dec 1, 2020
5715e9c
Fixed permissions for manager or cluster. Added on wz-user-permission…
gabiwassan Dec 3, 2020
00eeacf
Merge branch '4.0-7.9' into fix/2657-wrong-permissions-on-edit-cdb
gabiwassan Dec 3, 2020
20ce83a
Changed to const permissions declaration.
gabiwassan Dec 3, 2020
80aa117
Merge remote-tracking branch 'origin/fix/2657-wrong-permissions-on-ed…
gabiwassan Dec 3, 2020
b81b69d
Fixed user-permissions to support cominations of resources with &. Re…
gabiwassan Dec 4, 2020
129753e
Refactor Withe and Black mode. (juts simplify code)
gabiwassan Dec 4, 2020
3474127
Fixed typo error
gabiwassan Dec 4, 2020
191d3f6
Fixed errors detected on PR.
gabiwassan Dec 10, 2020
e6f95a6
Removed unnecessary request, to update list content, we have this val…
gabiwassan Dec 11, 2020
a611ff6
First commit scaffolding test wz-users-permissions
gabiwassan Dec 11, 2020
c793aaf
Fixed mock of userPermissions and requiredPermissions
gabiwassan Dec 11, 2020
754c5b5
Implemented a basic suite of test for wz-user-permissions.ts
gabiwassan Dec 11, 2020
6448c21
Removed import.
gabiwassan Dec 11, 2020
e8dd674
Added header Wazuh Copyright.
gabiwassan Dec 15, 2020
0c6be16
Added CHANGELOG.md
gabiwassan Dec 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import WzReporting from './reporting/reporting-main';
import WzConfiguration from './configuration/configuration-main';
import WzStatistics from './statistics/statistics-main';
import { connect } from 'react-redux';
import { clusterReq } from './configuration/utils/wz-fetch';
import { updateClusterStatus } from '../../../../redux/actions/appStateActions';

class WzManagementMain extends Component {
constructor(props) {
Expand All @@ -37,6 +39,33 @@ class WzManagementMain extends Component {
store.dispatch(updateRulesetSection(''));
}

componentDidMount() {
this.isClusterOrManager();
}

isClusterOrManager = async () => {
try {
const clusterStatus = await clusterReq();
if (clusterStatus.data.data.enabled === 'yes' && clusterStatus.data.data.running === 'yes') {
this.props.updateClusterStatus({
status: true,
contextConfigServer: 'cluster',
});
} else {
this.props.updateClusterStatus({
status: false,
contextConfigServer: 'manager',
});
}
} catch (error) {
console.warn(`Error when try to get cluster status`, error);
this.props.updateClusterStatus({
status: false,
contextConfigServer: 'manager',
});
}
};

render() {
const { section } = this.props;
const ruleset = ['ruleset', 'rules', 'decoders', 'lists'];
Expand All @@ -48,26 +77,24 @@ class WzManagementMain extends Component {
(section === 'statistics' && <WzStatistics />) ||
(section === 'logs' && <WzLogs />) ||
(section === 'configuration' && <WzConfiguration {...this.props.configurationProps} />) ||
(ruleset.includes(section) && <WzRuleset />)
}
(ruleset.includes(section) && <WzRuleset clusterStatus={this.props.clusterStatus} />)}
</Fragment>
);
}
}

function mapStateToProps(state) {
return {
state: state.managementReducers
state: state.managementReducers,
clusterStatus: state.appStateReducers.clusterStatus,
};
}

const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch) => {
return {
updateRulesetSection: section => dispatch(updateRulesetSection(section))
updateRulesetSection: (section) => dispatch(updateRulesetSection(section)),
updateClusterStatus: (clusterStatus) => dispatch(updateClusterStatus(clusterStatus)),
};
};

export default connect(
mapStateToProps,
mapDispatchToProps
)(WzManagementMain);
export default connect(mapStateToProps, mapDispatchToProps)(WzManagementMain);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
import React, { Component, Fragment } from 'react';
// Eui components
import { EuiFlexItem, EuiButtonEmpty, EuiGlobalToastList } from '@elastic/eui';
import { EuiFlexItem, EuiButtonEmpty } from '@elastic/eui';
import { toastNotifications } from 'ui/notify';

import { connect } from 'react-redux';
Expand All @@ -22,11 +22,10 @@ import {
updteAddingRulesetFile,
updateListContent,
updateIsProcessing,
updatePageIndex
updatePageIndex,
} from '../../../../../redux/actions/rulesetActions';

import { WzRequest } from '../../../../../react-services/wz-request';
import { ErrorHandler } from '../../../../../react-services/error-handler';
import exportCsv from '../../../../../react-services/wz-csv';
import { UploadFiles } from '../../upload-files';
import columns from './utils/columns';
Expand Down Expand Up @@ -164,46 +163,134 @@ class WzRulesetActionButtons extends Component {
render() {
const { section, showingFiles } = this.props.state;

const getPermissionsFiles = () => {
const permissions = [
{
action: `cluster:status`,
resource: `*:*:*`,
},
];

if (((this.props || {}).clusterStatus || {}).contextConfigServer === 'cluster') {
permissions.push(
{
action: `cluster:upload_file`,
resource: `node:id:*`,
},
{
action: `cluster:read`,
resource: `node:id:*`,
},
{
action: `cluster:read_file`,
resource: `node:id:*&file:path:*`,
}
);
} else {
permissions.push(
{
action: `manager:upload_file`,
resource: `file:path:/etc/${section}`,
},
{
action: `manager:read`,
resource: `file:path:/etc/${section}`,
},
{
action: `manager:read_file`,
resource: `file:path:/etc/${section}`,
}
);
}

return permissions;
};

// Export button
const exportButton = (
<EuiButtonEmpty
<WzButtonPermissions
buttonType="empty"
permissions={getPermissionsFiles()}
iconType="exportAction"
iconSide="left"
onClick={async () => await this.generateCsv()}
isLoading={this.state.generatingCsv}
>
Export formatted
</EuiButtonEmpty>
</WzButtonPermissions>
);

// Add new rule button
const addNewRuleButton = (
<WzButtonPermissions
permissions={[{action: 'manager:upload_file', resource: `file:path:/etc/${section}`}]}
buttonType='empty'
permissions={getPermissionsFiles()}
buttonType="empty"
iconType="plusInCircle"
onClick={() =>
this.props.updteAddingRulesetFile({
name: '',
content: '<!-- Modify it at your will. -->',
path: `etc/${section}`
path: `etc/${section}`,
})
}
>
{`Add new ${section} file`}
</WzButtonPermissions>
);

const getPermissionsNewFileCDB = () => {
const permissions = [
{
action: `cluster:status`,
resource: `*:*:*`,
},
];

if (((this.props || {}).clusterStatus || {}).contextConfigServer === 'cluster') {
permissions.push(
{
action: `cluster:upload_file`,
resource: `node:id:*`,
},
{
action: `cluster:read`,
resource: `node:id:*`,
},
{
action: `cluster:read_file`,
resource: `node:id:*&file:path:*`,
}
);
} else {
permissions.push(
{
action: `manager:read_file`,
resource: `file:path:/etc/${section}`,
},
{
action: `manager:read`,
resource: `*:*:*`,
},
{
action: `manager:upload_file`,
resource: `file:path:/etc/${section}`,
}
);
}

return permissions;
};

//Add new CDB list button
const addNewCdbListButton = (
<WzButtonPermissions
buttonType='empty'
permissions={[{action: 'manager:upload_file', resource: 'file:path:/etc/lists/files'}]}
buttonType="empty"
permissions={getPermissionsNewFileCDB()}
iconType="plusInCircle"
onClick={() =>
this.props.updateListContent({
name: false,
content: '',
path: 'etc/lists'
path: 'etc/lists',
})
}
>
Expand All @@ -214,8 +301,8 @@ class WzRulesetActionButtons extends Component {
// Manage files
const manageFiles = (
<WzButtonPermissions
buttonType='empty'
permissions={[{action: 'manager:upload_file', resource: `file:path:/etc/${section}`}]}
buttonType="empty"
permissions={getPermissionsFiles()}
iconType={showingFiles ? 'apmTrace' : 'folderClosed'}
onClick={async () => await this.toggleFiles()}
>
Expand Down Expand Up @@ -252,6 +339,7 @@ class WzRulesetActionButtons extends Component {
{(section === 'lists' || showingFiles) && (
<EuiFlexItem grow={false}>
<UploadFiles
clusterStatus={this.props.clusterStatus}
msg={section}
path={`etc/${section}`}
upload={uploadFile}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ class WzListEditor extends Component {
}
await this.rulesetHandler.sendCdbList(name, path, raw, overwrite, addingNew);
if (!addingNew) {
const result = await this.rulesetHandler.getCdbList(`${path}/${name}`);
const file = { name: name, content: result, path: path };
const file = { name: name, content: raw, path: path };
this.props.updateListContent(file);
this.setState({ showWarningRestart: true });
this.showToast(
Expand Down Expand Up @@ -317,7 +316,15 @@ class WzListEditor extends Component {

const saveButton = (
<WzButtonPermissions
permissions={[{action: 'manager:upload_file', resource: `file:path:${path}/${name}`}]}
permissions={[
{
action: `${((this.props || {}).clusterStatus || {}).contextConfigServer}:upload_file`,
resource:
((this.props || {}).clusterStatus || {}).contextConfigServer === 'cluster'
? 'node:id:*'
: `file:path:${path}/${name}`,
},
]}
fill
isDisabled={items.length === 0}
iconType="save"
Expand All @@ -333,7 +340,17 @@ class WzListEditor extends Component {
{!this.state.isPopoverOpen && (
<EuiFlexItem grow={false}>
<WzButtonPermissions
permissions={[{action: 'manager:upload_file', resource: `file:path:${path}/${name}`}]}
permissions={[
{
action: `${
((this.props || {}).clusterStatus || {}).contextConfigServer
}:upload_file`,
resource:
((this.props || {}).clusterStatus || {}).contextConfigServer === 'cluster'
? 'node:id:*'
: `file:path:${path}/${name}`,
},
]}
iconType="plusInCircle"
onClick={() => this.openAddEntry()}
>
Expand Down Expand Up @@ -496,7 +513,17 @@ class WzListEditor extends Component {
buttonType='icon'
aria-label="Edit content"
iconType="pencil"
permissions={[{action: 'manager:upload_file', resource: `file:path:${path}/${fileName}`}]}
permissions={[
{
action: `${
((this.props || {}).clusterStatus || {}).contextConfigServer
}:upload_file`,
resource:
((this.props || {}).clusterStatus || {}).contextConfigServer === 'cluster'
? 'node:id:*'
: `file:path:${path}/${fileName}`,
},
]}
tooltip={{position: 'top', content: `Edit ${item.key}`}}
onClick={() => {
this.setState({
Expand All @@ -510,7 +537,17 @@ class WzListEditor extends Component {
buttonType='icon'
aria-label="Remove content"
iconType="trash"
permissions={[{action: 'manager:upload_file', resource: `file:path:${path}/${fileName}`}]}
permissions={[
{
action: `${
((this.props || {}).clusterStatus || {}).contextConfigServer
}:upload_file`,
resource:
((this.props || {}).clusterStatus || {}).contextConfigServer === 'cluster'
? 'node:id:*'
: `file:path:${path}/${fileName}`,
},
]}
tooltip={{position: 'top', content: `Remove ${item.key}`}}
onClick={() => this.deleteItem(item.key)}
color="danger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export default class WzRuleset extends Component {
<WzReduxProvider>
{(ruleInfo && <WzRuleInfo />) ||
(decoderInfo && <WzDecoderInfo />) ||
(listInfo && <WzListEditor />) ||
((fileContent || addingRulesetFile) && <WzRulesetEditor />) || (
<WzRulesetOverview />
(listInfo && <WzListEditor clusterStatus={this.props.clusterStatus} />) ||
((fileContent || addingRulesetFile) && <WzRulesetEditor clusterStatus={this.props.clusterStatus}/>) || (
<WzRulesetOverview clusterStatus={this.props.clusterStatus} />
)}
</WzReduxProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WzRulesetOverview extends Component {
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem></EuiFlexItem>
<WzRulesetActionButtons />
<WzRulesetActionButtons clusterStatus={this.props.clusterStatus} />
</EuiFlexGroup>
<EuiFlexGroup>
<EuiFlexItem>
Expand All @@ -60,7 +60,11 @@ class WzRulesetOverview extends Component {
<WzRulesetSearchBar />
<EuiFlexGroup>
<EuiFlexItem>
<WzRulesetTable request={section} updateTotalItems={(totalItems) => this.setState({totalItems})} />
<WzRulesetTable
clusterStatus={this.props.clusterStatus}
request={section}
updateTotalItems={(totalItems) => this.setState({ totalItems })}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
Expand Down
Loading