Last active
October 25, 2022 11:59
-
-
Save maxpowel/5fb6c60e336a2dda774bc5d97a3b623b to your computer and use it in GitHub Desktop.
Secure mongo server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security: | |
authorization: "enabled" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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