Plaintext database user and password in config.php

Hey guys, I’m absolutely new here and not yet very experienced with Nextcloud. I just installed Nextcloud 15.0.5 on the webspace of our external provider. What I recognized is, that user and password of the Nextcloud database is stored in plaintext in the config.php file.

Well, I’m not a IT security expert - but this seems to be strange to me…

Even if access to this file is restricted, I’m pretty sure, the admin of the provider will habe access to read this file.

I really used the search function in this board but did not get useful results for me. If this topic was discussed before, I’m sorry to open a new thread…

My questions:

  1. Is this a security issue?
  2. Is this a bad configuration issue from my side?
  3. What is your suggestion to deal with this point?

Thanks a lot!
Tonio

This is how most webapps handles database connections. Wordpress for example does the same. The configuration has the username and password in plaintext.

This is not optimal from a security point. But it is pretty much the only way if keeping things simple enough.

Wow, thank you very much for this quick reponse! So… I guess Owncloud will handle this issue the same way?

Yes they do.

1 Like

In php, it is possible to use the getenv statement to get the value of an environment variable.
With this method, you can use safe software (Hashicorp Vault, Secret Server, etc.) and use dynamic authentication.

Thus, “most webapps” are not secure and do not respect good practices. TLS 1.2/1.3 do not completely protect an application. Securing authentication elements is an important principle.

The findings are as follows. Nextcloud wants to help having private clouds to prevent attacks. The problem is that the attack can come from the inside. And having the passwords in clear text in a configuration file is a major security flaw. A loophole that could be easily solved if Nextcloud wanted to make it happen. Which doesn’t seem to be the case.

Here a sample of code to use env var in config.php

config.php

<?php
$dbname = getenv('MYSQL_DATABASE') ;
$dbuser = getenv('MYSQL_USER');
$dbpassword = getenv('MYSQL_PASSWORD');
$dbhost = getenv('MYSQL_HOST');

$CONFIG = array {
...
...
),
'dbname' => $dbname,
'dbuser' => $dbuser,
'dbhost' => $dbhost,
'dbpassword' => $dbpassword,
....
}

And if you use docker, and vault, you can try this :slight_smile:

copy entrypoint.sh, and modify. then use a volume to map the file inside the container

#!/bin/sh
set -eu

apt update -y && apt install -y jq

VLT_TOKEN=$(curl -s -X POST -d '{"role_id":"'$ROLE_ID'","secret_id":"'$SECRET_ID'"}' $VAULT_ADDR:$VAULT_PORT/v1/auth/approle/login | jq -r '.auth.client_token')
DB_KEYS=$(curl -s -H "X-Vault-Token:$VLT_TOKEN" ${VAULT_ADDR}:${VAULT_PORT}/v1/${VAULT_NEXTCLOUD_DB_PATH})
export MYSQL_DATABASE=$(echo $DB_KEYS | jq -r '.data.data.MYSQL_DATABASE')
export MYSQL_PASSWORD=$(echo $DB_KEYS | jq -r '.data.data.MYSQL_PASSWORD')
export MYSQL_USER=$(echo $DB_KEYS | jq -r '.data.data.MYSQL_USER')

ROLE_ID and SECRET_ID can be generated by another scripts (in case of dynamic credential of the database) and injected to the container. Or using a secret (Swarm, Kubernested, Consol, etc…)