Skip to content

Instantly share code, notes, and snippets.

@maxpowel
Last active October 25, 2022 11:59
Show Gist options
  • Save maxpowel/5fb6c60e336a2dda774bc5d97a3b623b to your computer and use it in GitHub Desktop.
Save maxpowel/5fb6c60e336a2dda774bc5d97a3b623b to your computer and use it in GitHub Desktop.
Secure mongo server
security:
authorization: "enabled"
# Run docker without auth
docker run --rm -p 27017:27017 -v /home/ubuntu/mongodb/:/data/db mongo:6.0.2
# Create the admin user. Connect to mongo and run this:
use admin
db.createUser({ user: "mongoadmin" , pwd: "mongoadmin_password", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})
# Now stop the docker container and run it with authentication
docker run --rm -p 27017:27017 -v /home/ubuntu/mongodb/:/data/db -v /home/ubuntu/mongod.conf:/etc/mongod.conf mongo:6.0.2
# Create your users. Connect to mongo using your recently created admin.
# The users are created in the `admin` database. Where the permissions are applied is specified in the role
use admin
db.createUser(
{
user: "my-new-user",
pwd: "fVtqTCq7mTbwULzr",
roles: [ { role: "readWrite", db: "my-database" } ]
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment