Navigation

Set up User Authentication and Authorization with LDAP

Feature unavailable in Free and Shared-Tier Clusters

This feature is not available for M0 (Free Tier), M2, and M5 clusters. To learn more about which features are unavailable, see Atlas M0 (Free Tier), M2, and M5 Limitations.

Atlas provides the ability to manage user authentication and authorization from all MongoDB clients using your own Lightweight Directory Access Protocol (LDAP) server over TLS. A single LDAPS (LDAP over TLS) configuration applies to all clusters in a project.

If you enable user authorization with LDAP, you can create LDAP groups on the admin database by mapping LDAP groups to MongoDB roles on your Atlas databases. To use LDAP groups effectively, create additional projects within Atlas to control access to specific deployments in your organization, such as creating separate Atlas projects for development and production environments. You can then map an LDAP group to a role in the Atlas project to provide access to the desired deployment.

Note

When user authorization is enabled and an LDAP user does not belong to any LDAP group, Atlas does not assign any database roles to the user. When user authentication is enabled and user authorization is disabled, Atlas assigns MongoDB database roles to the LDAP user.

If you have multiple departments with their own billing needs, alert settings, and project members, create a new organization for each department.

Note

An explanation of LDAP is out of scope for the MongoDB documentation. Please review RFC 4515 and RFC 4516 or refer to your preferred LDAP documentation.

Prerequisites

You must meet the following prerequisites to manage user authentication and authorization using LDAP in Atlas:

  • Atlas cluster using MongoDB 3.4 or later.
  • LDAP server using TLS that is accessible to Atlas clusters over the network using either VPC or VNet peering connection or the cluster nodes’ public IP addresses.
  • LDAP group memberships for each user are embedded as an attribute in each user’s LDAP entry for user authorization only.

Recommendation

For your LDAPS service to access Atlas clusters, MongoDB recommends one of two configurations:

Using a VPC or VNet:

  1. Run your LDAP server in a VPC or VNet.
  2. Establish a peering connection to your Atlas project.
  3. Use a public FQDN that resolves to the private IP address of your LDAP server.

Using your data center:

  1. Run your LDAP server with a public FQDN that resolves to a public IP address.
  2. Configure the LDAP server to allow inbound access from the Atlas cluster nodes’ public IP addresses.

Considerations

Usernames

Atlas uses the full Distinguished Name (DN) of users in your LDAP server as the Atlas username. For example, an example LDAP user named ralph has the following username in Atlas:

cn=ralph,cn=Users,dc=aws-atlas-ldap-01,dc=myteam,dc=com

Connection String

If the administrator enables user authentication or both user authentication and authorization with LDAP, database users must override the following parameters in the connection string for their clients.

  • authSource must be $external
  • authenticationMechanism must be PLAIN

Example

The following connection string for the mongo client authenticates an LDAP user named rob:

mongo "mongodb+srv://cluster0-tijis.mongodb.net/test?authSource=%24external" --authenticationMechanism PLAIN --username cn=rob,cn=Users,dc=atlas-ldaps-01,dc=myteam,dc=com

To copy the connection string:

  1. Click Connect on the Clusters page.
  2. Edit the string with your User DN and password.

Note

Use escape characters in place of special characters in MongoDB connection strings. The example above passes ‘%24’ for the ‘$’.

Limitations

If you use LDAP to authenticate and authorize users, you cannot:

  • Provide public IP addresses that refer to other internal or private IP addresses using Network Address Translation to whitelist Atlas traffic to your LDAP server.
  • Use both LDAP and SCRAM authentication for the same MongoDB user.

Procedures

Configure Authentication with LDAP

Use the following procedure to configure user authentication with LDAP for all clusters in a project.

1

Log into Atlas.

2

Select a project from the Context menu.

3

In the Security section of the left navigation, click Advanced.

4

Toggle the button next to LDAP Authentication to On.

5

Enter the server details and bind credentials for your LDAP server in the Configure Your LDAP Server panel.

6

Optional: Enter a certificate issued from a Certificate Authority (CA) for your LDAP server in the CA Root Certificate field.

You may provide a self-signed certificate.

7

Click Verify and Save.

Wait for Atlas to deploy your changes. Atlas verifies that your clusters can connect to, authenticate with, and query your LDAP server using the configuration details that you provide.

Configure Authorization

Use the following procedure to configure user authorization with LDAP for all clusters in a project.

Important

  • You must enable authentication with LDAP before enabling authorization.
  • When the administrator configures LDAP authorization, previous database users configured for LDAP authentication only can no longer access databases.
1

Log into Atlas.

2

Select a project from Context.

3

In the Security section of the left navigation, click Advanced.

4

Toggle the button next to LDAP Authorization to On.

5

Enter the server details and bind credentials for your LDAP server in the Configure Your LDAP Server panel.

6

Optional: Enter a query template in Query Template.

Atlas executes the LDAP query template to obtain the LDAP groups to which the authenticated user belongs. Use the {USER} placeholder in the URL to substitute the authenticated username. The query is relative to the host specified in Server Hostname. The formatting for the query must conform to RFC4515 and RFC 4516.

If you do not provide a query template, Atlas applies the default value: {USER}?memberOf?base.

7

Click Verify and Save.

Wait for Atlas to deploy your changes. Atlas verifies that your clusters can connect to, authenticate with, and query your LDAP server using the configuration details that you provide.