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

Installation assistant Wazuh API default password change #1548

Merged
merged 45 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fd27e47
Added function to generate new passwords for the API
miguelfdez99 May 13, 2022
b6866c9
Added function to change API passswords
miguelfdez99 May 13, 2022
171d256
Added function to update wazuh-wui API passsword
miguelfdez99 May 13, 2022
9f4155d
Update API status function to get the password from the passwords file
miguelfdez99 May 13, 2022
2822e6b
Change version to test it in jenkins
miguelfdez99 May 13, 2022
362e7f7
Change version to test it in jenkins
miguelfdez99 May 13, 2022
f769633
Fix typo
miguelfdez99 May 13, 2022
06b1918
Change version
miguelfdez99 May 16, 2022
888ecfe
Change regular expression characters
miguelfdez99 May 16, 2022
59e05f3
Added file check
miguelfdez99 May 16, 2022
424c75c
Change version
miguelfdez99 May 16, 2022
a8b3617
Delete newline
miguelfdez99 May 16, 2022
3ede3ff
Delete newline
miguelfdez99 May 16, 2022
342ed72
Added functions from installCommon to passwords
miguelfdez99 May 20, 2022
c563e90
Added API option to password tool
miguelfdez99 May 23, 2022
6297b26
Update API password function
miguelfdez99 May 24, 2022
c77d1d9
Added new options to password tool
miguelfdez99 May 24, 2022
c4362c2
Change pattern for API password generation
miguelfdez99 May 24, 2022
bb0d889
Change shift call twice to shift 2
miguelfdez99 May 25, 2022
9e22306
Change version to test it in jenkins
miguelfdez99 May 25, 2022
6fe1ccb
Update version
miguelfdez99 May 25, 2022
409e15a
Added storing API passwords in different file
miguelfdez99 May 27, 2022
d3e7a30
Change strings quoting
miguelfdez99 May 27, 2022
b07aba8
Change dashboard revision version
miguelfdez99 May 30, 2022
f59e46c
Merge branch '4.3' of https://github.com/wazuh/wazuh-packages into 15…
DFolchA Jun 2, 2022
39d59da
Remove pasword api file and fix typos
DFolchA Jun 2, 2022
ae865dc
Set version to 4.3.3
DFolchA Jun 3, 2022
2e046bc
Use correct file variable
DFolchA Jun 3, 2022
f04bb3f
Update version in test
DFolchA Jun 3, 2022
a501b5e
Use old generate password function
DFolchA Jun 6, 2022
83e3500
Modify passwords_generatePassword to generate correct password format
DFolchA Jun 6, 2022
86a2a61
Merge branch '4.3' of https://github.com/wazuh/wazuh-packages into 15…
DFolchA Jun 6, 2022
5a99ea0
Correct password string possible values
DFolchA Jun 6, 2022
eecad12
Add " to variable
DFolchA Jun 6, 2022
c910060
Add ' to installCommon_readPasswordFileUsers
DFolchA Jun 7, 2022
1ccfd05
Remove ' from password generation
DFolchA Jun 7, 2022
91d0ba5
Set pasword file strings between ''
DFolchA Jun 7, 2022
bcd7dc3
Add print to test
DFolchA Jun 7, 2022
9bf4c86
Get api password correctly from file
DFolchA Jun 7, 2022
57ec492
Remove ' and " when getting sfileusers and sfilepasswords
DFolchA Jun 8, 2022
ca5a7b5
Remove echo
DFolchA Jun 8, 2022
c8c49c9
Removed blank spaces
alberpilot Jun 8, 2022
b4c8c78
Remove unnecessary function
DFolchA Jun 8, 2022
ac09720
Merge branch '1523-unattended-change-password-api' of https://github.…
DFolchA Jun 8, 2022
d1488db
Merge branch '4.3' of https://github.com/wazuh/wazuh-packages into 15…
DFolchA Jun 8, 2022
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
2 changes: 1 addition & 1 deletion tests/unattended/install/test_unattended.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_wazuh_api_status():
host = get_indexer_ip()
port = 55000
user = 'wazuh'
password = 'wazuh'
password = get_password("wazuh")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be used the variable user a function parameter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 39d59da

login_endpoint = 'security/user/authenticate'

login_url = f"{protocol}://{host}:{port}/{login_endpoint}"
Expand Down
28 changes: 27 additions & 1 deletion unattended_installer/install_functions/installCommon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function installCommon_installPrerequisites() {

function installCommon_readPasswordFileUsers() {

filecorrect=$(grep -Ev '^#|^\s*$' "${p_file}" | grep -Pzc '\A(\s*username:[ \t]+\w+\s*password:[ \t]+[A-Za-z0-9_\-]+\s*)+\Z')
filecorrect=$(grep -Ev '^#|^\s*$' "${p_file}" | grep -Pzc '\A(\s*username:[ \t]+\w+\s*password:[ \t]+[A-Za-z0-9.*+?()[{\|]+\s*)+\Z')
if [[ "${filecorrect}" -ne 1 ]]; then
common_logger -e "The password file doesn't have a correct format.

Expand Down Expand Up @@ -528,3 +528,29 @@ function installCommon_startService() {
fi

}

function installCommon_changePasswordAPI() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be included in the password tool.


password_wazuh=$(cat /tmp/wazuh-install-files/passwords.wazuh | awk -F': ' '{print $2}' | tail -n 6 | head -n 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. SC2002

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user has set the passwords in a different order?

password_wazuh_wui=$(cat /tmp/wazuh-install-files/passwords.wazuh | awk -F': ' '{print $2}' | tail -n 2 | head -n 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. SC2002

WAZUH_PASS='{"password":"'"$password_wazuh"'"}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
WAZUH_PASS appears unused. Verify use (or export if used externally). SC2034

WAZUH_WUI_PASS='{"password":"'"$password_wazuh_wui"'"}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
WAZUH_WUI_PASS appears unused. Verify use (or export if used externally). SC2034


TOKEN=$(curl -s -u wazuh:wazuh -k -X GET "https://localhost:55000/security/user/authenticate?raw=true")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
TOKEN appears unused. Verify use (or export if used externally). SC2034

eval 'curl -s -k -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d "$WAZUH_PASS" "https://localhost:55000/security/users/1" -o /dev/null'

TOKEN_WUI=$(curl -s -u wazuh-wui:wazuh-wui -k -X GET "https://localhost:55000/security/user/authenticate?raw=true")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
TOKEN_WUI appears unused. Verify use (or export if used externally). SC2034

eval 'curl -s -k -X PUT -H "Authorization: Bearer $TOKEN_WUI" -H "Content-Type: application/json" -d "$WAZUH_WUI_PASS" "https://localhost:55000/security/users/2" -o /dev/null'

}

function installCommon_updateDashborad_WUI_Password() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be included in the password tool.


if [ -f "/usr/share/wazuh-dashboard/data/wazuh/config/wazuh.yml" ]; then
password_wazuh_wui=$(cat /tmp/wazuh-install-files/passwords.wazuh | awk -F': ' '{print $2}' | tail -n 2 | head -n 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. SC2002

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, what if the user sets the passwords in a different order?

eval 'sed -i "s|password: wazuh-wui|password: ${password_wazuh_wui}|g" /usr/share/wazuh-dashboard/data/wazuh/config/wazuh.yml'
else
echo "ERROR: File /usr/share/wazuh-dashboard/data/wazuh/config/wazuh.yml does not exist"
fi

}
5 changes: 5 additions & 0 deletions unattended_installer/install_functions/installMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ function main() {
installCommon_changePasswords
installCommon_startService "wazuh-dashboard"
dashboard_initialize
installCommon_updateDashborad_WUI_Password

fi

Expand All @@ -306,6 +307,7 @@ function main() {
filebeat_install
filebeat_configure
installCommon_changePasswords
installCommon_changePasswordAPI
installCommon_startService "filebeat"
fi

Expand All @@ -329,7 +331,10 @@ function main() {
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
installCommon_changePasswordAPI
dashboard_initializeAIO
installCommon_updateDashborad_WUI_Password

fi

# -------------- Offline case ------------------------------------------
Expand Down
19 changes: 18 additions & 1 deletion unattended_installer/passwords_tool/passwordsFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function passwords_generatePasswordFile() {
echo " password: ${passwords[${i}]}" >> "${gen_file}"
echo "" >> "${gen_file}"
done
passwords_createPasswordAPI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Use passwords_createPasswordAPI "$@" if function's $1 should mean script's $1. SC2119


}

Expand Down Expand Up @@ -217,7 +218,7 @@ function passwords_readAdmincerts() {
}

function passwords_readFileUsers() {
filecorrect=$(grep -Ev '^#|^\s*$' "${p_file}" | grep -Pzc '\A(\s*username:[ \t]+\w+\s*password:[ \t]+[A-Za-z0-9_\-]+\s*)+\Z')
filecorrect=$(grep -Ev '^#|^\s*$' "${p_file}" | grep -Pzc '\A(\s*username:[ \t]+\w+\s*password:[ \t]+[A-Za-z0-9.*+?()[{\|]+\s*)+\Z')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
p_file is referenced but not assigned. SC2154

if [[ "${filecorrect}" -ne 1 ]]; then
common_logger -e "The password file doesn't have a correct format.

Expand Down Expand Up @@ -380,3 +381,19 @@ function passwords_runSecurityAdmin() {
fi

}

function passwords_createPasswordAPI() {

password_wazuh=$(tr -dc 'A-Za-z0-9.*+?()[{\|' </dev/urandom | head -c"${1:-32}";echo;)
password_wazuh_wui=$(tr -dc 'A-Za-z0-9.*+?()[{\|' </dev/urandom | head -c"${1:-32}";echo;)

echo "# New password for wazuh API" >> "${gen_file}"
echo " username: wazuh" >> "${gen_file}"
echo " password: $password_wazuh" >> "${gen_file}"
echo "" >> "${gen_file}"
echo "# New password for wazuh-wui API" >> "${gen_file}"
echo " username: wazuh_wui" >> "${gen_file}"
echo " password: $password_wazuh_wui" >> "${gen_file}"
echo "" >> "${gen_file}"

}