From 85cd85e0cb8cb2ab168f9c70318eaba72cd71205 Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Tue, 12 Dec 2023 18:43:18 +0100 Subject: [PATCH 1/2] Change the auth configuration endpoint request --- .../security/policies/create-policy.tsx | 72 ++++++++++--------- .../security/policies/edit-policy.tsx | 72 ++++++++++--------- .../security/policies/policies-table.tsx | 2 +- .../register-agent/register-agent.tsx | 39 ++++------ .../services/register-agent-services.tsx | 48 +++++++++---- 5 files changed, 126 insertions(+), 107 deletions(-) diff --git a/plugins/main/public/components/security/policies/create-policy.tsx b/plugins/main/public/components/security/policies/create-policy.tsx index 2bf87b539c..58fc60a897 100644 --- a/plugins/main/public/components/security/policies/create-policy.tsx +++ b/plugins/main/public/components/security/policies/create-policy.tsx @@ -110,23 +110,25 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { const actionsData = actionsRequest?.data?.data || {}; setAvailableActions(actionsData); - const actions = Object.keys(actionsData).map((x, idx) => { - return { - id: idx, - value: x, - inputDisplay: x, - dropdownDisplay: ( - <> - {x} - -

- {actionsData[x].description} -

-
- - ), - }; - }); + const actions = Object.keys(actionsData) + .map((x, idx) => { + return { + id: idx, + value: x, + inputDisplay: x, + dropdownDisplay: ( + <> + {x} + +

+ {actionsData[x].description} +

+
+ + ), + }; + }) + .sort((a, b) => a.value.localeCompare(b.value)); setActions(actions); } @@ -137,23 +139,25 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { allResources = allResources.concat(res); }); const allResourcesSet = new Set(allResources); - const resources = Array.from(allResourcesSet).map((x, idx) => { - return { - id: idx, - value: x, - inputDisplay: x, - dropdownDisplay: ( - <> - {x} - -

- {availableResources[x].description} -

-
- - ), - }; - }); + const resources = Array.from(allResourcesSet) + .map((x, idx) => { + return { + id: idx, + value: x, + inputDisplay: x, + dropdownDisplay: ( + <> + {x} + +

+ {availableResources[x].description} +

+
+ + ), + }; + }) + .sort((a, b) => a.value.localeCompare(b.value)); setResources(resources); }; diff --git a/plugins/main/public/components/security/policies/edit-policy.tsx b/plugins/main/public/components/security/policies/edit-policy.tsx index b2935bb611..17485f96d3 100644 --- a/plugins/main/public/components/security/policies/edit-policy.tsx +++ b/plugins/main/public/components/security/policies/edit-policy.tsx @@ -112,23 +112,25 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { const actionsData = actionsRequest?.data?.data || {}; setAvailableActions(actionsData); - const actions = Object.keys(actionsData).map((x, idx) => { - return { - id: idx, - value: x, - inputDisplay: x, - dropdownDisplay: ( - <> - {x} - -

- {actionsData[x].description} -

-
- - ), - }; - }); + const actions = Object.keys(actionsData) + .map((x, idx) => { + return { + id: idx, + value: x, + inputDisplay: x, + dropdownDisplay: ( + <> + {x} + +

+ {actionsData[x].description} +

+
+ + ), + }; + }) + .sort((a, b) => a.value.localeCompare(b.value)); setActions(actions); } @@ -139,23 +141,25 @@ export const EditPolicyFlyout = ({ policy, closeFlyout }) => { allResources = allResources.concat(res); }); const allResourcesSet = new Set(allResources); - const resources = Array.from(allResourcesSet).map((x, idx) => { - return { - id: idx, - value: x, - inputDisplay: x, - dropdownDisplay: ( - <> - {x} - -

- {(availableResources[x] || {}).description} -

-
- - ), - }; - }); + const resources = Array.from(allResourcesSet) + .map((x, idx) => { + return { + id: idx, + value: x, + inputDisplay: x, + dropdownDisplay: ( + <> + {x} + +

+ {(availableResources[x] || {}).description} +

+
+ + ), + }; + }) + .sort((a, b) => a.value.localeCompare(b.value)); setResources(resources); }; diff --git a/plugins/main/public/components/security/policies/policies-table.tsx b/plugins/main/public/components/security/policies/policies-table.tsx index 866d0a34d0..4e2d9b376d 100644 --- a/plugins/main/public/components/security/policies/policies-table.tsx +++ b/plugins/main/public/components/security/policies/policies-table.tsx @@ -87,7 +87,7 @@ export const PoliciesTable = ({ name: 'Actions', sortable: true, render: actions => { - return (actions || []).join(', '); + return (actions || []).sort((a, b) => a.localeCompare(b)).join(', '); }, truncateText: true, }, diff --git a/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx b/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx index 8ae23213cd..7d110bfa2d 100644 --- a/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx +++ b/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx @@ -11,15 +11,17 @@ import { EuiProgress, EuiButton, } from '@elastic/eui'; -import { WzRequest } from '../../../../react-services/wz-request'; + import { UI_LOGGER_LEVELS } from '../../../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types'; import { ErrorHandler } from '../../../../react-services/error-management'; -import { getMasterRemoteConfiguration } from '../../../agent/components/register-agent-service'; import './register-agent.scss'; import { Steps } from '../steps/steps'; import { InputForm } from '../../../../components/common/form'; -import { getGroups } from '../../services/register-agent-services'; +import { + getGroups, + getMasterConfiguration, +} from '../../services/register-agent-services'; import { useForm } from '../../../../components/common/form/hooks'; import { FormConfiguration } from '../../../../components/common/form/types'; import { useSelector } from 'react-redux'; @@ -93,39 +95,26 @@ export const RegisterAgent = withReduxProvider( const form = useForm(initialFields); - const getRemoteConfig = async () => { - const remoteConfig = await getMasterRemoteConfiguration(); - if (remoteConfig) { - setHaveUdpProtocol(remoteConfig.isUdp); - } - }; - - const getAuthInfo = async () => { - try { - const result = await WzRequest.apiReq( - 'GET', - '/agents/000/config/auth/auth', - {}, - ); - return (result.data || {}).data || {}; - } catch (error) { - ErrorHandler.handleError(error); + const getMasterConfig = async () => { + const masterConfig = await getMasterConfiguration(); + if (masterConfig?.remote) { + setHaveUdpProtocol(masterConfig.remote.isUdp); } + return masterConfig; }; useEffect(() => { const fetchData = async () => { try { const wazuhVersion = await getWazuhVersion(); - await getRemoteConfig(); - const authInfo = await getAuthInfo(); + const { auth: authConfig } = await getMasterConfig(); // get wazuh password configuration let wazuhPassword = ''; - const needsPassword = (authInfo.auth || {}).use_password === 'yes'; + const needsPassword = authConfig?.auth?.use_password === 'yes'; if (needsPassword) { wazuhPassword = - configuration['enrollment.password'] || - authInfo['authd.pass'] || + configuration?.['enrollment.password'] || + authConfig?.['authd.pass'] || ''; } const groups = await getGroups(); diff --git a/plugins/main/public/controllers/register-agent/services/register-agent-services.tsx b/plugins/main/public/controllers/register-agent/services/register-agent-services.tsx index 8200224bb2..71c3b1dc15 100644 --- a/plugins/main/public/controllers/register-agent/services/register-agent-services.tsx +++ b/plugins/main/public/controllers/register-agent/services/register-agent-services.tsx @@ -92,6 +92,19 @@ async function getRemoteConfiguration(nodeName: string): Promise { return config; } } +/** + * Get the manager/cluster auth configuration from Wazuh API + * @param node + * @returns + */ +async function getAuthConfiguration(node?: string) { + const authConfigUrl = node + ? `/cluster/${node}/configuration/auth/auth` + : '/manager/configuration/auth/auth'; + const result = await WzRequest.apiReq('GET', authConfigUrl, {}); + const auth = result?.data?.data?.affected_items?.[0]; + return auth; +} /** * Get the remote protocol available from list of protocols @@ -213,13 +226,18 @@ export const getMasterNode = (nodeIps: any[]): any[] => { }; /** - * Get the remote configuration from manager + * Get the remote and the auth configuration from manager * This function get the config from manager mode or cluster mode */ -export const getMasterRemoteConfiguration = async () => { +export const getMasterConfiguration = async () => { const nodes = await fetchClusterNodesOptions(); const masterNode = getMasterNode(nodes); - return await getRemoteConfiguration(masterNode[0].label); + const remote = await getRemoteConfiguration(masterNode[0].label); + const auth = await getAuthConfiguration(masterNode[0].label); + return { + remote, + auth, + }; }; export { getConnectionConfig, getRemoteConfiguration }; @@ -260,16 +278,18 @@ export interface IParseRegisterFormValues { export const parseRegisterAgentFormValues = ( formValues: { name: keyof UseFormReturn['fields']; value: any }[], OSOptionsDefined: RegisterAgentData[], - initialValues?: IParseRegisterFormValues + initialValues?: IParseRegisterFormValues, ) => { // return the values form the formFields and the value property - const parsedForm = initialValues || { - operatingSystem: { - architecture: '', - name: '', - }, - optionalParams: {}, - } as IParseRegisterFormValues; + const parsedForm = + initialValues || + ({ + operatingSystem: { + architecture: '', + name: '', + }, + optionalParams: {}, + } as IParseRegisterFormValues); formValues.forEach(field => { if (field.name === 'operatingSystemSelection') { // search the architecture defined in architecture array and get the os name defined in title array in the same index @@ -284,7 +304,9 @@ export const parseRegisterAgentFormValues = ( } } else { if (field.name === 'agentGroups') { - parsedForm.optionalParams[field.name as any] = field.value.map(item => item.id) + parsedForm.optionalParams[field.name as any] = field.value.map( + item => item.id, + ); } else { parsedForm.optionalParams[field.name as any] = field.value; } @@ -292,4 +314,4 @@ export const parseRegisterAgentFormValues = ( }); return parsedForm; -}; \ No newline at end of file +}; From cb380252781fd234cb3120102745f7ec13f8c6c4 Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Tue, 12 Dec 2023 19:01:52 +0100 Subject: [PATCH 2/2] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a69ecb03..4d2a06e2cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Fixed - Fixed Agents preview page load when there are no registered agents [#6185](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6185) +- Fixed the endpoint to get Wazuh server auth configuration [#6206](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6206) ## Wazuh v4.7.1 - OpenSearch Dashboards 2.8.0 - Revision 01