Skip to content

Archive Trac mongo security

madscatt edited this page Jun 20, 2026 · 1 revision

Mongo Security

Legacy Trac archive page imported from mongo_security. Source: https://genapp.rocks/wiki/wiki/mongo_security. Review age, links, and examples before treating as current.

mongo security setup

  • mongo requires some sort of security if accessible from other than localhost

  • change dockerfile to use host genapp_docker_mongo

    • this works without "allInvalidHostname*

updated to do 8 nov 18

openssl req -new -key mongodb.pem -out mongodb2.csr
openssl x509 -req -days 365 -in mongodb2.csr -signkey mongodb.pem -out mongodb2.crt
- tried various orders with that, but can't seem to work it.
- maybe https://www.mongodb.com/blog/post/secure-mongodb-with-x-509-authentication
- or http://pe-kay.blogspot.com/2016/02/securing-mongodb-using-x509-certificate.html

action plan

setup security


# generate a 365 day certificate
cd /etc/ssl/
openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key
# cert CN must match bind ip?
# create a pem combining the key and cert
cat mongodb-cert.key mongodb-cert.crt > mongodb.pem
# start mongo from command line
mongod --sslMode requireSSL --sslPEMKeyFile /etc/ssl/mongodb.pem --bind_ip xx.xx.xx.xx <additional options>
e.g. for gadocker.tacc
mongod --sslMode requireSSL --sslPEMKeyFile /etc/ssl/mongodb.pem --bind_ip 0.0.0.0
# or maybe ? 172.18.228.12

# connect to mongo requiring encryption
mongo --ssl --host `hostname` --sslCAFile /etc/ssl/mongodb-cert.crt

php 5.x connect

<?php

$mc = new MongoClient(
    "mongodb://js-17-194.jetstream-cloud.org/?ssl=true",
    [], [ "context" => stream_context_create( [ "ssl" => [ "cafile" => "/etc/ssl/mongodb-cert.crt" ] ] ) ]
    );

initial questions

Clone this wiki locally