Updated Password Tool to add default user and password to the filebeat.yml when changing passwords. #2989
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As seen on related issue, the user for Filebeat connection was
wazuh
before 4.3.x version. When you tried to migrate to a newer version and then change the passwords, thefilebeat.yml
file remained witht the same username that waswazuh
. This breaks the installations as the user by default for Filebeat connection isadmin
from 4.3.x versions onwards. More information can be seen here: #1369 (comment)First aim
So, the aim of this PR is to change the Password Tool so that when a password change is requested for all users, it ensures the
filebeat.yml
file that the username isadmin
and the password is updated to the new one.To do that I added the
username: admin
to this line:More changes
In addition, while doing the tests, I realized that the way the Password Tool works is that when it detects that the password variable exists in the Filebeat Keystore, it assumes that in the
filebeat.yml
file${username}
is used as username and${password}
as password.But it could be that there was plain text instead of variables in the
filebeat.yml
, and this would break the operation. So we decided that, in addition, we would add that when it is detected that the Keystore variables are being used, thefilebeat.yml
is updated and what is there is replaced with the Filebeat Keystore variables.We divided the change in two operations. The first one will check if there is a variable on the Filebeat Keystore with the name
password
and, if so, we update the password with the new one and change thefilebeat.yml
with the${password}
variable. The second one will be inside the first one and, if there is a variable calledpassword
on the Filebeat Keystore, then we check for a variable namedusername
and, if it's found, we update thefilebeat.yml
username field with the${username}
variable in order to add more sturdiness.Also a log was added to report the user about these changes.
To do that I added these lines:
Tests
Tests for the plain text case
I manually changed the username to other than admin to see if it's updated to admin when passwords are changed.And after the passwords are changed with:
The username is updated to admin and the passwords is updated to the new one too:
Tests for the Filebeat Keystore case
We are going to test if with Filebeat Keystore variables configured, the Password Tool changes the plain text on the `filebeat.yml` to the variables used on the Keystore.Check if the Keystore has the password variable:
Manually change the username and password values to plain text:
And after changing the password with:
We can see that the log reports the user about the change made and the
filebeat.yml
file looks like this:But, if the user wants to use the user on plain text and the password on the Filbeat Keystore. For that, we did also a test.
The
filebeat.yml
file:We first delete the username of the Keystore. And the output when changing passwords:
The filebeat.yml file remains like this:
Final version
As the final improved version of this PR we thought it would be better to always use Filebeat Keystore in order to grant more security. So, if the user had configured the username or password in plain text in the
filebeat.ym
l file, he will be warned that this will be changed when changing the passwords and the default admin user and the new password will be stored in the Filebeat Keystore. To change the user you can refer to the updated documentation with this change.Tests for the final version
Test with plain text both on username and password
The
filebeat.yml
:When changing the passwords:
The final
filebeat.yml
:Tests with one variable in plain text and the other on the correct variable
The
filebeat.yml
:Changing the passwords:
Tests with both on correct variables
The
filebeat.yml
:Changing the passwords: