diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c0da2dc2..12c10ca4e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Fixed problem with new or missing columns in agent table. [#5591](https://github.com/wazuh/wazuh-kibana-app/pull/5591) - Fixed the color of the agent name in the groups section in dark mode. [#5676](https://github.com/wazuh/wazuh-kibana-app/pull/5676) - Fixed the propagation event so that the flyout data, in the decoders, does not change when the button is pressed. [#5597](https://github.com/wazuh/wazuh-kibana-app/pull/5597) +- Fixed the tooltips of the tables in the security section, and unnecessary requests are removed. [#5631](https://github.com/wazuh/wazuh-kibana-app/pull/5631) ## Wazuh v4.6.0 - OpenSearch Dashboards 2.6.0 - Revision 01 diff --git a/docker/imposter/initial_data.json b/docker/imposter/initial_data.json index 985da0369f..b25b4d64d1 100644 --- a/docker/imposter/initial_data.json +++ b/docker/imposter/initial_data.json @@ -1,4 +1,8 @@ { "attempt": 0, - "callRestart": false + "callRestart": false, + "deleteUser": false, + "deleteRole": false, + "deletePolicies": false, + "deleteRolesMapping": false } diff --git a/docker/imposter/security/policies/delete-policies.js b/docker/imposter/security/policies/delete-policies.js new file mode 100644 index 0000000000..d4626b85b0 --- /dev/null +++ b/docker/imposter/security/policies/delete-policies.js @@ -0,0 +1,28 @@ +var id = context.request.queryParams.policy_ids; +var storeWazuh = stores.open('storeWazuh'); + +storeWazuh.save('deletePolicies', true); + +var data = { + data: { + affected_items: [ + { + id: id, + name: 'TestWazuhPolicy', + policy: { + actions: ['security:delete'], + resources: ['user:id:*'], + effect: 'deny', + }, + roles: [], + }, + ], + total_affected_items: 1, + total_failed_items: 0, + failed_items: [], + }, + message: 'All specified policies were deleted', + error: 0, +}; + +respond().withStatusCode(200).withData(JSON.stringify(data)); diff --git a/docker/imposter/security/policies/get-policies-after-delete.json b/docker/imposter/security/policies/get-policies-after-delete.json new file mode 100644 index 0000000000..384a082fe2 --- /dev/null +++ b/docker/imposter/security/policies/get-policies-after-delete.json @@ -0,0 +1,423 @@ +{ + "data": { + "affected_items": [ + { + "id": 1, + "name": "agents_all_resourceless", + "policy": { + "actions": ["agent:create", "group:create"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1, 5] + }, + { + "id": 2, + "name": "agents_all_agents", + "policy": { + "actions": [ + "agent:read", + "agent:delete", + "agent:modify_group", + "agent:reconnect", + "agent:restart", + "agent:upgrade" + ], + "resources": ["agent:id:*", "agent:group:*"], + "effect": "allow" + }, + "roles": [1, 5] + }, + { + "id": 3, + "name": "agents_all_groups", + "policy": { + "actions": [ + "group:read", + "group:delete", + "group:update_config", + "group:modify_assignments" + ], + "resources": ["group:id:*"], + "effect": "allow" + }, + "roles": [1, 5] + }, + { + "id": 4, + "name": "agents_read_agents", + "policy": { + "actions": ["agent:read"], + "resources": ["agent:id:*", "agent:group:*"], + "effect": "allow" + }, + "roles": [2, 4, 100] + }, + { + "id": 5, + "name": "agents_read_groups", + "policy": { + "actions": ["group:read"], + "resources": ["group:id:*"], + "effect": "allow" + }, + "roles": [2, 4, 100] + }, + { + "id": 6, + "name": "agents_commands_agents", + "policy": { + "actions": ["active-response:command"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 7, + "name": "security_all_resourceless", + "policy": { + "actions": [ + "security:create", + "security:create_user", + "security:read_config", + "security:update_config", + "security:revoke", + "security:edit_run_as" + ], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 8, + "name": "security_all_security", + "policy": { + "actions": ["security:read", "security:update", "security:delete"], + "resources": ["role:id:*", "policy:id:*", "user:id:*", "rule:id:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 9, + "name": "users_all_resourceless", + "policy": { + "actions": [ + "security:create_user", + "security:revoke", + "security:edit_run_as" + ], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [3] + }, + { + "id": 10, + "name": "users_all_users", + "policy": { + "actions": ["security:read", "security:update", "security:delete"], + "resources": ["user:id:*"], + "effect": "allow" + }, + "roles": [3] + }, + { + "id": 11, + "name": "users_modify_run_as_flag", + "policy": { + "actions": ["security:edit_run_as"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [] + }, + { + "id": 12, + "name": "ciscat_read_ciscat", + "policy": { + "actions": ["ciscat:read"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1, 2, 100] + }, + { + "id": 13, + "name": "decoders_read_decoders", + "policy": { + "actions": ["decoders:read"], + "resources": ["decoder:file:*"], + "effect": "allow" + }, + "roles": [2, 100] + }, + { + "id": 14, + "name": "decoders_all_files", + "policy": { + "actions": ["decoders:read", "decoders:delete"], + "resources": ["decoder:file:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 15, + "name": "decoders_all_resourceless", + "policy": { + "actions": ["decoders:update"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 16, + "name": "mitre_read_mitre", + "policy": { + "actions": ["mitre:read"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1, 2, 100] + }, + { + "id": 17, + "name": "lists_read_rules", + "policy": { + "actions": ["lists:read"], + "resources": ["list:file:*"], + "effect": "allow" + }, + "roles": [2, 100] + }, + { + "id": 18, + "name": "lists_all_rules", + "policy": { + "actions": ["lists:read", "lists:delete"], + "resources": ["list:file:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 19, + "name": "lists_all_resourceless", + "policy": { + "actions": ["lists:update"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 20, + "name": "rootcheck_read_rootcheck", + "policy": { + "actions": ["rootcheck:read"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [2, 100] + }, + { + "id": 21, + "name": "rootcheck_all_rootcheck", + "policy": { + "actions": ["rootcheck:clear", "rootcheck:read", "rootcheck:run"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 22, + "name": "rules_read_rules", + "policy": { + "actions": ["rules:read"], + "resources": ["rule:file:*"], + "effect": "allow" + }, + "roles": [2, 100] + }, + { + "id": 23, + "name": "rules_all_files", + "policy": { + "actions": ["rules:read", "rules:delete"], + "resources": ["rule:file:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 24, + "name": "rules_all_resourceless", + "policy": { + "actions": ["rules:update"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 25, + "name": "sca_read_sca", + "policy": { + "actions": ["sca:read"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1, 2, 100] + }, + { + "id": 26, + "name": "syscheck_read_syscheck", + "policy": { + "actions": ["syscheck:read"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [2, 100] + }, + { + "id": 27, + "name": "syscheck_all_syscheck", + "policy": { + "actions": ["syscheck:clear", "syscheck:read", "syscheck:run"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 28, + "name": "syscollector_read_syscollector", + "policy": { + "actions": ["syscollector:read"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1, 2, 100] + }, + { + "id": 29, + "name": "cluster_all_resourceless", + "policy": { + "actions": [ + "cluster:status", + "manager:read", + "manager:read_api_config", + "manager:update_config", + "manager:restart" + ], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1, 7] + }, + { + "id": 30, + "name": "cluster_all_nodes", + "policy": { + "actions": [ + "cluster:read_api_config", + "cluster:read", + "cluster:restart", + "cluster:update_config" + ], + "resources": ["node:id:*"], + "effect": "allow" + }, + "roles": [1, 7] + }, + { + "id": 31, + "name": "cluster_read_resourceless", + "policy": { + "actions": [ + "cluster:status", + "manager:read", + "manager:read_api_config" + ], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [2, 6, 100] + }, + { + "id": 32, + "name": "cluster_read_nodes", + "policy": { + "actions": [ + "cluster:read_api_config", + "cluster:read", + "cluster:read_api_config" + ], + "resources": ["node:id:*"], + "effect": "allow" + }, + "roles": [2, 6, 100] + }, + { + "id": 33, + "name": "logtest_all_logtest", + "policy": { + "actions": ["logtest:run"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1, 100] + }, + { + "id": 34, + "name": "task_status_task", + "policy": { + "actions": ["task:status"], + "resources": ["*:*:*"], + "effect": "allow" + }, + "roles": [1] + }, + { + "id": 35, + "name": "vulnerability_read_vulnerability", + "policy": { + "actions": ["vulnerability:read"], + "resources": ["agent:id:*"], + "effect": "allow" + }, + "roles": [1, 2, 100] + }, + { + "id": 100, + "name": "manager_deny_read", + "policy": { + "actions": ["manager:read", "cluster:read"], + "resources": ["*:*:*", "node:id:*"], + "effect": "deny" + }, + "roles": [100] + }, + { + "id": 102, + "name": "custom_manager_deny_read2", + "policy": { + "actions": ["manager:read", "cluster:read"], + "resources": ["*:*:*", "node:id:*"], + "effect": "deny" + }, + "roles": [100] + } + ], + "total_affected_items": 36, + "total_failed_items": 0, + "failed_items": [] + }, + "message": "All specified policies were returned", + "error": 0 +} diff --git a/docker/imposter/security/policies/get-policies.js b/docker/imposter/security/policies/get-policies.js new file mode 100644 index 0000000000..afc37541cd --- /dev/null +++ b/docker/imposter/security/policies/get-policies.js @@ -0,0 +1,21 @@ +var storeWazuh = stores.open('storeWazuh'); +var deletePolicies = storeWazuh.load('deletePolicies'); + +switch (deletePolicies) { + case false: + respond() + .withStatusCode(200) + .withFile('security/policies/get-policies.json'); + break; + case true: + storeWazuh.save('deletePolicies', false); + respond() + .withStatusCode(200) + .withFile('security/policies/get-policies-after-delete.json'); + break; + default: + respond() + .withStatusCode(200) + .withFile('security/policies/get-policies.json'); + break; +} diff --git a/docker/imposter/security/security-policies.json b/docker/imposter/security/policies/get-policies.json similarity index 100% rename from docker/imposter/security/security-policies.json rename to docker/imposter/security/policies/get-policies.json diff --git a/docker/imposter/security/roles-mapping/delete-rules.js b/docker/imposter/security/roles-mapping/delete-rules.js new file mode 100644 index 0000000000..13e3c5510c --- /dev/null +++ b/docker/imposter/security/roles-mapping/delete-rules.js @@ -0,0 +1,28 @@ +var id = context.request.queryParams.rule_ids; +var storeWazuh = stores.open('storeWazuh'); + +storeWazuh.save('deleteRolesMapping', true); + +var data = { + data: { + affected_items: [ + { + id: id, + name: 'TestWazuhRule', + rule: { + MATCH: { + definition: 'test_rule', + }, + }, + roles: [], + }, + ], + total_affected_items: 1, + total_failed_items: 0, + failed_items: [], + }, + message: 'All specified security rules were deleted', + error: 0, +}; + +respond().withStatusCode(200).withData(JSON.stringify(data)); diff --git a/docker/imposter/security/roles-mapping/get-rules-after-delete.json b/docker/imposter/security/roles-mapping/get-rules-after-delete.json new file mode 100644 index 0000000000..96ceee9986 --- /dev/null +++ b/docker/imposter/security/roles-mapping/get-rules-after-delete.json @@ -0,0 +1,39 @@ +{ + "data": { + "affected_items": [ + { + "id": 1, + "name": "wui_elastic_admin", + "rule": { + "FIND": { + "username": "elastic" + } + }, + "roles": [1] + }, + { + "id": 2, + "name": "wui_opendistro_admin", + "rule": { + "FIND": { + "username": "admin" + } + }, + "roles": [1] + }, + { + "id": 102, + "name": "custom_rule2", + "rule": { + "FIND": { + "username": "admin" + } + }, + "roles": [2] + } + ], + "total_affected_items": 4, + "total_failed_items": 0, + "failed_items": [] + } +} diff --git a/docker/imposter/security/roles-mapping/get-rules.js b/docker/imposter/security/roles-mapping/get-rules.js new file mode 100644 index 0000000000..c592adb09d --- /dev/null +++ b/docker/imposter/security/roles-mapping/get-rules.js @@ -0,0 +1,21 @@ +var storeWazuh = stores.open('storeWazuh'); +var deleteRolesMapping = storeWazuh.load('deleteRolesMapping'); + +switch (deleteRolesMapping) { + case false: + respond() + .withStatusCode(200) + .withFile('security/roles-mapping/get-rules.json'); + break; + case true: + storeWazuh.save('deleteRolesMapping', false); + respond() + .withStatusCode(200) + .withFile('security/roles-mapping/get-rules-after-delete.json'); + break; + default: + respond() + .withStatusCode(200) + .withFile('security/roles-mapping/get-rules.json'); + break; +} diff --git a/docker/imposter/security/security-rules.json b/docker/imposter/security/roles-mapping/get-rules.json similarity index 100% rename from docker/imposter/security/security-rules.json rename to docker/imposter/security/roles-mapping/get-rules.json diff --git a/docker/imposter/security/roles/delete-roles.js b/docker/imposter/security/roles/delete-roles.js new file mode 100644 index 0000000000..e97c4ae1f0 --- /dev/null +++ b/docker/imposter/security/roles/delete-roles.js @@ -0,0 +1,25 @@ +var id = context.request.queryParams.role_ids; +var storeWazuh = stores.open('storeWazuh'); + +storeWazuh.save('deleteRole', true); + +var data = { + data: { + affected_items: [ + { + id: id, + name: 'administrator', + policies: [4, 5], + rules: [8], + users: [101, 104], + }, + ], + total_affected_items: 1, + total_failed_items: 0, + failed_items: [], + }, + message: 'All specified roles were deleted', + error: 0, +}; + +respond().withStatusCode(200).withData(JSON.stringify(data)); diff --git a/docker/imposter/security/roles/get-roles-after-delete.json b/docker/imposter/security/roles/get-roles-after-delete.json new file mode 100644 index 0000000000..605804113e --- /dev/null +++ b/docker/imposter/security/roles/get-roles-after-delete.json @@ -0,0 +1,70 @@ +{ + "data": { + "affected_items": [ + { + "id": 1, + "name": "administrator", + "policies": [ + 1, 2, 3, 6, 7, 8, 29, 30, 12, 14, 15, 18, 19, 21, 23, 24, 16, 25, 27, + 28, 33, 34, 35 + ], + "users": [1, 2], + "rules": [1, 2, 100] + }, + { + "id": 2, + "name": "readonly", + "policies": [4, 5, 12, 31, 32, 13, 17, 20, 22, 16, 25, 26, 28, 35], + "users": [], + "rules": [] + }, + { + "id": 3, + "name": "users_admin", + "policies": [9, 10], + "users": [], + "rules": [] + }, + { + "id": 4, + "name": "agents_readonly", + "policies": [4, 5], + "users": [], + "rules": [] + }, + { + "id": 5, + "name": "agents_admin", + "policies": [1, 2, 3], + "users": [], + "rules": [] + }, + { + "id": 6, + "name": "cluster_readonly", + "policies": [31, 32], + "users": [], + "rules": [] + }, + { + "id": 7, + "name": "cluster_admin", + "policies": [29, 30], + "users": [], + "rules": [] + }, + { + "id": 102, + "name": "custom_role2", + "policies": [29, 30], + "users": [], + "rules": [] + } + ], + "total_affected_items": 8, + "total_failed_items": 0, + "failed_items": [] + }, + "message": "All specified roles were returned", + "error": 0 +} diff --git a/docker/imposter/security/roles/get-roles.js b/docker/imposter/security/roles/get-roles.js new file mode 100644 index 0000000000..bce8ca5a61 --- /dev/null +++ b/docker/imposter/security/roles/get-roles.js @@ -0,0 +1,17 @@ +var storeWazuh = stores.open('storeWazuh'); +var deleteRole = storeWazuh.load('deleteRole'); + +switch (deleteRole) { + case false: + respond().withStatusCode(200).withFile('security/roles/get-roles.json'); + break; + case true: + storeWazuh.save('deleteRole', false); + respond() + .withStatusCode(200) + .withFile('security/roles/get-roles-after-delete.json'); + break; + default: + respond().withStatusCode(200).withFile('security/roles/get-roles.json'); + break; +} diff --git a/docker/imposter/security/security-roles.json b/docker/imposter/security/roles/get-roles.json similarity index 100% rename from docker/imposter/security/security-roles.json rename to docker/imposter/security/roles/get-roles.json diff --git a/docker/imposter/security/users/delete-user.js b/docker/imposter/security/users/delete-user.js new file mode 100644 index 0000000000..8516b74474 --- /dev/null +++ b/docker/imposter/security/users/delete-user.js @@ -0,0 +1,24 @@ +var id = context.request.queryParams.user_ids; +var storeWazuh = stores.open('storeWazuh'); + +storeWazuh.save('deleteUser', true); + +var data = { + data: { + affected_items: [ + { + id: id, + username: 'test', + allow_run_as: false, + roles: [], + }, + ], + total_affected_items: 1, + total_failed_items: 0, + failed_items: [], + }, + message: 'Users were successfully deleted', + error: 0, +}; + +respond().withStatusCode(200).withData(JSON.stringify(data)); diff --git a/docker/imposter/security/users/get-users-after-delete.json b/docker/imposter/security/users/get-users-after-delete.json new file mode 100644 index 0000000000..c9103bd7a9 --- /dev/null +++ b/docker/imposter/security/users/get-users-after-delete.json @@ -0,0 +1,57 @@ +{ + "data": { + "affected_items": [ + { + "id": 1, + "username": "wazuh", + "allow_run_as": true, + "roles": [1] + }, + { + "id": 2, + "username": "wazuh-wui", + "allow_run_as": true, + "roles": [] + }, + { + "id": 3, + "username": "administrator", + "allow_run_as": true, + "roles": [2] + }, + { + "id": 4, + "username": "guest", + "allow_run_as": false, + "roles": [] + }, + { + "id": 5, + "username": "normal", + "allow_run_as": false, + "roles": [4, 5, 6] + }, + { + "id": 6, + "username": "ossec", + "allow_run_as": true, + "roles": [2, 5] + }, + { + "id": 7, + "username": "rbac", + "allow_run_as": false, + "roles": [3, 4, 5] + }, + { + "id": 101, + "username": "custom_user", + "allow_run_as": true, + "roles": [] + } + ], + "total_affected_items": 8, + "total_failed_items": 0, + "failed_items": [] + } +} diff --git a/docker/imposter/security/users/get-users.js b/docker/imposter/security/users/get-users.js new file mode 100644 index 0000000000..4f4c8eb74e --- /dev/null +++ b/docker/imposter/security/users/get-users.js @@ -0,0 +1,17 @@ +var storeWazuh = stores.open('storeWazuh'); +var deleteUser = storeWazuh.load('deleteUser'); + +switch (deleteUser) { + case false: + respond().withStatusCode(200).withFile('security/users/get-users.json'); + break; + case true: + storeWazuh.save('deleteUser', false); + respond() + .withStatusCode(200) + .withFile('security/users/get-users-after-delete.json'); + break; + default: + respond().withStatusCode(200).withFile('security/users/get-users.json'); + break; +} diff --git a/docker/imposter/security/users.json b/docker/imposter/security/users/get-users.json similarity index 100% rename from docker/imposter/security/users.json rename to docker/imposter/security/users/get-users.json diff --git a/docker/imposter/wazuh-config.yml b/docker/imposter/wazuh-config.yml index 028dd20d3f..fac787e84d 100755 --- a/docker/imposter/wazuh-config.yml +++ b/docker/imposter/wazuh-config.yml @@ -688,7 +688,7 @@ resources: path: /security/users response: statusCode: 200 - staticFile: security/users.json + scriptFile: security/users/get-users.js # Add users - method: POST @@ -697,6 +697,9 @@ resources: # Delete users - method: DELETE path: /security/users + response: + statusCode: 200 + scriptFile: security/users/delete-user.js # Update users - method: PUT @@ -707,7 +710,7 @@ resources: path: /security/roles response: statusCode: 200 - staticFile: security/security-roles.json + scriptFile: security/roles/get-roles.js # Add role - method: POST @@ -716,6 +719,9 @@ resources: # Delete roles - method: DELETE path: /security/roles + response: + statusCode: 200 + scriptFile: security/roles/delete-roles.js # Update role - method: PUT @@ -726,7 +732,7 @@ resources: path: /security/rules response: statusCode: 200 - staticFile: security/security-rules.json + scriptFile: security/roles-mapping/get-rules.js # Add security rule - method: POST @@ -735,6 +741,9 @@ resources: # Delete security rules - method: DELETE path: /security/rules + response: + statusCode: 200 + scriptFile: security/roles-mapping/delete-rules.js # Update security rule - method: PUT @@ -745,7 +754,7 @@ resources: path: /security/policies response: statusCode: 200 - staticFile: security/security-policies.json + scriptFile: security/policies/get-policies.js # Add policy - method: POST @@ -754,6 +763,9 @@ resources: # Delete policies - method: DELETE path: /security/policies + response: + statusCode: 200 + scriptFile: security/policies/delete-policies.js # Update policy - method: PUT diff --git a/plugins/main/public/components/common/flyouts/close-flyout-security.tsx b/plugins/main/public/components/common/flyouts/close-flyout-security.tsx new file mode 100644 index 0000000000..1fb1d155b1 --- /dev/null +++ b/plugins/main/public/components/common/flyouts/close-flyout-security.tsx @@ -0,0 +1,4 @@ +export const closeFlyout = async (needRefresh, setState, getData) => { + setState(false); + needRefresh && (await getData()); +}; diff --git a/plugins/main/public/components/security/policies/create-policy.tsx b/plugins/main/public/components/security/policies/create-policy.tsx index 65f2cbf086..2bf87b539c 100644 --- a/plugins/main/public/components/security/policies/create-policy.tsx +++ b/plugins/main/public/components/security/policies/create-policy.tsx @@ -39,7 +39,7 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { const [effectValue, setEffectValue] = useState(); const [hasChanges, setHasChanges] = useState(false); - const actions_columns = [ + const actionsColumns = [ { field: 'action', name: 'Actions', @@ -61,7 +61,7 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { }, ]; - const resources_columns = [ + const resourcesColumns = [ { field: 'resource', name: 'Resources', @@ -171,8 +171,8 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { effect: effectValue, }, }); - const resultData = (result.data || {}).data; - if (resultData.failed_items && resultData.failed_items.length) { + const resultData = result?.data?.data; + if (resultData?.failed_items && resultData?.failed_items?.length) { return; } ErrorHandler.info('Policy was successfully created', ''); @@ -194,7 +194,7 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { }; getErrorOrchestrator().handleError(options); } - closeFlyout(); + closeFlyout(true); }; const getIdentifier = () => { @@ -360,7 +360,7 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { @@ -418,7 +418,7 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { diff --git a/plugins/main/public/components/security/policies/edit-policy.tsx b/plugins/main/public/components/security/policies/edit-policy.tsx index 13e2e50c79..b2935bb611 100644 --- a/plugins/main/public/components/security/policies/edit-policy.tsx +++ b/plugins/main/public/components/security/policies/edit-policy.tsx @@ -72,14 +72,14 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { }, ); - const data = (response.data || {}).data; - if (data.failed_items && data.failed_items.length) { + const data = response?.data?.data; + if (data?.failed_items && data?.failed_items?.length) { return; } ErrorHandler.info( 'Role was successfully updated with the selected policies', ); - closeFlyout(); + closeFlyout(true); } catch (error) { const options = { context: `${EditPolicyFlyout.name}.updatePolicy`, @@ -97,22 +97,22 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { }; async function getData() { - const resources_request = await WzRequest.apiReq( + const resourcesRequest = await WzRequest.apiReq( 'GET', '/security/resources', {}, ); - const actions_request = await WzRequest.apiReq( + const actionsRequest = await WzRequest.apiReq( 'GET', '/security/actions', {}, ); - const resources_data = ((resources_request || {}).data || {}).data || {}; - setAvailableResources(resources_data); + const resourcesData = resourcesRequest?.data?.data || {}; + setAvailableResources(resourcesData); - const actions_data = ((actions_request || {}).data || {}).data || {}; - setAvailableActions(actions_data); - const actions = Object.keys(actions_data).map((x, idx) => { + const actionsData = actionsRequest?.data?.data || {}; + setAvailableActions(actionsData); + const actions = Object.keys(actionsData).map((x, idx) => { return { id: idx, value: x, @@ -122,7 +122,7 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { {x}

- {actions_data[x].description} + {actionsData[x].description}

@@ -211,7 +211,7 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { setAddedActions(addedActions.filter(x => x !== action)); }; - const actions_columns = [ + const actionsColumns = [ { field: 'action', name: 'Actions', @@ -234,7 +234,7 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { }, ]; - const resources_columns = [ + const resourcesColumns = [ { field: 'resource', name: 'Resources', @@ -391,7 +391,7 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { @@ -446,7 +446,7 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { diff --git a/plugins/main/public/components/security/policies/policies-table.tsx b/plugins/main/public/components/security/policies/policies-table.tsx index 7f5d5fea2a..866d0a34d0 100644 --- a/plugins/main/public/components/security/policies/policies-table.tsx +++ b/plugins/main/public/components/security/policies/policies-table.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { EuiInMemoryTable, EuiBadge } from '@elastic/eui'; import { WzRequest } from '../../../react-services/wz-request'; import { ErrorHandler } from '../../../react-services/error-handler'; @@ -14,6 +14,12 @@ export const PoliciesTable = ({ editPolicy, updatePolicies, }) => { + const [policiesState, setPoliciesState] = useState([]); + + useEffect(() => { + setPoliciesState(policies); + }, [policies]); + const getRowProps = item => { const { id } = item; return { @@ -36,10 +42,13 @@ export const PoliciesTable = ({ }, }, ); - const data = (response.data || {}).data; - if (data.failed_items && data.failed_items.length) { + const data = response?.data?.data; + if (data?.failed_items && data?.failed_items?.length) { return; } + // Workaround for tooltip problem does not disappear + // when deleting a policy if the following policy is a reserved policy + setPoliciesState([]); ErrorHandler.info('Policy was successfully deleted'); await updatePolicies(); } catch (error) { @@ -153,7 +162,7 @@ export const PoliciesTable = ({ return ( { - setIsEditingPolicy(false); - await getPolicies(); + const closeEditingFlyout = needRefresh => { + closeFlyout(needRefresh, setIsEditingPolicy, getPolicies); }; - const closeCreatingFlyout = async () => { - setIsCreatingPolicy(false); - await getPolicies(); + const closeCreatingFlyout = needRefresh => { + closeFlyout(needRefresh, setIsCreatingPolicy, getPolicies); }; let editFlyout; diff --git a/plugins/main/public/components/security/roles-mapping/components/roles-mapping-table.tsx b/plugins/main/public/components/security/roles-mapping/components/roles-mapping-table.tsx index 5efe9cbb14..2167487405 100644 --- a/plugins/main/public/components/security/roles-mapping/components/roles-mapping-table.tsx +++ b/plugins/main/public/components/security/roles-mapping/components/roles-mapping-table.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { EuiToolTip, EuiInMemoryTable, @@ -12,7 +12,10 @@ import { ErrorHandler } from '../../../../react-services/error-handler'; import { WzButtonPermissionsModalConfirm } from '../../../common/buttons'; import { WzAPIUtils } from '../../../../react-services/wz-api-utils'; import RulesServices from '../../rules/services'; -import { UI_LOGGER_LEVELS, WAZUH_API_RESERVED_WUI_SECURITY_RULES } from '../../../../../common/constants'; +import { + UI_LOGGER_LEVELS, + WAZUH_API_RESERVED_WUI_SECURITY_RULES, +} from '../../../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types'; import { getErrorOrchestrator } from '../../../../react-services/common-services'; @@ -23,6 +26,12 @@ export const RolesMappingTable = ({ editRule, updateRules, }) => { + const [rulesState, setRulesState] = useState([]); + + useEffect(() => { + setRulesState(rules); + }, [rules]); + const getRowProps = item => { const { id } = item; return { @@ -37,6 +46,9 @@ export const RolesMappingTable = ({ await RulesServices.DeleteRules([item.id]); ErrorHandler.info('Role mapping was successfully deleted'); updateRules(); + // Workaround for tooltip problem does not disappear + // when deleting a rule if the following rule is a reserved rule + setRulesState([]); } catch (error) { const options = { context: `${RolesMappingTable.name}.onDeleteRoleMapping`, @@ -161,7 +173,7 @@ export const RolesMappingTable = ({ return ( { + closeFlyout(needRefresh, setIsEditingRule, initData); + }; + + const closeCreatingFlyout = needRefresh => { + closeFlyout(needRefresh, setIsCreatingRule, initData); + }; + let editFlyout; if (isEditingRule) { editFlyout = ( { - setIsEditingRule(isVisible); - initData(); - }} + closeFlyout={closeEditingFlyout} rolesEquivalences={rolesEquivalences} roles={roles} internalUsers={internalUsers} @@ -145,10 +151,7 @@ export const RolesMapping = withUserAuthorizationPrompt([ if (isCreatingRule) { createFlyout = ( { - setIsCreatingRule(isVisible); - initData(); - }} + closeFlyout={closeCreatingFlyout} rolesEquivalences={rolesEquivalences} roles={roles} internalUsers={internalUsers} diff --git a/plugins/main/public/components/security/roles/create-role.tsx b/plugins/main/public/components/security/roles/create-role.tsx index 832954df28..e7d30643f9 100644 --- a/plugins/main/public/components/security/roles/create-role.tsx +++ b/plugins/main/public/components/security/roles/create-role.tsx @@ -64,13 +64,13 @@ export const CreateRole = ({ closeFlyout }) => { const result = await WzRequest.apiReq('POST', '/security/roles', { name: roleName, }); - const data = (result.data || {}).data; - if (data.failed_items && data.failed_items.length) { + const data = result?.data?.data; + if (data?.failed_items && data?.failed_items?.length) { return; } let roleId = ''; - if (data.affected_items && data.affected_items) { - roleId = data.affected_items[0].id; + if (data?.affected_items) { + roleId = data.affected_items?.[0]?.id; } const policiesId = selectedPolicies.map(policy => { return policy.id; @@ -85,8 +85,8 @@ export const CreateRole = ({ closeFlyout }) => { }, ); - const policiesData = (policyResult.data || {}).data; - if (policiesData.failed_items && policiesData.failed_items.length) { + const policiesData = policyResult?.data?.data; + if (policiesData?.failed_items && policiesData?.failed_items?.length) { return; } ErrorHandler.info( @@ -95,7 +95,7 @@ export const CreateRole = ({ closeFlyout }) => { } catch (error) { ErrorHandler.handle(error, 'There was an error'); } - closeFlyout(false); + closeFlyout(true); }; const onChangeRoleName = e => { diff --git a/plugins/main/public/components/security/roles/edit-role-table.tsx b/plugins/main/public/components/security/roles/edit-role-table.tsx index f12fba2967..048138ccfd 100644 --- a/plugins/main/public/components/security/roles/edit-role-table.tsx +++ b/plugins/main/public/components/security/roles/edit-role-table.tsx @@ -99,10 +99,10 @@ export const EditRolesTable = ({ }, }, ); - const removePolicy = (response.data || {}).data; + const removePolicy = response?.data?.data; if ( - removePolicy.failed_items && - removePolicy.failed_items.length + removePolicy?.failed_items && + removePolicy?.failed_items?.length ) { setIsLoading(false); return; diff --git a/plugins/main/public/components/security/roles/edit-role.tsx b/plugins/main/public/components/security/roles/edit-role.tsx index c18b72e8de..53daf608a2 100644 --- a/plugins/main/public/components/security/roles/edit-role.tsx +++ b/plugins/main/public/components/security/roles/edit-role.tsx @@ -58,8 +58,7 @@ export const EditRole = ({ role, closeFlyout }) => { }, }, ); - const roleData = (((roleDataResponse.data || {}).data || {}) - .affected_items || [])[0]; + const roleData = roleDataResponse?.data?.data?.affected_items?.[0]; setCurrentRole(roleData); const policies_request = await WzRequest.apiReq( 'GET', @@ -120,8 +119,8 @@ export const EditRole = ({ role, closeFlyout }) => { }, ); - const policiesData = (policyResult.data || {}).data; - if (policiesData.failed_items && policiesData.failed_items.length) { + const policiesData = policyResult?.data?.data; + if (policiesData?.failed_items && policiesData?.failed_items?.length) { return; } ErrorHandler.info( diff --git a/plugins/main/public/components/security/roles/roles-table.tsx b/plugins/main/public/components/security/roles/roles-table.tsx index 20a66adcc4..cd83f2eb4f 100644 --- a/plugins/main/public/components/security/roles/roles-table.tsx +++ b/plugins/main/public/components/security/roles/roles-table.tsx @@ -23,6 +23,12 @@ export const RolesTable = ({ editRole, updateRoles, }) => { + const [rolesState, setRolesState] = useState([]); + + useEffect(() => { + setRolesState(roles); + }, [roles]); + const getRowProps = item => { const { id } = item; return { @@ -34,15 +40,18 @@ export const RolesTable = ({ const onConfirmDeleteRole = item => { return async () => { try { - const response = await WzRequest.apiReq('DELETE', `/security/roles/`, { + const response = await WzRequest.apiReq('DELETE', '/security/roles/', { params: { role_ids: item.id, }, }); - const data = (response.data || {}).data; - if (data.failed_items && data.failed_items.length) { + const data = response?.data?.data; + if (data?.failed_items && data?.failed_items?.length) { return; } + // Workaround for tooltip problem does not disappear + // when deleting a role if the following role is a reserved role + setRolesState([]); ErrorHandler.info('Role was successfully deleted'); await updateRoles(); } catch (error) { @@ -187,7 +196,7 @@ export const RolesTable = ({ return ( { + closeFlyout(needRefresh, setIsEditFlyoutVisible, getData); + }; + + const closeCreatingFlyout = needRefresh => { + closeFlyout(needRefresh, setIsFlyoutVisible, getData); + }; + let flyout; if (isFlyoutVisible) { - flyout = ( - { - setIsFlyoutVisible(isVisible); - await getData(); - }} - /> - ); + flyout = ; } const editRole = item => { @@ -65,13 +65,7 @@ export const Roles = withUserAuthorizationPrompt([ let editFlyout; if (isEditFlyoutVisible) { editFlyout = ( - { - setIsEditFlyoutVisible(isVisible); - await getData(); - }} - /> + ); } diff --git a/plugins/main/public/components/security/users/components/users-table.tsx b/plugins/main/public/components/security/users/components/users-table.tsx index 9f9bb51f91..4416fc9292 100644 --- a/plugins/main/public/components/security/users/components/users-table.tsx +++ b/plugins/main/public/components/security/users/components/users-table.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { EuiInMemoryTable, EuiBadge, @@ -23,6 +23,7 @@ export const UsersTable = ({ roles, onSave, }) => { + const [userState, setUserState] = useState([]); const getRowProps = item => { const { id } = item; return { @@ -31,10 +32,17 @@ export const UsersTable = ({ }; }; + useEffect(() => { + setUserState(users); + }, [users]); + const onConfirmDeleteUser = item => { return async () => { try { await UsersServices.DeleteUsers([item.id]); + // Workaround for tooltip problem does not disappear + // when deleting a user if the following user is a reserved user + setUserState([]); ErrorHandler.info('User was successfully deleted'); onSave(); } catch (error) { @@ -139,7 +147,7 @@ export const UsersTable = ({ return ( { - if (refresh) await getUsers(); - setIsEditFlyoutVisible(false); + const closeEditFlyout = refresh => { + closeFlyout(refresh, setIsEditFlyoutVisible, getUsers); }; - const closeCreateFlyout = async refresh => { - if (refresh) await getUsers(); - setIsCreateFlyoutVisible(false); + const closeCreateFlyout = refresh => { + closeFlyout(refresh, setIsCreateFlyoutVisible, getUsers); }; if (securityError) {