Skip to main content

Managed MongoDB Credentials

A managed MongoDB on Quave One comes with a root user whose password is stored in the database environment's env vars. This page explains which variables you can change, how to change the root password, how to give each app its own user, and what to do when a password leaks.

Users and variables​

Open the database environment and go to Env. vars. You will see these variables:

VariableWhat it isCan you change it?
DB_USER_ADMINName of the admin user, root by default.No. Keep the value it was created with.
DB_PASS_ADMINPassword of the admin user.Yes. See Change the root password.
DB_PASS_QC_ADMINPassword of qcClusterAdmin, a Quave One user used for monitoring and for query analysis (Slow Queries). It can only monitor and manage the cluster, and it cannot read or write your data. It is separate from the root password.No. Leave it as is.
VERSIONMongoDB version the database runs. Not a credential.Leave it as is when you change passwords.

Quave One also creates internal users for monitoring and, when it is enabled, MongoDB Search. They are managed for you and you do not need to touch them.

Quave One manages these users: the values in Env. vars are the source of truth. Users you create yourself with createUser are yours. Quave One does not change or remove them.

Change the root password​

  1. Open the database environment, go to Env. vars, and edit DB_PASS_ADMIN.
  2. Click Apply changes.

Quave One updates the password of the root user inside MongoDB. Connections that log in with the old password are refused after that.

Applying changes restarts the database

Applying a new DB_PASS_ADMIN restarts the database members, like other changes that redeploy the database. A database with one member is unavailable for a few minutes (2 to 5 minutes in our tests), and every app connected to it loses its connection until it comes back. With more than one member, the members restart one at a time.

Plan the change for a time with little traffic, or give each app its own user first (next section) so that no app has to change its settings during the restart.

Do not change the root password from a MongoDB client, for example with db.changeUserPassword('root', ...). Quave One sets the password back to the value in DB_PASS_ADMIN within seconds. Always change it in Env. vars.

Create a user per app​

Your apps should not connect as root. Give each app its own user with access only to its own database. If one app's password leaks, only that database is exposed, and you can change the root password without touching the apps.

  1. Connect to the database as root. The connection string is in the Hosts tab of the database environment. Clients outside Quave One need the Quave One Root CA.

  2. Create one user per app in the admin database, with readWrite on the app's database:

    use admin
    db.createUser({
    user: 'my-app',
    pwd: passwordPrompt(),
    roles: [{ role: 'readWrite', db: 'my_app_db' }],
    })

    readWrite lets the app read, write and create indexes on my_app_db, and nothing else. Creating the user in admin keeps authSource=admin in the connection string valid.

  3. In the app environment, update the connection string env var (for example MONGO_URL) to use the new user. Change only the user and the password and keep the rest of the URL:

    mongodb://my-app:<password>@<hosts from the Hosts tab>/my_app_db?authSource=admin&ssl=true&replicaSet=<replica set>

    If the password has characters such as @, : or /, URL-encode them.

  4. Click Apply changes on the app and check that it starts and reads its data. Do one app at a time.

Users you create keep working across restarts and root password changes.

Change an app user's password​

App users are not managed by Quave One, so you change them from a MongoDB client, and the database does not restart. To avoid any login failures, replace the user instead of changing it in place:

  1. Create a new user for the app, for example my-app-2, as in Create a user per app.
  2. Switch the app's connection string to the new user and apply.
  3. Once the app runs on the new user, remove the old one with db.getSiblingDB('admin').dropUser('my-app').

If a password leaks​

  1. Give each app its own user if they still connect as root (see Create a user per app). This avoids any app settings change during the restart.

  2. Change the leaked password. For root, edit DB_PASS_ADMIN and apply, at a time with little traffic if the database has one member. For an app user, follow Change an app user's password.

  3. Check. Try to connect with the old password. It must be refused. Then look at who is connected:

    db.getSiblingDB('admin').aggregate([
    { $currentOp: { allUsers: true } },
    { $group: { _id: '$effectiveUsers.user', connections: { $sum: 1 } } },
    ])

    Only your app users should appear, plus the Quave One internal users.

  4. Limit who can reach the database. If only your apps on Quave One use the database, connect them through the internal host in the Hosts tab and restrict the external host with the IP allowlist.

If you need help with any of these steps, contact support.