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 issue when there is more than one API user #1057

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vhsantos
Copy link

@vhsantos vhsantos commented Oct 5, 2023

What

  • Fixed the admin.json.j2 template to create valid JSON files.
  • Modified the create_user.py script to read and process all user/password pairs from the admin.json file.
  • Removed unnecessary parameters (--username and --password) from the Ansible task command that runs create_user.py.

Why

  1. When setting multiple API users or using default users like wazuh and wazuh-gui in the wazuh_api_users variable, the admin.json.j2 template was generating an invalid JSON file, like:
{"username":"wazuh", "password": "XXXXXX?o?uqu4eiria7j"}
{"username":"wazuh-gui", "password": "XXXXXXX?eirae.Woo9pushie"}
{"username":"custom-vhs", "password": "XXXXXXX??lSsJFEVXOBi7475k.u?MDX"}

which generate this error when the **create_user.py ** script try to read the file:

# /var/ossec/framework/python/bin/python3 create_user.py
Traceback (most recent call last):
  File "/var/ossec/framework/scripts/create_user.py", line 71, in <module>
    users = read_user_file()
  File "/var/ossec/framework/scripts/create_user.py", line 31, in read_user_file
    data = json.load(user_file)
  File "/var/ossec/framework/python/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/var/ossec/framework/python/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/var/ossec/framework/python/lib/python3.9/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 3 column 1 (char 62)

With this fix, the template ensures that each user/password pair is correctly enclosed within its JSON object, resulting in valid JSON.

[
{"username":"wazuh", "password": "XXXXXX?o?uqu4eiria7j"},
{"username":"wazuh-gui", "password": "XXXXXXX?eirae.Woo9pushie"},
{"username":"custom-vhs", "password": "XXXXXXX??lSsJFEVXOBi7475k.u?MDX"}
]
  1. The create_user.py script now processes all user/password pairs from the admin.json file without requiring extra parameters (--username and --password).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant