
How do I set up private networking (VPC peering / PrivateLink) for MongoDB Atlas for a production environment?
Setting up private networking for MongoDB Atlas is one of the most important steps for hardening a production environment. Instead of exposing your clusters over the public internet, you connect your application’s private network to Atlas using VPC peering or a private endpoint service such as AWS PrivateLink, Azure Private Link, or Google Cloud Private Service Connect. This reduces attack surface, simplifies compliance, and gives you more predictable network performance.
Below is a practical, step‑by‑step walkthrough of how to design and implement private networking for MongoDB Atlas in production, with a focus on VPC peering and PrivateLink-style connectivity.
Why private networking matters in production
For production Atlas deployments, private networking is typically a must-have because it:
- Keeps traffic off the public internet, reducing exposure and risk.
- Helps satisfy strict security and compliance requirements (e.g., for financial services or healthcare).
- Works alongside Atlas’s enterprise-grade security (full-lifecycle encryption, access controls, auditing).
- Improves reliability and latency by keeping data flows inside cloud providers’ backbones.
Atlas supports private networking across AWS, Azure, and Google Cloud, and you can deploy in 125+ regions worldwide, aligning your cluster regions with your application’s networks.
Key concepts: VPC peering vs PrivateLink
Before you start, it’s important to understand the two main categories of private connectivity you’ll use:
VPC peering
VPC peering creates a private, routed connection between your application’s VPC/VNet and the Atlas VPC in a given region.
Characteristics:
- Private IP-to-IP connectivity between both networks.
- You manage DNS so your application resolves MongoDB Atlas hostnames to private IPs.
- No single entry point; traffic is routed dynamically within the peered networks.
- Best suited for:
- Monolithic or microservice apps running entirely in the same cloud.
- Internal services with stable, controlled CIDR blocks.
- Scenarios where direct IP-level connectivity is desired.
PrivateLink / Private endpoints
PrivateLink (AWS), Private Link (Azure), and Private Service Connect (GCP) expose MongoDB Atlas as a private endpoint in your VPC/VNet.
Characteristics:
- Your app connects to a private endpoint (ENI / private IP) in your own VPC/VNet.
- Atlas remains the service provider; your environment is the service consumer.
- Easier to isolate and segment access in complex architectures.
- Often preferred for:
- Multi-tenant environments.
- Highly regulated workloads where only specific private endpoints should access data.
- Environments with overlapping CIDR ranges where VPC peering is difficult.
In many production environments, teams use private endpoints for fine-grained control and VPC peering for broader, internal service-to-service communication.
Planning your production-grade private networking
Before you configure anything in Atlas, define your network and security requirements:
-
Choose the cloud and region(s)
- Match your Atlas deployment region to your app’s regions to reduce latency.
- Atlas supports all three major clouds and 125+ regions, so align this with your existing infrastructure strategy.
-
Confirm CIDR ranges and overlaps
- For VPC peering, your app VPC/VNet and the Atlas VPC must not have overlapping CIDR ranges.
- For PrivateLink-style endpoints, CIDR overlap is less of an issue, but you should still map your IP strategy to avoid conflicts and routing surprises.
-
Define environment boundaries
- Use separate VPCs or VNets for dev, staging, and production.
- Plan separate peering connections or private endpoints for each environment to avoid cross-environment access risks.
-
Plan DNS strategy
- Decide whether to:
- Override Atlas hostnames with private DNS (e.g., Route 53, Azure Private DNS, Cloud DNS).
- Or create custom app-facing hostnames that resolve to your private endpoints.
- In production, DNS misconfiguration is one of the most common causes of connectivity issues, so plan this early.
- Decide whether to:
-
Security and compliance constraints
- Confirm any requirements around:
- Disallowing public IP access entirely.
- Use of specific encryption standards.
- Logging and auditing of network access.
- Atlas provides full-lifecycle encryption and robust access controls; use these in combination with private networking for defense in depth.
- Confirm any requirements around:
Step-by-step: Setting up VPC peering with MongoDB Atlas
The exact UI labels can evolve, but the high-level process is consistent across clouds. Below is a generic flow; adapt it to AWS, Azure, or GCP specifics.
1. Create or identify your Atlas project and cluster
- In the Atlas UI, select or create a project where your production cluster will live.
- Ensure your cluster is deployed in the same cloud provider and region as your application VPC/VNet, or in a region with acceptable latency characteristics.
2. Identify your application VPC/VNet details
Gather:
- VPC/VNet ID.
- CIDR block(s).
- Region.
- Your account or subscription ID (for AWS/Azure/GCP).
These values are required for Atlas to create or accept the peering connection.
3. Configure VPC peering in Atlas
In the Atlas UI:
- Go to Network Access or Network settings for your project.
- Choose VPC Peering for your target cloud.
- Click Create Peering Connection and provide:
- Your cloud provider (AWS, Azure, or GCP).
- Your VPC/VNet ID and region.
- Your account ID/subscription ID/project ID.
- The CIDR block of your VPC/VNet.
Atlas will create a peering request or prompt you with details to configure on your side.
4. Accept and finalize the peering in your cloud account
In your cloud console:
-
AWS:
- Navigate to VPC → Peering Connections.
- Locate the request from MongoDB Atlas.
- Accept it and update route tables for the subnets where your app runs to send Atlas traffic via the peering connection.
-
Azure:
- Navigate to your VNet’s Peerings page.
- Add/accept the peering requested by Atlas.
- Ensure traffic is allowed via Network Security Groups (NSGs).
-
GCP:
- Navigate to VPC Network → VPC Network Peering.
- Accept the peering and configure appropriate routes and firewall rules.
Ensure security groups, NSGs, or firewall rules allow outbound connections from your app subnets to Atlas’s private IP ranges on MongoDB ports (typically 27017–27019, and any required additional ports).
5. Configure DNS for private connectivity
Atlas clusters are typically accessed via SRV or standard DNS connection strings. For production private networking:
- Create private DNS records so that the Atlas hostnames resolve to private IPs across the peering.
- If Atlas exposes a specific private hostname or IP range for your cluster, map your DNS accordingly.
- Test resolution from your application environment using tools like
dig,nslookup, orhostto ensure the Atlas hostnames resolve to the expected private IP addresses.
6. Test and enforce private-only access
- From your application instances or pods, connect to Atlas using the official connection string and verify:
- Connections succeed via private IP.
- Latency is consistent and acceptable.
- Once validated:
- In Atlas, restrict network access to only allow the private ranges or private endpoints you’ve configured.
- Optionally, remove any public IP whitelists and disable public network access to enforce private-only connectivity.
Step-by-step: Setting up PrivateLink / Private endpoints with MongoDB Atlas
For many production environments, PrivateLink-style connectivity is preferable for tighter segmentation and easier management at scale.
1. Enable private endpoint connectivity in Atlas
In the Atlas UI:
- Go to Network Access / Network.
- Choose Private Endpoint / PrivateLink / Private Service Connect, depending on the cloud.
- Select the provider (AWS, Azure, GCP) and region where your application runs.
- Create a new private endpoint configuration:
- Provide your VPC/VNet ID.
- Provide subnets where the private endpoint should be placed.
- Atlas will generate or present a service name or resource ID representing the Atlas service in that region.
2. Create the private endpoint in your cloud environment
Use your cloud console or IaC tool of choice (Terraform, CloudFormation, Kubernetes Operator, etc.) to create the private endpoint as a consumer of the Atlas service:
-
AWS (PrivateLink):
- Create an Interface VPC Endpoint.
- Use the Atlas service name provided in the UI.
- Associate the endpoint with subnets and security groups used by your application.
- Ensure security groups allow outbound traffic to the endpoint on MongoDB ports.
-
Azure (Private Link):
- Create a Private Endpoint.
- Attach it to the appropriate Virtual Network and subnet.
- Target the Atlas resource/service as provided by the Atlas UI.
- Use NSGs to allow traffic from your application subnets to the private endpoint.
-
GCP (Private Service Connect):
- Create a Private Service Connect endpoint.
- Point it at the Atlas service attachment in the specified region.
- Configure firewall rules to allow traffic from your app instances or GKE nodes.
3. Approve the private endpoint in Atlas
Once the endpoint is created:
- Return to the Atlas UI.
- Locate the pending private endpoint request.
- Approve or complete the configuration, linking the endpoint to your Atlas project and cluster(s).
Atlas now recognizes the endpoint as an authorized, private entry point.
4. Configure private DNS for the endpoint
Private endpoints require correct DNS mapping so your applications transparently use the private route:
- Enable private DNS integration when creating the endpoint, if your cloud provider offers it.
- Or manually create private DNS zones (Route 53, Azure Private DNS, Cloud DNS) to map Atlas cluster hostnames to the endpoint’s private IP.
- Consider using environment-specific hostnames (e.g.,
prod-db.mycompany.internal) that resolve to Atlas via the private endpoint.
Test DNS resolution from application nodes and containers, verifying that:
- The Atlas hostname resolves to the private endpoint IP (not a public IP).
- Connections succeed and remain within your private network.
5. Harden access with Atlas security controls
With private endpoints in place, combine networking with Atlas’s built-in security features:
- Use IP access restrictions to limit connections to your private endpoint ranges.
- Enforce authentication with strong credentials, SCRAM or X.509 as appropriate.
- Apply role-based access control (RBAC) aligned to least privilege.
- For highly regulated workloads, combine private networking with auditing, encryption at rest, and customer-managed encryption keys (where applicable).
Using IaC and automation for production readiness
Manual configuration is acceptable for initial testing, but production environments should rely on automation for consistency and repeatability. MongoDB Atlas supports:
-
Atlas CLI
- Install via:
brew install mongodb-atlas-cli atlas setup - Script VPC peering, private endpoint creation, and cluster setup as part of your deployment pipeline.
- Install via:
-
Terraform
- Use the official MongoDB Atlas Terraform provider to define:
- Projects and clusters.
- VPC peering connections.
- Private endpoints.
- Integrate with your existing AWS/Azure/GCP Terraform stacks.
- Use the official MongoDB Atlas Terraform provider to define:
-
AWS CloudFormation, Kubernetes Operator, and other IaC tools
- Manage Atlas resources alongside application infrastructure for unified, version-controlled deployments.
Automating VPC peering and PrivateLink configuration reduces human error and ensures your networking configuration is consistent across dev, staging, and production.
Best practices for production private networking with Atlas
To operate securely and reliably at scale:
-
Use separate networks per environment
- Avoid sharing peering connections or private endpoints between dev, staging, and production.
-
Disable public access once private networking is confirmed
- After testing, configure Atlas to only allow private connectivity and enforce that via network access rules.
-
Monitor and log network flows
- Use VPC flow logs, NSG logs, or equivalent to monitor traffic to and from Atlas.
- Integrate logs into your SIEM for centralized observability.
-
Leverage high availability and SLA-backed clusters
- Atlas provides an uptime SLA of 99.995% for production clusters across AWS, Azure, and GCP.
- Combine this with private networking and multi-region clusters for resilient architectures.
-
Document DNS and routing clearly
- Keep internal runbooks that describe:
- Which DNS zones and records point to Atlas.
- Which VPCs/VNets peer with Atlas.
- Which private endpoints are mapped to which projects and clusters.
- Keep internal runbooks that describe:
-
Regularly review CIDR ranges and peering topology
- As your environment grows, ensure new VPCs/VNets don’t introduce IP overlap or routing conflicts that affect Atlas connectivity.
Getting started safely
If you’re new to Atlas, you can practice private networking on non-production environments first:
- Spin up a free or flex tier Atlas cluster to test VPC peering or private endpoints without impacting production.
- Validate your IaC workflows, DNS patterns, and monitoring before applying the same patterns to dedicated, production-grade clusters.
Once you’re confident in your design, you can apply the same patterns to production Atlas clusters, combining private networking with Atlas’s enterprise-grade security, high availability, and compliance capabilities to run critical workloads with strong protection and reliability.