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

[Redesign add page] Agent register wizard handle properly special characters in password #5738

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
03bdb99
parent component
chantal-kelm May 17, 2023
75cce24
Added a title to the container and updated filenames
chantal-kelm May 19, 2023
5e834bf
Merge branch '4.5' into 4205-redesign-add-agent-page
chantal-kelm May 19, 2023
60cf736
Merge branch '4.5' into 4205-redesign-add-agent-page
chantal-kelm May 23, 2023
edd6ff4
Update register-agent.scss
chantal-kelm May 23, 2023
8b646f5
[Redesign add agent] Register agent reuse common/form component (Sett…
Machi3mfl May 24, 2023
106cda1
[Redesign add agent] Add register agent command generator (#5469)
Machi3mfl Jun 13, 2023
9ada6ba
Create reusable card for operating systems (#5462)
chantal-kelm Jun 15, 2023
10a9d9d
5518 inputs logic server address name password and group (#5554)
chantal-kelm Jun 23, 2023
11a462d
[Redesign add agent] Integration commands generator with UI (#5593)
Machi3mfl Jun 27, 2023
1c31e45
[Redesign add agent] Dark mode (#5620)
chantal-kelm Jun 28, 2023
2fc1dc5
[Redesign add agent] Add and validate register agent commands (#5622)
Machi3mfl Jun 30, 2023
82a588f
merge with 4.6.0
chantal-kelm Jul 3, 2023
b92c8c5
Fixed imports in tests
Machi3mfl Jul 3, 2023
537fb68
Fix components unit tests
Machi3mfl Jul 3, 2023
7617c96
Fix unit test checkbox group component
Machi3mfl Jul 3, 2023
3d187b1
Fix os card unit test with mock uiSettings
Machi3mfl Jul 3, 2023
bade293
modify the fqdn regex because it interferes with an ipv4 instance
chantal-kelm Jul 4, 2023
d0b89f4
[Redesign add page] Add form status callout message (#5634)
Machi3mfl Jul 7, 2023
be7b1cd
Step 2: the design triggers warnings (#5649)
chantal-kelm Jul 10, 2023
0241a59
update changelog
chantal-kelm Jul 11, 2023
bf647a7
update changelog
chantal-kelm Jul 11, 2023
3c5f965
Merge 4.5.1 into 4.6.0 (#5671)
yenienserrano Jul 11, 2023
249eb8b
Remove unused embedded jquery-ui (#5592)
Desvelao Jul 12, 2023
24efe6f
Merge branch '4.6.0' into 4205-redesign-add-agent-page
chantal-kelm Jul 12, 2023
de033d2
Fixes redirection problem to inventory data, stats and configuration …
yenienserrano Jul 18, 2023
07ebb4f
Merge branch '4.6.0' into 4205-redesign-add-agent-page
chantal-kelm Jul 19, 2023
657fecb
Fix conflicts in branch synchronization (#5708)
Desvelao Jul 20, 2023
a957b24
Fix 4.6.0 changelog merge errors (#5692)
yenienserrano Jul 20, 2023
2e590e1
Merge branch '4.6.0' into 4205-redesign-add-agent-page
Machi3mfl Jul 21, 2023
8e2405b
Merge 4.5.2 into 4.6.0 (#5721)
Desvelao Jul 21, 2023
cfded12
Merge branch '4.6.0' into 4205-redesign-add-agent-page
chantal-kelm Jul 24, 2023
0419bd8
Add method to scape special chars in wazuh password
Machi3mfl Jul 26, 2023
e84f88e
Upgrade environments to 4.6 and 4.7 (#5741)
yenienserrano Jul 28, 2023
97ecb93
Applied special chars scape un command password
Machi3mfl Jul 31, 2023
140c2ec
Merge branch '4.7.0' into feat/5493-register-agent-handle-password-wi…
Machi3mfl Aug 1, 2023
b8298b4
Redesign deploy new agent page (#5457)
chantal-kelm Aug 1, 2023
7d42afa
Add password scaped singlequote
Machi3mfl Aug 2, 2023
4cf09f2
Add new wazuh password service for scape special characters with unit…
Machi3mfl Aug 3, 2023
3956dd5
Add new unit test case
Machi3mfl Aug 3, 2023
d39fd3f
Fix service and added unit tests
Machi3mfl Aug 3, 2023
b566f03
Merge branch '4.7.0' into feat/5493-register-agent-handle-password-wi…
Machi3mfl Aug 4, 2023
5463030
Merge remote-tracking branch 'origin/4.6.0' into feat/5493-register-a…
Machi3mfl Aug 4, 2023
8fcd2a8
Merge branch '4.7.0' into feat/5493-register-agent-handle-password-wi…
Machi3mfl Aug 4, 2023
d154bd1
Comment logs in service unit test
Machi3mfl Aug 4, 2023
755942b
Update CHANGELOG
Machi3mfl Aug 4, 2023
74fd4ea
Change regex to scape special characters
Machi3mfl Aug 7, 2023
8dde16c
Fix unit tests
Machi3mfl Aug 7, 2023
69f3fcf
Fix osdfucate password with toggle
Machi3mfl Aug 7, 2023
cc74845
Change scape and osdfucate password depending on os selected
Machi3mfl Aug 8, 2023
12968ee
Add osdfucate and scape password for windows
Machi3mfl Aug 8, 2023
da215c6
Add windows scape password unit tests
Machi3mfl Aug 9, 2023
67249a5
Remove $ in wazuh password command param
Machi3mfl Aug 9, 2023
791be71
Fix overlay height to fix horizontal scroll
Machi3mfl Aug 9, 2023
4b6042b
Merge branch '4.7.0' into feat/5493-register-agent-handle-password-wi…
Machi3mfl Aug 9, 2023
91f2d8b
Change macos scape characters method and unit tests
Machi3mfl Aug 9, 2023
6f98e92
Change macos scape method
Machi3mfl Aug 9, 2023
9cc42b7
Fix mac os scape service unit test
Machi3mfl Aug 9, 2023
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 @@ -8,6 +8,7 @@ All notable changes to the Wazuh app project will be documented in this file.

- Support for Wazuh 4.7.0
- Added `status detail` column in the agents table. [#5680](https:/wazuh/wazuh-kibana-app/pull/5680)
- Added agent register wizard handle properly special characters in password [5738](https:/wazuh/wazuh-kibana-app/pull/5738)

### Changed

Expand Down
24 changes: 24 additions & 0 deletions docker/images/wzd-dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Usage: docker build --build-arg NODE_VERSION=16.20.0 --build-arg WAZUH_DASHBOARD_VERSION=4.6.0 -t quay.io/wazuh/osd-dev:4.6.0 -f wzd-dev.Dockerfile .

ARG NODE_VERSION
FROM node:${NODE_VERSION} AS base
ARG WAZUH_DASHBOARD_VERSION
USER node
RUN git clone --depth 1 --branch ${WAZUH_DASHBOARD_VERSION} https:/wazuh/wazuh-dashboard.git /home/node/kbn
RUN chown node.node /home/node/kbn

WORKDIR /home/node/kbn
RUN yarn osd bootstrap --production


WORKDIR /home/node/kbn/plugins
RUN git clone --depth 1 --branch ${WAZUH_DASHBOARD_VERSION} https:/wazuh/wazuh-security-dashboards-plugin.git
WORKDIR /home/node/kbn/plugins/wazuh-security-dashboards-plugin
RUN yarn install

RUN mkdir -p /home/node/kbn/data/wazuh/config

FROM node:${NODE_VERSION}
USER node
COPY --chown=node:node --from=base /home/node/kbn /home/node/kbn
WORKDIR /home/node/kbn
13 changes: 12 additions & 1 deletion docker/osd-dev/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ os_versions=(
'2.4.0'
'2.4.1'
'2.6.0'
'2.8.0'
'2.9.0'
)

osd_versions=(
Expand All @@ -20,6 +22,8 @@ osd_versions=(
'2.4.0'
'2.4.1'
'2.6.0'
'4.6.0'
'4.7.0'
)

usage() {
Expand Down Expand Up @@ -71,9 +75,16 @@ export OSD_VERSION=$2
export OSD_PORT=${PORT:-5601}
export IMPOSTER_PORT=8081
export SRC=$3
export OSD_MAJOR=$(echo $OSD_VERSION | cut -d. -f1).x
export OSD_MAJOR_NUMBER=$(echo $OSD_VERSION | cut -d. -f1)
export COMPOSE_PROJECT_NAME=os-dev-${OSD_VERSION//./}

if [[ "$OSD_MAJOR_NUMBER" -ge 2 ]];
then
export OSD_MAJOR="2.x"
else
export OSD_MAJOR="1.x"
fi

profile="standard"
export WAZUH_DASHBOARD_CONF=./config/${OSD_MAJOR}/osd/opensearch_dashboards.yml
export SEC_CONFIG_FILE=./config/${OSD_MAJOR}/os/config.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
position: absolute;
top: 0;
width: 100%;
height: 100%;
height: 90%;
display: flex;
flex-direction: column;
justify-content: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@elastic/eui';
import React, { Fragment, useEffect, useState } from 'react';
import { tOperatingSystem } from '../../core/config/os-commands-definitions';
import { osdfucatePasswordInCommand } from '../../services/wazuh-password-service';

interface ICommandSectionProps {
commandText: string;
Expand All @@ -20,13 +21,6 @@ interface ICommandSectionProps {

export default function CommandOutput(props: ICommandSectionProps) {
const { commandText, showCommand, onCopy, os, password } = props;
const getHighlightCodeLanguage = (os: 'WINDOWS' | string) => {
if (os.toLowerCase() === 'windows') {
return 'powershell';
} else {
return 'bash';
}
};
const [havePassword, setHavePassword] = useState(false);
const [showPassword, setShowPassword] = useState(false);

Expand All @@ -45,27 +39,23 @@ export default function CommandOutput(props: ICommandSectionProps) {
setHavePassword(false);
setCommandToShow(commandText);
}
}, [password, commandText, showPassword])

}, [password, commandText, showPassword]);

const osdfucatePassword = (password: string) => {
if(!password) return;
if(!commandText) return;
if (!password) return;
if (!commandText) return;

if(showPassword){
if (showPassword) {
setCommandToShow(commandText);
}else{
// search password in commandText and replace with * for every character
const findPassword = commandText.search(password);
if (findPassword > -1) {
let command = commandText;
setCommandToShow(command.replace(/WAZUH_REGISTRATION_PASSWORD='([^']+)'/,`WAZUH_REGISTRATION_PASSWORD='${'*'.repeat(password.length)}'`));
}
} else {
setCommandToShow(osdfucatePasswordInCommand(password, commandText, os));
}
}

};
const onChangeShowPassword = (event: EuiSwitchEvent) => {
setShowPassword(event.target.checked);
}
};

return (
<Fragment>
Expand All @@ -76,7 +66,7 @@ export default function CommandOutput(props: ICommandSectionProps) {
style={{
zIndex: '100',
}}
language={getHighlightCodeLanguage(os || '')}
language='tsx'
>
{showCommand ? commandToShow : ''}
</EuiCodeBlock>
Expand All @@ -96,7 +86,13 @@ export default function CommandOutput(props: ICommandSectionProps) {
)}
</div>
<EuiSpacer size='s' />
{showCommand && havePassword ? <EuiSwitch checked={showPassword} label='Show password' onChange={onChangeShowPassword}/> : null}
{showCommand && havePassword ? (
<EuiSwitch
checked={showPassword}
label='Show password'
onChange={onChangeShowPassword}
/>
) : null}
</EuiText>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
validateServerAddress,
validateAgentName,
} from '../../utils/validations';
import { getPasswordWithScapedSpecialCharacters } from '../../services/wazuh-password-service';


interface IRegisterAgentProps {
getWazuhVersion: () => Promise<string>;
Expand Down Expand Up @@ -127,6 +129,7 @@ export const RegisterAgent = withReduxProvider(
configuration['enrollment.password'] ||
authInfo['authd.pass'] ||
'';
//wazuhPassword = getPasswordWithScapedSpecialCharacters(wazuhPassword);
}
const groups = await getGroups();
setNeedsPassword(needsPassword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const Steps = ({
) {
selectOS(registerAgentFormValues.operatingSystem as tOperatingSystem);
}
setOptionalParams({ ...registerAgentFormValues.optionalParams });
setOptionalParams({ ...registerAgentFormValues.optionalParams }, registerAgentFormValues.operatingSystem as tOperatingSystem);
setInstallCommandWasCopied(false);
setStartCommandWasCopied(false);
}, [registerAgentFormValues]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getMacosStartCommand,
getWindowsInstallCommand,
getWindowsStartCommand } from '../../services/register-agent-os-commands-services';
import { scapeSpecialCharsForLinux, scapeSpecialCharsForMacOS, scapeSpecialCharsForWindows } from '../../services/wazuh-password-service';
import { IOSDefinition, tOptionalParams } from '../register-commands/types';

// Defined OS combinations
Expand Down Expand Up @@ -149,21 +150,21 @@ export const osCommandsDefinitions = [
export const optionalParamsDefinitions: tOptionalParams<tOptionalParameters> = {
serverAddress: {
property: 'WAZUH_MANAGER',
getParamCommand: props => {
getParamCommand: (props,selectedOS) => {
const { property, value } = props;
return value !== '' ? `${property}='${value}'` : '';
},
},
agentName: {
property: 'WAZUH_AGENT_NAME',
getParamCommand: props => {
getParamCommand: (props,selectedOS) => {
const { property, value } = props;
return value !== '' ? `${property}='${value}'` : '';
},
},
agentGroups: {
property: 'WAZUH_AGENT_GROUP',
getParamCommand: props => {
getParamCommand: (props,selectedOS) => {
const { property, value } = props;
let parsedValue = value;
if (Array.isArray(value)) {
Expand All @@ -174,16 +175,34 @@ export const optionalParamsDefinitions: tOptionalParams<tOptionalParameters> = {
},
protocol: {
property: 'WAZUH_PROTOCOL',
getParamCommand: props => {
getParamCommand: (props,selectedOS) => {
const { property, value } = props;
return value !== '' ? `${property}='${value}'` : '';
},
},
wazuhPassword: {
property: 'WAZUH_REGISTRATION_PASSWORD',
getParamCommand: props => {
getParamCommand: (props,selectedOS) => {
const { property, value } = props;
return value !== '' ? `${property}='${value}'` : '';
if(!value){
return '';
}
if(selectedOS){
let osName = selectedOS.name.toLocaleLowerCase();
switch(osName){
case "linux":
return `${property}=$'${scapeSpecialCharsForLinux(value)}'`;
case "macos":
return `${property}='${scapeSpecialCharsForMacOS(value)}'`;
case "windows":
return `${property}='${scapeSpecialCharsForWindows(value)}'`;
default:
return `${property}=$'${value}'`;
}

}

return value !== '' ? `${property}=$'${value}'` : '';
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export class CommandGenerator<OS extends IOperationSystem, Params extends string
* @param props - The optional parameters to select
* @returns The selected optional parameters
*/
addOptionalParams(props: IOptionalParameters<Params>): void {
addOptionalParams(props: IOptionalParameters<Params>, selectedOS?: OS): void {
// Get all the optional parameters based on the given parameters
this.optionals = this.optionalsManager.getAllOptionalParams(props);
this.optionals = this.optionalsManager.getAllOptionalParams(props, selectedOS);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { tOperatingSystem } from '../../config/os-commands-definitions';
import { NoOptionalParamFoundException } from '../exceptions';
import { IOptionalParamInput, IOptionalParameters, IOptionalParametersManager, tOptionalParams } from '../types';
import { IOperationSystem, IOptionalParamInput, IOptionalParameters, IOptionalParametersManager, tOptionalParams } from '../types';

export class OptionalParametersManager<Params extends string> implements IOptionalParametersManager<Params> {
constructor(private optionalParamsConfig: tOptionalParams<Params>) {}
Expand All @@ -10,7 +11,7 @@ export class OptionalParametersManager<Params extends string> implements IOption
* @returns The command string for the given optional parameter.
* @throws NoOptionalParamFoundException if the given optional parameter name is not found in the configuration.
*/
getOptionalParam(props: IOptionalParamInput<Params>) {
getOptionalParam(props: IOptionalParamInput<Params>, selectedOS?: IOperationSystem) {
const { value, name } = props;
if (!this.optionalParamsConfig[name]) {
throw new NoOptionalParamFoundException(name);
Expand All @@ -19,7 +20,8 @@ export class OptionalParametersManager<Params extends string> implements IOption
value,
property: this.optionalParamsConfig[name].property,
name
});
},
selectedOS);
}

/**
Expand All @@ -28,7 +30,7 @@ export class OptionalParametersManager<Params extends string> implements IOption
* @returns An object containing the command strings for all optional parameters with non-empty values.
* @throws NoOptionalParamFoundException if any of the given optional parameter names is not found in the configuration.
*/
getAllOptionalParams(paramsValues: IOptionalParameters<Params>){
getAllOptionalParams(paramsValues: IOptionalParameters<Params>, selectedOS: IOperationSystem){
// get keys for only the optional params with values !== ''
const optionalParams = Object.keys(paramsValues).filter(key => paramsValues[key as keyof typeof paramsValues] !== '') as Array<keyof typeof paramsValues>;
const resolvedOptionalParams: any = {};
Expand All @@ -42,7 +44,7 @@ export class OptionalParametersManager<Params extends string> implements IOption
name: param as Params,
value: paramsValues[param] as string,
property: paramDef.property
}) as string;
}, selectedOS) as string;
}
return resolvedOptionalParams;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/////////////////////////////////////////////////////////
/// Domain

import { tOperatingSystem } from "../../hooks/use-register-agent-commands.test";

/////////////////////////////////////////////////////////
export interface IOperationSystem {
name: string;
Expand Down Expand Up @@ -51,7 +54,7 @@ export type tOptionalParamsCommandProps<T extends string> = IOptionalParamProps
};
export interface IOptionsParamConfig<T extends string> {
property: string;
getParamCommand: (props: tOptionalParamsCommandProps<T>) => string;
getParamCommand: (props: tOptionalParamsCommandProps<T>, selectedOS?: IOperationSystem) => string;
}

export type tOptionalParams<T extends string> = {
Expand All @@ -64,7 +67,7 @@ export interface IOptionalParamInput<T extends string> {
}
export interface IOptionalParametersManager<T extends string> {
getOptionalParam(props: IOptionalParamInput<T>): string;
getAllOptionalParams(paramsValues: IOptionalParameters<T>): object;
getAllOptionalParams(paramsValues: IOptionalParameters<T>, selectedOs?: IOperationSystem): object;
}

///////////////////////////////////////////////////////////////////
Expand All @@ -79,7 +82,7 @@ export interface ICommandGenerator<OS extends IOperationSystem, Params extends s

export interface ICommandGeneratorMethods<T extends string> {
selectOS(params: IOperationSystem): void;
addOptionalParams(props: IOptionalParameters<T>): void;
addOptionalParams(props: IOptionalParameters<T>, osSelected?: IOperationSystem): void;
getInstallCommand(): string;
getStartCommand(): string;
getUrlPackage(): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IUseRegisterCommandsProps<OS extends IOperationSystem, Params extends

interface IUseRegisterCommandsOutput<OS extends IOperationSystem, Params extends string> {
selectOS: (params: OS) => void;
setOptionalParams: (params: IOptionalParameters<Params>) => void;
setOptionalParams: (params: IOptionalParameters<Params>, selectedOS?: OS) => void;
installCommand: string;
startCommand: string;
optionalParamsParsed: IOptionalParameters<Params> | {};
Expand Down Expand Up @@ -62,7 +62,7 @@ export function useRegisterAgentCommands<OS extends IOperationSystem, Params ext
}
if (optionalParamsValues) {
commandGenerator.addOptionalParams(
optionalParamsValues as IOptionalParameters<Params>,
optionalParamsValues as IOptionalParameters<Params>, osSelected
);
}
const installCommand = commandGenerator.getInstallCommand();
Expand Down Expand Up @@ -93,8 +93,8 @@ export function useRegisterAgentCommands<OS extends IOperationSystem, Params ext
* @param {IOptionalParameters} params - The optional parameters to be set.
* @returns {void}
*/
const setOptionalParams = (params: IOptionalParameters<Params>): void => {
commandGenerator.addOptionalParams(params);
const setOptionalParams = (params: IOptionalParameters<Params>, selectedOS?: OS): void => {
commandGenerator.addOptionalParams(params,selectedOS);
setOptionalParamsValues(params);
setOptionalParamsParsed(commandGenerator.getOptionalParamsCommands());
};
Expand Down
Loading
Loading