For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Authorization and Authentication Examples

The following examples show how to implement our recommendations for authentication and authorization for different access types. The examples show how to implement the recommendations using both the Atlas CLI and Terraform.

To learn about Terraform, see Get Started with Terraform and the MongoDB Atlas Provider and the MongoDB Atlas Provider Terraform docs.

For access to the Atlas UI:

  • Implement IP access lists. For example,

    atlas organizations apiKeys accessLists create --apiKey <API_KEY_ID> --ip <IP_ADDRESS>
  • Implement Federated Authentication or Atlas credentials and Multi-factor Authentication (MFA).

    To set up Federated Auth, use the atlas-federatedAuthentication and related commands. You can then use the atlas-users-invite command to invite users to your organization and projects.

    To get started, use the following command:

    atlas federatedAuthentication --help

    Note

    For users that authenticate with SSO, you will also need to configure the SSO Identity Provider.

    For more information, see Configure Federated Authentication.

For workforce database access:

  • Use the atlas-dbusers-certs-create command to create Atlas-managed MFA (Multi-Factor Authentication) X.509 client certificates.

    Note

    To use self-managed certificates, you must first configure X.509:

    atlas dbusers certs create --username <USERNAME> --projectId <PROJECT_ID> [--monthsUntilExpiration <MONTHS>] [--output json]

For workload (machine) access, use Workload Identity Federation.

Use the serviceAccounts and related commands to create and manage Service Accounts. For example,

atlas api serviceAccounts createServiceAccount [options]

For development and test environments, you can also use API keys. For example,

atlas organizations apiKeys create [options]

Tip

For Terraform examples that enforce our recommendations across all pillars, see one of the following examples in GitHub:

For an example of an Atlas project with the Atlas role assigned to a specific group, see Examples.

Rate this page