Ir al contenido

Cryptography, Hashes, and API Configuration in Wazuh

Advanced credential synchronization, OpenSearch password hashing scripts, and cryptographic user injection into the Wazuh cluster.

0views

The greatest architectural challenge in implementing Wazuh via Docker containers lies in the fact that the indexing database (OpenSearch / Wazuh Indexer) does not read or process plain text passwords. For security reasons, it requires translating the passwords from the orchestration file into encrypted hashes using the bcrypt security algorithm and injecting them at a low level using the internal administration tool.

Hash Persistence

This synchronization and hash generation workflow must obligatorily be executed during each new cluster provisioning, or after performing a complete purge of system volumes with the instruction: sudo docker compose down -v.


Ensure that the cluster containers are up and active in the Docker engine (sudo docker compose up -d) and execute the following command sequence from the /opt/wazuh-stack/single-node directory:

Step 1: Generation and Extraction of Cryptographic Hashes

Sección titulada «Paso 1: Generación y Extracción de Hashes Criptográficos»

We invoke the native hashing script (hash.sh) hosted in the storage container, forcing the use of the container host's internal Java environment variable:

Ventana de terminal
# 1. Generar y exportar el hash encriptado del usuario 'admin'
HASH_ADMIN=$(sudo docker compose exec --env JAVA_HOME=/usr/share/wazuh-indexer/jdk wazuh.indexer bash /usr/share/wazuh-indexer/plugins/opensearch-security/tools/hash.sh -p zR9mK2vX5pW8qN3tY6cR4vB1 | grep '\$2')
# 2. Generar y exportar el hash encriptado del usuario de servicios 'kibanaserver'
HASH_KIBANA=$(sudo docker compose exec --env JAVA_HOME=/usr/share/wazuh-indexer/jdk wazuh.indexer bash /usr/share/wazuh-indexer/plugins/opensearch-security/tools/hash.sh -p yQ3wV8xR9pK2mN6tT5sR4vC1 | grep '\$2')
# 3. VERIFICACIÓN (Paso crítico: valida que las variables contienen texto cifrado)
echo "HASH ADMIN ES: $HASH_ADMIN"
echo "HASH KIBANA ES: $HASH_KIBANA"

To avoid inode issues caused by atypical Docker volume mounts, we will rewrite and apply permissions to the user configuration file directly from the host terminal:

Ventana de terminal
cat << EOF > ./config/wazuh_indexer/internal_users.yml
_meta:
type: "internalusers"
config_version: 2
admin:
hash: "$HASH_ADMIN"
reserved: true
backend_roles: ["admin"]
description: "Admin user"
kibanaserver:
hash: "$HASH_KIBANA"
reserved: true
description: "Kibana user"
EOF
# Aplicar permisos correctos de lectura
sudo chmod 644 ./config/wazuh_indexer/internal_users.yml

Run the security initialization tool securityadmin.sh by feeding it the digital signatures of your internal certificates to force the indexer to rebuild the user database:

Ventana de terminal
sudo docker compose exec --env JAVA_HOME=/usr/share/wazuh-indexer/jdk wazuh.indexer bash /usr/share/wazuh-indexer/plugins/opensearch-security/tools/securityadmin.sh -cd /usr/share/wazuh-indexer/opensearch-security/ -icl -nhnv -cacert /usr/share/wazuh-indexer/certs/root-ca.pem -cert /usr/share/wazuh-indexer/certs/admin.pem -key /usr/share/wazuh-indexer/certs/admin-key.pem

If the injection completes successfully, the console output should end with the message: Done with success.


Sección titulada «2. Configuración y Conectividad del Dashboard (API Link)»

Once the identity database is operational, we must instruct the Dashboard to connect to the Wazuh Manager using credentials authorized in the API.

To avoid collisions when editing system files live, momentarily shut down the graphical interface:

Ventana de terminal
sudo docker compose stop wazuh.dashboard

We overwrite the Dashboard file, ensuring correct YAML syntactic nesting (avoiding duplicate base tags):

Ventana de terminal
cat << 'EOF' > ./config/wazuh_dashboard/wazuh.yml
hosts:
- default:
url: https://wazuh.manager
port: 55000
username: wazuh-wui
password: mP5nT8qB2vK9wR3xY6cS4dB9.
run_as: false
EOF

Reinitializes the user interface and forces the restart of the analytical manager to consolidate network channels:

Ventana de terminal
sudo docker compose start wazuh.dashboard
sudo docker compose restart wazuh.manager