Cryptography, Hashes, and API Configuration in Wazuh
Advanced credential synchronization, OpenSearch password hashing scripts, and cryptographic user injection into the Wazuh cluster.
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.
1. Security Hash Synchronization (Bcrypt)
Sección titulada «1. Sincronización de Hashes de Seguridad (Bcrypt)»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:
# 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"Step 2: Secure Reconstruction of the User File
Sección titulada «Paso 2: Reconstrucción Segura del Archivo de Usuarios»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:
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 lecturasudo chmod 644 ./config/wazuh_indexer/internal_users.ymlStep 3: Forced PKI Application to the Database (Injection)
Sección titulada «Paso 3: Aplicación Forzada de la PKI en la Base de Datos (Inyección)»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:
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.pemIf the injection completes successfully, the console output should end with the message: Done with success.
2. Dashboard Configuration and Connectivity (API Link)
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.
Step 1: Controlled Dashboard Shutdown
Sección titulada «Paso 1: Detención Controlada del Dashboard»To avoid collisions when editing system files live, momentarily shut down the graphical interface:
sudo docker compose stop wazuh.dashboardStep 2: Inject Clean Configuration and Credentials
Sección titulada «Paso 2: Inyectar Configuración y Credenciales Limpias»We overwrite the Dashboard file, ensuring correct YAML syntactic nesting (avoiding duplicate base tags):
cat << 'EOF' > ./config/wazuh_dashboard/wazuh.ymlhosts: - default: url: https://wazuh.manager port: 55000 username: wazuh-wui password: mP5nT8qB2vK9wR3xY6cS4dB9. run_as: falseEOFStep 3: Service Restart
Sección titulada «Paso 3: Rearranque de Servicios»Reinitializes the user interface and forces the restart of the analytical manager to consolidate network channels:
sudo docker compose start wazuh.dashboardsudo docker compose restart wazuh.manager
