CNs are important!!! -days 3650
openssl req -newkey rsa:2048 -new -x509 -days 3650 -nodes -subj '/C=US/ST=Massachusetts/L=Bedford/O=Personal/OU=Personal/[email protected]/CN=localhost' -out mongodb-cert.crt -keyout mongodb-cert.keycat mongodb-cert.key mongodb-cert.crt > mongodb.pemcp mongodb-cert.crt mongodb-ca.crt# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
ssl:
mode: allowSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/mongodb-cert.crtsudo mongod --config /etc/mongod.confsudo service mongod restartmongo --ssl --sslAllowInvalidHostnames --sslCAFile mongodb-ca.crt --sslPEMKeyFile /etc/ssl/mongodb.pem{
ssl: true,
sslValidate: true,
sslKey: fs.readFileSync('/etc/ssl/mongodb.pem'),
sslCert: fs.readFileSync('/etc/ssl/mongodb-cert.crt'),
sslCA: fs.readFileSync('/etc/ssl/mongodb-ca.crt')
}
Setting Up MongoDB 4.4.29 with TLS
1. Create a Public Key Certificate and Private Key
Generate a public key certificate and its associated private key using OpenSSL:
2. Create a PEM File
Combine the certificate and key into a single PEM file:
cat mongodb-cert.key mongodb-cert.crt > mongodb.pem3. Copy Files to /etc/ssl
Move the generated certificate and PEM files to /etc/ssl:
4. Edit the MongoDB Configuration
Open the MongoDB configuration file for editing:
Update the configuration to include the TLS/SSL settings:
Test Connection
Test connection by mongosh