Charmed MongoDB

Channel Revision Published Runs on
5/stable 117 20 Apr 2023
Ubuntu 22.04
5/candidate 117 20 Apr 2023
Ubuntu 22.04
5/edge 127 19 Sep 2023
Ubuntu 22.04
3.6/stable 100 28 Apr 2023
Ubuntu 20.04 Ubuntu 18.04
3.6/candidate 100 13 Apr 2023
Ubuntu 20.04 Ubuntu 18.04
3.6/edge 100 03 Feb 2023
Ubuntu 20.04 Ubuntu 18.04
juju deploy mongodb --channel 5/stable
Show information

Platform:

Ubuntu
22.04

Manage Passwords

This is part of the Charmed MongoDB Tutorial. Please refer to this page for more information and the overview of the content.

Passwords

When we accessed MongoDB earlier in this tutorial, we needed to include a password in the URI. Passwords help to secure our database and are essential for security. Over time it is a good practice to change the password frequently. Here we will go through setting and changing the password for the admin user.

Retrieve the admin password

As previously mentioned, the admin password can be retrieved by running the get-password action on the Charmed MongoDB application:

juju run mongodb/leader get-password

Running the command should output:

Running operation 9 with 1 task
  - task 10 on unit-mongodb-0

Waiting for task 10...
password: 9JLjd0tuGngW5xFKWWbo0Blxyef0oGec

The admin password is under the result: password.

Rotate the admin password

You can change the admin password to a new random password by entering:

juju run mongodb/leader set-password

Running the command should output:

Running operation 11 with 1 task
  - task 12 on unit-mongodb-0

Waiting for task 12...
password: f3QkHE6QgmDLdRBonrt4vToWB7IZd4JO

The admin password is under the result: password. It should be different from your previous password.

Note when you change the admin password you will also need to update the admin password the in MongoDB URI; as the old password will no longer be valid. Update the DB password used in the URI and update the URI:

export DB_PASSWORD=$(juju run mongodb/leader get-password | grep password|  awk '{print $2}')
export URI=mongodb://$DB_USERNAME:$DB_PASSWORD@$HOST_IP/$DB_NAME?replicaSet=$REPL_SET_NAME

Set the admin password

You can change the admin password to a specific password by entering:

juju run mongodb/leader set-password password=<password>

Running the command should output:

Running operation 17 with 1 task
  - task 18 on unit-mongodb-0

Waiting for task 18...
password: <password>

The admin password under the result: password should match whatever you passed in when you entered the command.

Note that when you change the admin password you will also need to update the admin password in the MongoDB URI, as the old password will no longer be valid. To update the DB password used in the URI:

export DB_PASSWORD=$(juju run mongodb/leader get-password | grep password|  awk '{print $2}')
export URI=mongodb://$DB_USERNAME:$DB_PASSWORD@$HOST_IP/$DB_NAME?replicaSet=$REPL_SET_NAME

Next step

Charmed MongoDB Tutorial - Relate your MongoDB deployment


Help us improve this documentation

Most of this documentation can be collaboratively discussed and changed on the respective topic in the doc category of the Charmhub forum. See the documentation guidelines if you’d like to contribute.

Last updated 30 days ago. Help improve this document in the forum.