-
Notifications
You must be signed in to change notification settings - Fork 190
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
Changes from 15 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 23b6f1e
Added new method isClusterOrManager to get cluster status, set on red…
gabiwassan f2188c9
Fixed and replaced all permissions by contextConfigServer (cluster or…
gabiwassan acbb51c
Rollback, wrong change.
gabiwassan f1420b8
Request changes of validation null properties.
gabiwassan 4ed8732
Added initial state of clusterStatus
gabiwassan f689408
Moved method isClusterOrManager to management-main.js to distribute t…
gabiwassan 9cd4472
Fixed permissions to edit and export to csv.
gabiwassan 5715e9c
Fixed permissions for manager or cluster. Added on wz-user-permission…
gabiwassan 00eeacf
Merge branch '4.0-7.9' into fix/2657-wrong-permissions-on-edit-cdb
gabiwassan 20ce83a
Changed to const permissions declaration.
gabiwassan 80aa117
Merge remote-tracking branch 'origin/fix/2657-wrong-permissions-on-ed…
gabiwassan b81b69d
Fixed user-permissions to support cominations of resources with &. Re…
gabiwassan 129753e
Refactor Withe and Black mode. (juts simplify code)
gabiwassan 3474127
Fixed typo error
gabiwassan 191d3f6
Fixed errors detected on PR.
gabiwassan e6f95a6
Removed unnecessary request, to update list content, we have this val…
gabiwassan a611ff6
First commit scaffolding test wz-users-permissions
gabiwassan c793aaf
Fixed mock of userPermissions and requiredPermissions
gabiwassan 754c5b5
Implemented a basic suite of test for wz-user-permissions.ts
gabiwassan 6448c21
Removed import.
gabiwassan e8dd674
Added header Wazuh Copyright.
gabiwassan 0c6be16
Added CHANGELOG.md
gabiwassan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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'; | ||
|
@@ -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', | ||
}) | ||
} | ||
> | ||
|
@@ -214,8 +301,25 @@ class WzRulesetActionButtons extends Component { | |
// Manage files | ||
const manageFiles = ( | ||
<WzButtonPermissions | ||
buttonType='empty' | ||
permissions={[{action: 'manager:upload_file', resource: `file:path:/etc/${section}`}]} | ||
buttonType="empty" | ||
permissions={[ | ||
{ | ||
action: `${((this.props || {}).clusterStatus || {}).contextConfigServer}:upload_file`, | ||
resource: `file:path:/etc/${section}`, | ||
}, | ||
{ | ||
action: `${((this.props || {}).clusterStatus || {}).contextConfigServer}:read`, | ||
resource: `file:path:/etc/${this.props.msg}`, | ||
}, | ||
{ | ||
action: `${((this.props || {}).clusterStatus || {}).contextConfigServer}:read_file`, | ||
resource: `file:path:/etc/${this.props.msg}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be the |
||
}, | ||
{ | ||
action: `cluster:status`, | ||
resource: `*:*:*`, | ||
}, | ||
]} | ||
iconType={showingFiles ? 'apmTrace' : 'folderClosed'} | ||
onClick={async () => await this.toggleFiles()} | ||
> | ||
|
@@ -252,6 +356,7 @@ class WzRulesetActionButtons extends Component { | |
{(section === 'lists' || showingFiles) && ( | ||
<EuiFlexItem grow={false}> | ||
<UploadFiles | ||
clusterStatus={this.props.clusterStatus} | ||
msg={section} | ||
path={`etc/${section}`} | ||
upload={uploadFile} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be the
section
variable insteadthis.props.msg
? I checked the code and didn't found where it is coming from.