Closed c-bordon closed 9 months ago
These messages are the outputs of the execution of the certificate creation commands. In other words, this affects the certs-tool.
The debug option shows the output of the command as is, so the options I consider are:
1- remove the debug in these commands, with the risk of not capturing error messages in these commands.
2- Add more descriptive messages, such as, we are creating this certificate
:
vagrant@ubuntu22:~$ openssl req -x509 -new -nodes -newkey rsa:2048 -keyout root-ca.key -out root-ca.pem -batch -subj '/OU=Wazuh/O=Wazuh/L=California/' -days 3650
..+...+........+.+.....+.+...+.....+............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+..+.+...+............+...+...............+.........+...+.....+....+....................+.+........+.+.....+..........+.........+..+...+......+...+...............+...+...+....+........+.........+.........+.......+........+....+.....+......+....+..................+...+......+...+..+....+..+...............+...+......+...+.+.....+.+.....+.........+....+...........+.+...+..+.........+....+........+.........+................+.........+...+..+.+.........+......+..+.+..+...............+....+.........+.....+....+............+.....+...+......+.......+.....+.........+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+......+...+....................+...+....+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+....+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+............+............+......+...+......+........................+....+..+.+....................+....+........+.+..+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
The message can be added in this block (example):
function cert_generateIndexercertificates() {
common_logger -d "Generating Wazuh indexer certificates."
if [ ${#indexer_node_names[@]} -gt 0 ]; then
for i in "${!indexer_node_names[@]}"; do
indexer_node_name=${indexer_node_names[$i]}
cert_generateCertificateconfiguration "${indexer_node_name}" "${indexer_node_ips[i]}"
common_logger -d "Creating the Wazuh indexer tmp key pair."
eval "openssl req -new -nodes -newkey rsa:2048 -keyout ${cert_tmp_path}/${indexer_node_name}-key.pem -out ${cert_tmp_path}/${indexer_node_name}.csr -config ${cert_tmp_path}/${indexer_node_name}.conf ${debug}"
common_logger -d "Creating the Wazuh indexer certificates."
eval "openssl x509 -req -in ${cert_tmp_path}/${indexer_node_name}.csr -CA ${cert_tmp_path}/root-ca.pem -CAkey ${cert_tmp_path}/root-ca.key -CAcreateserial -out ${cert_tmp_path}/${indexer_node_name}.pem -extfile ${cert_tmp_path}/${indexer_node_name}.conf -extensions v3_req -days 3650 ${debug}"
done
else
return 1
fi
}
The output can be silenced using the > /dev/null 2>&1
parameters, redirecting the stderr
and the stdout
to /dev/null
(discarding all types of output)
vagrant@ubuntu22:~$ openssl req -x509 -new -nodes -newkey rsa:2048 -keyout root-ca.key -out root-ca.pem -batch -subj '/OU=Wazuh/O=Wazuh/L=California/' -days 3650 >> /dev/null 2>&1
vagrant@ubuntu22:~$ echo $?
0
As we are removing the debug in these commands with the risk of not capturing error messages in these commands, it would be desirable to check if the commands are being executed correctly.
The related functions are:
cert_generateRootCAcertificate
cert_generateAdmincertificate
cert_generateIndexercertificates
cert_generateFilebeatcertificates
cert_generateDashboardcertificates
The cert_generateRootCAcertificate
function:
function cert_generateRootCAcertificate() {
common_logger -d "Creating the root certificate."
# Create the root certificate
eval "openssl req -x509 -new -nodes -newkey rsa:2048 -keyout ${cert_tmp_path}/root-ca.key -out ${cert_tmp_path}/root-ca.pem -batch -subj '/OU=Wazuh/O=Wazuh/L=California/' -days 3650" > /dev/null 2>&1
# Validate the root certificate creation
if [ "${PIPESTATUS[0]}" != 0 ]; then
common_logger -e "Error creating Root CA certificate."
return 1
fi
}
The cert_generateIndexercertificates
function:
function cert_generateIndexercertificates() {
common_logger -d "Generating Wazuh indexer certificates."
if [ ${#indexer_node_names[@]} -gt 0 ]; then
common_logger -d "Creating the Wazuh indexer certificates."
for i in "${!indexer_node_names[@]}"; do
indexer_node_name=${indexer_node_names[$i]}
cert_generateCertificateconfiguration "${indexer_node_name}" "${indexer_node_ips[i]}"
eval "openssl req -new -nodes -newkey rsa:2048 -keyout ${cert_tmp_path}/${indexer_node_name}-key.pem -out ${cert_tmp_path}/${indexer_node_name}.csr -config ${cert_tmp_path}/${indexer_node_name}.conf" > /dev/null 2>&1
eval "openssl x509 -req -in ${cert_tmp_path}/${indexer_node_name}.csr -CA ${cert_tmp_path}/root-ca.pem -CAkey ${cert_tmp_path}/root-ca.key -CAcreateserial -out ${cert_tmp_path}/${indexer_node_name}.pem -extfile ${cert_tmp_path}/${indexer_node_name}.conf -extensions v3_req -days 3650" > /dev/null 2>&1
# Validate the certificate creation
if [ "${PIPESTATUS[0]}" != 0 ] || [ "${PIPESTATUS[1]}" != 0 ]; then
common_logger -e "Error creating certificate for ${indexer_node_name}."
return 1
fi
done
else
return 1
fi
}
The cert_generateAdmincertificate
function:
function cert_generateAdmincertificate() {
common_logger -d "Generating Admin certificates."
# Generate private key
eval "openssl genrsa -out ${cert_tmp_path}/admin-key-temp.pem 2048" > /dev/null 2>&1
if [ "${PIPESTATUS[0]}" != 0 ]; then
common_logger -e "Error generating Admin private key."
return 1
fi
# Convert private key to PKCS8 format
eval "openssl pkcs8 -inform PEM -outform PEM -in ${cert_tmp_path}/admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out ${cert_tmp_path}/admin-key.pem" > /dev/null 2>&1
if [ "${PIPESTATUS[0]}" != 0 ]; then
common_logger -e "Error converting Admin private key to PKCS8 format."
return 1
fi
# Generate certificate signing request (CSR)
eval "openssl req -new -key ${cert_tmp_path}/admin-key.pem -out ${cert_tmp_path}/admin.csr -batch -subj '/C=US/L=California/O=Wazuh/OU=Wazuh/CN=admin'" > /dev/null 2>&1
if [ "${PIPESTATUS[0]}" != 0 ]; then
common_logger -e "Error generating Admin CSR."
return 1
fi
# Sign the certificate
eval "openssl x509 -days 3650 -req -in ${cert_tmp_path}/admin.csr -CA ${cert_tmp_path}/root-ca.pem -CAkey ${cert_tmp_path}/root-ca.key -CAcreateserial -sha256 -out ${cert_tmp_path}/admin.pem" > /dev/null 2>&1
if [ "${PIPESTATUS[0]}" != 0 ]; then
common_logger -e "Error creating Admin certificate."
return 1
fi
}
The cert_generateFilebeatcertificates
function:
function cert_generateFilebeatcertificates() {
common_logger -d "Generating Filebeat certificates."
if [ ${#server_node_names[@]} -gt 0 ]; then
common_logger -d "Creating the Wazuh server certificates."
for i in "${!server_node_names[@]}"; do
server_name="${server_node_names[i]}"
j=$((i+1))
declare -a server_ips=(server_node_ip_"$j"[@])
cert_generateCertificateconfiguration "${server_name}" "${!server_ips}"
eval "openssl req -new -nodes -newkey rsa:2048 -keyout ${cert_tmp_path}/${server_name}-key.pem -out ${cert_tmp_path}/${server_name}.csr -config ${cert_tmp_path}/${server_name}.conf" > /dev/null 2>&1
eval "openssl x509 -req -in ${cert_tmp_path}/${server_name}.csr -CA ${cert_tmp_path}/root-ca.pem -CAkey ${cert_tmp_path}/root-ca.key -CAcreateserial -out ${cert_tmp_path}/${server_name}.pem -extfile ${cert_tmp_path}/${server_name}.conf -extensions v3_req -days 3650" > /dev/null 2>&1
# Validate the certificate creation
if [ "${PIPESTATUS[0]}" != 0 ] || [ "${PIPESTATUS[1]}" != 0 ]; then
common_logger -e "Error creating certificate for ${server_name}."
return 1
fi
done
else
return 1
fi
}
The cert_generateDashboardcertificates
function:
function cert_generateDashboardcertificates() {
common_logger -d "Generating Wazuh dashboard certificates."
if [ ${#dashboard_node_names[@]} -gt 0 ]; then
common_logger -d "Creating the Wazuh dashboard certificates."
for i in "${!dashboard_node_names[@]}"; do
dashboard_node_name="${dashboard_node_names[i]}"
cert_generateCertificateconfiguration "${dashboard_node_name}" "${dashboard_node_ips[i]}"
eval "openssl req -new -nodes -newkey rsa:2048 -keyout ${cert_tmp_path}/${dashboard_node_name}-key.pem -out ${cert_tmp_path}/${dashboard_node_name}.csr -config ${cert_tmp_path}/${dashboard_node_name}.conf" > /dev/null 2>&1
eval "openssl x509 -req -in ${cert_tmp_path}/${dashboard_node_name}.csr -CA ${cert_tmp_path}/root-ca.pem -CAkey ${cert_tmp_path}/root-ca.key -CAcreateserial -out ${cert_tmp_path}/${dashboard_node_name}.pem -extfile ${cert_tmp_path}/${dashboard_node_name}.conf -extensions v3_req -days 3650" > /dev/null 2>&1
# Validate the certificate creation
if [ "${PIPESTATUS[0]}" != 0 ] || [ "${PIPESTATUS[1]}" != 0 ]; then
common_logger -e "Error creating certificate for ${dashboard_node_name}."
return 1
fi
done
else
return 1
fi
}
@davidjiglesias if we suppress the log mentioned in the description, we will also suppress the error log. We didn't find a way to get rid only of the ++---+++
log.
I think that the only improvement we can add is the one proposed by @c-bordon here:
2- Add more descriptive messages, such as, we are creating this certificate
@davidcr01 will continue to implement this.
As removing the ++--++
output is very desirable, I will implement a methodology that will perform the following steps in the openssl
commands:
With this, the output will be silenced but shown when an error is generated. By this way, we are catching the possible errors while reducing the noise of the script output.
Description
The output that we are showing in the verbose mode when creating the keys, is confusing and not descriptive. We have to validate if we can avoid this output: