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 deployment wizard to add the WAZUH_PROTOCOL variable only for UDP connections #4760

Closed
49 changes: 49 additions & 0 deletions public/controllers/agent/components/register-agent-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { WzRequest } from '../../../react-services/wz-request';

type RemoteConfig = {
udpProtocol: boolean | null;
connectionSecure: boolean | null;
};

type RemoteItem = {
connection: 'syslog' | 'secure';
ipv6: 'yes' | 'no';
protocol: 'TCP' | 'UDP'[];
};

export const getRemoteConfiguration = async (): Promise<RemoteConfig> => {
let config: RemoteConfig = {
udpProtocol: null,
connectionSecure: null,
};
const result = await WzRequest.apiReq(
'GET',
'/agents/000/config/request/remote',
{},
);
const remote = ((result.data || {}).data || {}).remote || {};
const remoteFiltered = remote.filter((item: RemoteItem) => {
return item.connection === 'secure';
});
if (remoteFiltered.length === 0) {
config.connectionSecure = false;
} else {
remoteFiltered.forEach((item: RemoteItem) => {
if (item.connection === 'secure') {
if (item.protocol.length === 1 && item.protocol[0] == 'UDP') {
config = {
udpProtocol: true,
connectionSecure: true,
};
}
if (item.protocol.length > 1 && item.protocol[0] == 'TCP') {
config = {
udpProtocol: false,
connectionSecure: true,
};
}
}
});
}
return config;
};
99 changes: 90 additions & 9 deletions public/controllers/agent/components/register-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { UI_LOGGER_LEVELS } from '../../../../common/constants';
import { UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../../react-services/common-services';
import { webDocumentationLink } from '../../../../common/services/web_documentation';
import { getRemoteConfiguration } from './register-agent-service'

const architectureButtons = [
{
Expand Down Expand Up @@ -143,6 +144,7 @@ export const RegisterAgent = withErrorBoundary(
selectedGroup: [],
udpProtocol: false,
showPassword: false,
connectionSecure: true
};
this.restartAgentCommand = {
rpm: this.systemSelector(),
Expand Down Expand Up @@ -172,7 +174,7 @@ export const RegisterAgent = withErrorBoundary(
}
}

const udpProtocol = await this.getRemoteInfo();
await this.getRemoteInfo();
const groups = await this.getGroups();
this.setState({
serverAddress,
Expand All @@ -182,7 +184,6 @@ export const RegisterAgent = withErrorBoundary(
architectureButtons,
architectureCentos5OrRedHat5,
wazuhPassword,
udpProtocol,
wazuhVersion,
groups,
loading: false,
Expand All @@ -196,7 +197,7 @@ export const RegisterAgent = withErrorBoundary(
context: `${RegisterAgent.name}.componentDidMount`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
display: false,
display: true,
store: false,
error: {
error: error,
Expand All @@ -220,9 +221,8 @@ export const RegisterAgent = withErrorBoundary(

async getRemoteInfo() {
try {
const result = await WzRequest.apiReq('GET', '/agents/000/config/request/remote', {});
const remote = ((result.data || {}).data || {}).remote || {};
return (remote[0] || {}).protocol !== 'tcp' && (remote[0] || {}).protocol[0] !== 'TCP';
let config = await getRemoteConfiguration();
this.setState({ udpProtocol: config.udpProtocol, connectionSecure: config.connectionSecure });
} catch (error) {
throw new Error(error);
}
Expand Down Expand Up @@ -308,7 +308,6 @@ export const RegisterAgent = withErrorBoundary(
if (this.state.needsPassword) {
deployment += `WAZUH_REGISTRATION_PASSWORD='${this.state.wazuhPassword}' `;
}

if (this.state.udpProtocol) {
deployment += `WAZUH_PROTOCOL='UDP' `;
}
Expand Down Expand Up @@ -529,8 +528,90 @@ export const RegisterAgent = withErrorBoundary(
title='This section could not be displayed because you do not have permission to get access to the registration service.'
iconType="iInCircle"
/>
) :
this.state.selectedOS && (
) : (this.state.connectionSecure === true && this.state.udpProtocol === false) ? (
<EuiText>
<p>
You can use this command to install and enroll the Wazuh agent in one or more hosts.
</p>
<EuiCallOut
color="warning"
title={
<>
If the installer finds another Wazuh agent in the system, it will upgrade it preserving the configuration.
</>
}
iconType="iInCircle"
/>
<EuiSpacer />
{windowsAdvice}
<div className="copy-codeblock-wrapper">
<EuiCodeBlock style={codeBlock} language={language}>
{this.state.wazuhPassword && !this.state.showPassword ? this.obfuscatePassword(text) : text}
</EuiCodeBlock>
<EuiCopy textToCopy={text}>
{(copy) => (
<div className="copy-overlay" onClick={copy}>
<p><EuiIcon type="copy"/> Copy command</p>
</div>
)}
</EuiCopy>
</div>
{this.state.needsPassword && (
<EuiSwitch
label="Show password"
checked={this.state.showPassword}
onChange={(active) => this.setShowPassword(active)}
/>
)}
<EuiSpacer />
</EuiText>) : (this.state.connectionSecure === false) ?
(
<EuiText>
<p>
You can use this command to install and enroll the Wazuh agent in one or more hosts.
</p>
<EuiCallOut
color="warning"
title={
<>
If the installer finds another Wazuh agent in the system, it will upgrade it preserving the configuration.
</>
}
iconType="iInCircle"
/>
<EuiSpacer />
<EuiCallOut
color="danger"
title={
<>
Warning: there's no <EuiLink target="_blank" href={webDocumentationLink('user-manual/deployment-variables/deployment-variables.html', appVersionMajorDotMinor)}>secure protocol configured</EuiLink> and agents will not be able to communicate with the manager.
</>
}
iconType="iInCircle"
/>
<EuiSpacer />
{windowsAdvice}
<div className="copy-codeblock-wrapper">
<EuiCodeBlock style={codeBlock} language={language}>
{this.state.wazuhPassword && !this.state.showPassword ? this.obfuscatePassword(text) : text}
</EuiCodeBlock>
<EuiCopy textToCopy={text}>
{(copy) => (
<div className="copy-overlay" onClick={copy}>
<p><EuiIcon type="copy"/> Copy command</p>
</div>
)}
</EuiCopy>
</div>
{this.state.needsPassword && (
<EuiSwitch
label="Show password"
checked={this.state.showPassword}
onChange={(active) => this.setShowPassword(active)}
/>
)}
<EuiSpacer />
</EuiText>) : (
<EuiText>
<p>
You can use this command to install and enroll the Wazuh agent in one or more hosts.
Expand Down