MongoDB Authentication and Automation

MongoDB

#Cloud

MongoDB supports role-based authentication, so you can restrict access to your deployment for safety and security. Cloud Manager Automation makes enabling and managing your users easy.

An important note before we begin: Authentication Settings made here apply to your entire Cloud Manager group. If you are using Automation, and it’s vital that different deployments in your group have different credentials, you will have to create a new Cloud Manager group for these deployment items and import them.

Enabling Authentication

If you already have authentication enabled, follow the normal importation into Automation methodolgy, especially noting the creation of a new automation-agent user, then you can skip this section and go on to the role and user management sections below.

If you have an unauthenticated deployment:

  1. Click the “…” menu on your Deployment Page and choose “Authentication & SSL Settings”
    https://webassets.mongodb.com/_com_assets/blog/tblr/41.media.tumblr.com--96d3ff626a493befd9b487eed9478f10--tumblr_nxx25oM9XH1sdaytmo1_1280.png

  2. Click “Next” to get to the “Select Authentication Mechanisms” screen
    https://webassets.mongodb.com/_com_assets/blog/tblr/40.media.tumblr.com--3d2a8e032a5a9bb2df4212f50c0d072f--tumblr_nxx25oM9XH1sdaytmo8_1280.png
    https://webassets.mongodb.com/_com_assets/blog/tblr/40.media.tumblr.com--9aca5b8de0b173a37c77f20fd55a1ad7--tumblr_nxx25oM9XH1sdaytmo9_1280.png

  3. Select “Username/Password” and click “Next”. Click “Next” again to skip the SSL settings (a topic for this other post).

  4. Now you will see the new users that will be automatically created for you. Click “Save” to create a new automation draft with your new users.
    https://webassets.mongodb.com/_com_assets/blog/tblr/41.media.tumblr.com--e5274a0582c19719dc45e988fcbf1d25--tumblr_nxx25oM9XH1sdaytmo5_1280.png

  5. Now you just have to “Review & Deploy” and “Confirm & Deploy” as normal. Beware: Clients without authentication will fail to connect after this point. Make sure your application is ready for this change. Check your drivers’ documentation on how to enable MongoDB authentication in your application.

Role Management

Let’s start with adding a new role:

  1. Head over to your “Authorization & Roles” tab
    https://webassets.mongodb.com/_com_assets/blog/tblr/40.media.tumblr.com--ed55cda862c6f2b4fb8b8c9ab35db016--tumblr_nxx25oM9XH1sdaytmo10_1280.png

  2. When you click the “Add Role” button in the upper-right, you will be presented with a dialog to fill out:
    https://webassets.mongodb.com/_com_assets/blog/tblr/41.media.tumblr.com--a8fa786316b74a3c26b0c84a8ee0b25e--tumblr_nxx25oM9XH1sdaytmo6_1280.png

  3. You can even add collection-level and other privileges if you want
    https://webassets.mongodb.com/_com_assets/blog/tblr/36.media.tumblr.com--b6100f51cf47723f5c6d9c9997967f87--tumblr_nxx2taCfhl1sdaytmo2_1280.png

  4. In my case, I’ve let my reader role also be able to do certain diagnostic actions
    https://webassets.mongodb.com/_com_assets/blog/tblr/36.media.tumblr.com--75d728996018bee75adebbe464b591ac--tumblr_nxx25oM9XH1sdaytmo7_1280.png

  5. Once the role is added, you just have to do the usual “Review & Deploy”/”Confirm & Deploy” to push this role out to your group.

Once the role has been created, you can edit or remove it via the gear icon, as shown below. You can only edit custom roles, not built-in roles.
https://webassets.mongodb.com/_com_assets/blog/tblr/40.media.tumblr.com--bc02db540ed54858e757302ae88e7c2b--tumblr_nxx2taCfhl1sdaytmo1_1280.png

Users

Once you have the roles you need (if you need custom roles at all), you can start creating users.

  1. Head to your “Authentication & Users” tab
    https://webassets.mongodb.com/_com_assets/blog/tblr/41.media.tumblr.com--1741febd8d237fa670f3ca8549d5461a--tumblr_nxx25oM9XH1sdaytmo4_1280.png

  2. Create a new user via the “Add User” button in the upper-right
    https://webassets.mongodb.com/_com_assets/blog/tblr/36.media.tumblr.com--d21c25b1963847de82c38884e47f310d--tumblr_nxx25oM9XH1sdaytmo3_1280.png

  3. You can choose any custom or built-in roles you wish and enter the user’s password

  4. Once the user is added, you just have to do the usual “Review & Deploy”/”Confirm & Deploy” to push this user out to your group.

Once the user has been created, you can edit or delete it via the gear. You cannot edit the built-in users for the agents.
https://webassets.mongodb.com/_com_assets/blog/tblr/40.media.tumblr.com--31c2c38a20d41bb313e924eba4318e1b--tumblr_nxx25oM9XH1sdaytmo2_1280.png

Removing Authentication

Maybe you have moved your deployment into a private network and have decided to remove your authentication settings. Here’s how:

  1. Click the “…” menu on your Deployment page and select “Authentication & SSL Settings”
  2. Click “Next” to get to the “Authentication Mechanisms” screen and un-check “Username/Password”
  3. Click “Next” to skip the SSL settings, and then click “Save”
  4. When you next do a “Review & Deploy”/”Confirm & Deploy”, the Automation Agents will disable authentication.

All your custom roles and users will remain cached in Cloud Manager in case you wish to re-enable authentication. You can edit them even when authentication is not enabled.