Mitigation Strategy: Enforce Authentication and Authorization (MongoDB Server)
-
Mitigation Strategy: Enforce Authentication and Authorization (MongoDB Server)
-
Description:
- Enable Authentication: Modify the MongoDB server configuration file (
mongod.conf
or through the MongoDB Atlas UI) to enable authentication. Setsecurity.authorization
toenabled
. - Create Administrative User: Create at least one administrative user in the
admin
database before enabling authentication. This user will be needed to manage other users and roles. - Define Roles (Principle of Least Privilege):
- Create custom roles that grant only the minimum necessary permissions to each application user or service. Avoid using built-in roles like
readWriteAnyDatabase
orroot
for application users. - Use built-in roles only when they precisely match the required permissions.
- Consider roles like
read
,readWrite
,dbAdmin
, and custom roles for specific collections or operations.
- Create custom roles that grant only the minimum necessary permissions to each application user or service. Avoid using built-in roles like
- Create Application Users: Create individual user accounts for each application or service, assigning them the appropriate custom roles.
- Choose Authentication Mechanism: Select a secure authentication mechanism. SCRAM (Salted Challenge Response Authentication Mechanism) is the recommended option (e.g.,
SCRAM-SHA-256
). - Restart MongoDB: Restart the MongoDB server for the changes to take effect.
- Regularly Audit Roles: Periodically review user roles and permissions to ensure they remain appropriate and that no unnecessary privileges have been granted.
- Rotate Credentials: Implement a process for regularly rotating MongoDB user passwords.
- Enable Authentication: Modify the MongoDB server configuration file (
-
List of Threats Mitigated:
- Unauthorized Data Access (Critical): Prevents unauthorized users or applications from accessing or modifying data.
- Privilege Escalation (High): Limits the damage an attacker can do if they compromise a user account.
-
Impact:
- Unauthorized Data Access: Risk reduced from Critical to Low (depending on password strength and RBAC effectiveness).
- Privilege Escalation: Risk reduced from High to Low.
-
Currently Implemented:
- Example: Authentication is enabled. Basic roles are defined, but they are overly permissive.
-
Missing Implementation:
- Example: Need to define more granular roles based on the principle of least privilege.
- Example: No process for regularly rotating credentials.
- Example: No regular audit of user roles.
-
Mitigation Strategy: Enable TLS/SSL Encryption (MongoDB Server)
-
Mitigation Strategy: Enable TLS/SSL Encryption (MongoDB Server)
-
Description:
- Obtain TLS Certificate: Obtain a TLS/SSL certificate for your MongoDB server. For production, use a certificate from a trusted Certificate Authority (CA). Self-signed certificates can be used for testing.
- Configure MongoDB Server: Modify the
mongod.conf
file (or MongoDB Atlas settings):tls.mode
: Set torequireTLS
to enforce TLS connections. Other options includepreferTLS
(allows both TLS and non-TLS) andallowTLS
(allows non-TLS, but enables TLS if requested).disabled
turns off TLS.tls.certificateKeyFile
: Specify the path to the combined certificate and private key file (PEM format).tls.CAFile
: (Optional, but recommended) Specify the path to the CA certificate file (PEM format) used to verify client certificates (if using client certificate authentication).tls.allowConnectionsWithoutCertificates
: (Optional) If set totrue
, allows clients to connect without presenting a certificate (not recommended for production).
- Restart MongoDB: Restart the MongoDB server for the changes to take effect.
- Configure Clients: Ensure all clients (including your Go application using the
mongo-go-driver
) are configured to connect using TLS.
-
List of Threats Mitigated:
- Man-in-the-Middle (MitM) Attacks (High): Prevents interception and eavesdropping on communication.
- Data Exposure in Transit (High): Protects sensitive data during transmission.
-
Impact:
- Man-in-the-Middle (MitM) Attacks: Risk reduced from High to Negligible (with proper TLS configuration and valid certificates).
- Data Exposure in Transit: Risk reduced from High to Negligible.
-
Currently Implemented:
- Example: TLS/SSL is enabled on the MongoDB server for the production environment.
-
Missing Implementation:
- Example: TLS is not enforced for connections from the development environment.
-
Mitigation Strategy: Configure Network Exposure (MongoDB Server)
-
Mitigation Strategy: Configure Network Exposure (MongoDB Server)
-
Description:
- Bind to Specific Interfaces: Modify the
mongod.conf
file (or MongoDB Atlas network access settings):net.bindIp
: Specify the IP address(es) or hostname(s) that MongoDB should listen on. Never bind to0.0.0.0
(all interfaces) in production unless absolutely necessary and secured with a firewall. Bind to127.0.0.1
(localhost) if only local access is needed. Bind to a specific private IP address if accessible only within a private network.
- Firewall Rules: Configure a firewall (e.g.,
iptables
,ufw
, or a cloud provider's firewall) to restrict access to the MongoDB port (default: 27017) to only authorized clients. Block all other incoming connections to that port. - MongoDB Atlas (if applicable):
- IP Whitelisting: Use MongoDB Atlas's IP Access List feature to specify the IP addresses or CIDR blocks that are allowed to connect.
- VPC Peering: If your application is running in a Virtual Private Cloud (VPC), use VPC peering to connect to your MongoDB Atlas cluster securely without exposing it to the public internet.
- Private Endpoints: Use Private Endpoints (available on some cloud providers) for even more secure and isolated connectivity.
- Bind to Specific Interfaces: Modify the
-
List of Threats Mitigated:
- Unauthorized Access (Critical): Prevents unauthorized connections from outside the intended network.
- Denial of Service (DoS) (Medium): Reduces the attack surface by limiting the number of potential attackers.
-
Impact:
- Unauthorized Access: Risk reduced from Critical to Low (depending on the restrictiveness of the firewall rules and network configuration).
- Denial of Service (DoS): Risk reduced from Medium to Low.
-
Currently Implemented:
- Example: MongoDB is bound to a specific private IP address. A firewall is in place, but the rules are not very restrictive.
-
Missing Implementation:
- Example: Need to tighten firewall rules to allow only specific IP addresses or CIDR blocks.
- Example: If using MongoDB Atlas, IP whitelisting is not fully configured.
-
Mitigation Strategy: Enable Auditing (MongoDB Server)
-
Mitigation Strategy: Enable Auditing (MongoDB Server)
-
Description:
- Configure Auditing: Modify the
mongod.conf
file (or MongoDB Atlas auditing settings):auditLog.destination
: Specify where audit logs should be written. Options includesyslog
,console
,file
, orjsonFile
(for JSON format).auditLog.format
: Specify the log format (e.g.,JSON
).auditLog.path
: (Ifdestination
isfile
orjsonFile
) Specify the path to the audit log file.auditLog.filter
: (Optional, but highly recommended) Define a filter to specify which events should be logged. This helps reduce the volume of audit data and focus on relevant events. You can filter by user, database, operation type, etc. Example:auditLog: destination: file format: JSON path: /var/log/mongodb/auditLog.json filter: '{ "atype": { $in: [ "authCheck", "authenticate" ] }, "param.db": "mydb" }'
- Restart MongoDB: Restart the MongoDB server for the changes to take effect.
- Regularly Review Logs: Implement a process for regularly reviewing the audit logs. Look for suspicious activity, unauthorized access attempts, and other security-relevant events.
- Log Rotation: Configure log rotation to prevent the audit log file from growing indefinitely.
- Configure Auditing: Modify the
-
List of Threats Mitigated:
- Unauthorized Access (Detection) (High): Provides a record of all database operations, allowing you to detect unauthorized access or suspicious activity.
- Data Breaches (Investigation) (High): Helps you investigate data breaches and determine the scope of the compromise.
- Compliance (Variable): Helps you meet compliance requirements that mandate audit logging.
-
Impact:
- Unauthorized Access (Detection): Does not prevent unauthorized access, but significantly improves your ability to detect it.
- Data Breaches (Investigation): Provides crucial information for investigating data breaches.
- Compliance: Helps meet compliance requirements.
-
Currently Implemented:
- Example: Auditing is not currently enabled.
-
Missing Implementation:
- Example: Need to configure auditing in the
mongod.conf
file and set up a process for reviewing the logs.
- Example: Need to configure auditing in the
-
Mitigation Strategy: Disable Server-Side JavaScript (MongoDB Server)
-
Mitigation Strategy: Disable Server-Side JavaScript (MongoDB Server)
-
Description:
- Disable
db.eval()
: Disable thedb.eval()
command using thesetParameter
command. This can be done from the mongo shell or through the driver usingRunCommand
:// From the mongo shell: db.adminCommand({setParameter: 1, javascriptEnabled: false})
// From the Go driver: var result bson.M err := client.Database("admin").RunCommand(context.TODO(), bson.D{{"setParameter", 1}, {"javascriptEnabled", false}}).Decode(&result)
- Avoid
$where
andmapReduce
(if possible): Prefer the aggregation framework over server-side JavaScript functions like$where
andmapReduce
. The aggregation framework is generally more secure and performant. - Restart MongoDB: Restart the MongoDB server for the
javascriptEnabled
setting to take effect.
- Disable
-
List of Threats Mitigated:
- Server-Side JavaScript Injection (High): Prevents attackers from injecting malicious JavaScript code.
-
Impact:
- Server-Side JavaScript Injection: Risk reduced from High to Negligible (if server-side JavaScript is completely disabled).
-
Currently Implemented:
- Example:
db.eval()
is disabled.
- Example:
-
Missing Implementation:
- Example: None (assuming all server-side JavaScript usage has been eliminated or properly secured).
-