Networking Security: Atlas / Using the IP Access List
When you build something valuable, you wanna control who can access it. Your MongoDB Atlas database contains your organization's important data, and deciding who can connect to it is a fundamental part of good database management.
The IP access list in MongoDB Atlas gives you precise control over which computers or networks can communicate with your cluster.
It's like having a guest list for your database.
Only those with the approved IP addresses get to interact with your data.
In this video, we'll explore how to use MongoDB Atlas's IP access list feature to manage access to your cluster.
We'll learn how to add trusted addresses, review your current settings, and modify the list as your needs change. Let's begin. The public Internet connects billions of devices worldwide, creating an interconnected network that allows information to flow freely.
While this connectivity brings tremendous benefits, it also introduces security challenges.
Without proper network security hardening, systems exposed to the public Internet, like databases, can be potentially accessed by anyone with access to the Internet.
This includes legitimate users, but also potential attackers who constantly scan for systems with security weaknesses.
Each connection attempt to your database represents a potential entry point.
Without proper controls, your data might be at risk of unauthorized access, modification, or even deletion.
This is why limiting access to your MongoDB Atlas cluster is so important. For many organizations, data protection isn't just good practice, it's a legal requirement.
Various regulations like GDPR, HIPAA, and others mandate specific security controls for different types of data.
Controlling who can connect to your database is often a core requirement of these regulations.
The IP access list in MongoDB Atlas serves as a gatekeeper for your database.
It allows you to specify which IP addresses or IP ranges can connect to your Atlas cluster.
However, it's important to recognize that IP access lists are a relatively basic security measure with limitations.
They can be circumvented through techniques like IP spoofing, where the attackers disguise their true IP address to appear as a trusted source.
IP access lists should be implemented as just one component of a comprehensive security strategy. Here's how it works.
Atlas checks the source IP address of every connection attempt against your access list.
If the IP address is on the list, the connection can proceed to authentication.
If not, the connection is rejected immediately. No questions asked.
By default, MongoDB Atlas takes a security first approach.
When you first create a cluster, only Atlas managed IP addresses, other cluster nodes, and Atlas control pane are allowed to connect.
While all other external IP addresses are blocked.
This means your database starts in a completely locked down state, and you must explicitly add the IP addresses that need access. Each MongoDB Atlas project can have up to two hundred IP addresses or CIDR (Classless Inter-Domain Routing) ranges in its access list.
While this provides plenty of flexibility, it's good practice to keep this list as small as possible.
The fewer IP addresses allowed to connect, the smaller your potential attack surface.
For temporary access needs, such as when a developer needs brief access to troubleshoot an issue, Atlas offers temporary IP entries.
These automatically expire after a set period, reducing the risk of forgotten access permissions.
Regular auditing of your IP access list is an important maintenance task.
Over time, as systems change or projects end, some IP addresses may no longer need access.
Removing these unused entries helps maintain a clean, secure environment.
Remember that the IP access list works alongside your authentication (AuthN) and authorization (AuthZ) systems.
It doesn't replace the need for strong passwords and proper user roles, but rather complements them by adding an additional security layer. Now that we understand the concept and the importance of the IP access list, let's add an IP address to our MongoDB Atlas project.
We'll use the Atlas command line interface or CLI for this task.
Though you could also do this through the Atlas web dashboard or the Admin API.
The Atlas CLI makes it straightforward to manage your access list. To add a new IP address, we'll use the access list create command.
We start off by specifying the IP address that we want added to the access list.
If you want to add your current IP address without having to look it up, the Atlas CLI features a helpful shortcut with the "--currentIp" option.
This automatically detects and adds the IP addresses you're connecting from.
When you want to grant temporary access, use the "--deleteAfter" option.
This creates an entry that will automatically be removed after a specified time period.
Dates and times should adhere to the ISO (International Organization for Standardization) 8601 UTC (Universal Time Coordinated) format.
Next, we specify the ID of the project we want this IP address to be added to.
Finally, the "--comment" parameter helps you remember why this IP was added, which becomes valuable as you review the access later. After adding an IP address, applications and tools connecting from that address will be able to attempt authentication with your cluster.
This two-step security process, first checking IP and then verifying credentials, provides an effective security boundary.
Once you've added IP addresses to your access list, you'll need to monitor and manage them.
The Atlas CLI provides several helpful commands for this purpose.
To view the IP access list, use the "accessLists list" command.
For this command, we have to specify the project that we want to view the IP access list for.
We also have the option to choose the output format.
Here, we'll specify JSON for the format. When we run this command, we see a complete list of all entries in the access list.
Each entry shows the IP address or range, when it was added, and any comments.
For a more detailed view of a specific entry, you can use the "accessLists describe" command.
For this command, we have to provide the IP address we want to inspect along with a project ID.
Like before, we can also specify the output format. This single entry view offers the same details as before, including the current status and metadata.
The detailed view is useful for confirming entry specifics, such as whether it's temporary and if there's an expiration date.
To delete an IP entry from the access list, use the "accessLists delete" command.
Similar to before, we specify the IP address and the project ID for the entry we want to remove.
After running the command, you'll be prompted to confirm that you want to delete the specific IP address.
Once confirmed, that IP address will no longer be able to connect to your clusters.
If you want further confirmation, you can verify the deletion was successful by running the list command again.
Now you'll see that the IP address you deleted is no longer in the results.
This confirms that connections from that address will be rejected by Atlas.
Regular maintenance of your access list is a key security practice that helps ensure only authorized systems can connect to your database.
Great job. You've now learned how to use MongoDB Atlas' IP access list to control which IP addresses can connect to your clusters.
Let's review what we've covered.
We started by exploring why controlling access to your database is important in the context of the public Internet.
We saw that IP access lists act as a first line of defense, preventing unauthorized connection attempts. Next, we learned that Atlas blocks all connections by default, requiring you to explicitly allow specific IP addresses or ranges.
This security first approach helps you ensure that your database is accessible only to authorized systems.
We then walked through adding an IP address using the Atlas CLI, including how to add your current IP and create temporary access entries.
This flexibility allows you to manage access precisely according to your needs.
Finally, we explored how to view and manage your IP access list, including removing entries that are no longer needed.
Regular maintenance of your access list is an essential security practice.
Remember that the IP access list works hand in hand with authentication and authorization.
Together, these create multiple layers of security for your MongoDB Atlas clusters.
By implementing these practices, you've taken an important step toward creating a secure database environment that protects your valuable data while still allowing legitimate access to your applications and tools.
