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

Change the endpoint to get Wazuh manager auth configuration #6206

Merged
merged 2 commits into from
Dec 13, 2023
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 @@ -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

Expand Down
72 changes: 38 additions & 34 deletions plugins/main/public/components/security/policies/create-policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{actionsData[x].description}
</p>
</EuiText>
</>
),
};
});
const actions = Object.keys(actionsData)
.map((x, idx) => {
return {
id: idx,
value: x,
inputDisplay: x,
dropdownDisplay: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{actionsData[x].description}
</p>
</EuiText>
</>
),
};
})
.sort((a, b) => a.value.localeCompare(b.value));
setActions(actions);
}

Expand All @@ -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: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{availableResources[x].description}
</p>
</EuiText>
</>
),
};
});
const resources = Array.from(allResourcesSet)
.map((x, idx) => {
return {
id: idx,
value: x,
inputDisplay: x,
dropdownDisplay: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{availableResources[x].description}
</p>
</EuiText>
</>
),
};
})
.sort((a, b) => a.value.localeCompare(b.value));
setResources(resources);
};

Expand Down
72 changes: 38 additions & 34 deletions plugins/main/public/components/security/policies/edit-policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{actionsData[x].description}
</p>
</EuiText>
</>
),
};
});
const actions = Object.keys(actionsData)
.map((x, idx) => {
return {
id: idx,
value: x,
inputDisplay: x,
dropdownDisplay: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{actionsData[x].description}
</p>
</EuiText>
</>
),
};
})
.sort((a, b) => a.value.localeCompare(b.value));
setActions(actions);
}

Expand All @@ -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: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{(availableResources[x] || {}).description}
</p>
</EuiText>
</>
),
};
});
const resources = Array.from(allResourcesSet)
.map((x, idx) => {
return {
id: idx,
value: x,
inputDisplay: x,
dropdownDisplay: (
<>
<strong>{x}</strong>
<EuiText size='s' color='subdued'>
<p className='euiTextColor--subdued'>
{(availableResources[x] || {}).description}
</p>
</EuiText>
</>
),
};
})
.sort((a, b) => a.value.localeCompare(b.value));
setResources(resources);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ async function getRemoteConfiguration(nodeName: string): Promise<RemoteConfig> {
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
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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
Expand All @@ -284,12 +304,14 @@ 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;
}
}
});

return parsedForm;
};
};
Loading