Skip to content

Instantly share code, notes, and snippets.

@kennwhite
Last active August 24, 2020 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennwhite/1647b170bca829c1834ea28022328cdc to your computer and use it in GitHub Desktop.
Save kennwhite/1647b170bca829c1834ea28022328cdc to your computer and use it in GitHub Desktop.
Bootstrap mongodb binary (mongod) properly from command line with encrypted storage engine enabled (full database encryption)
# See: https://docs.mongodb.com/manual/tutorial/configure-encryption/#local-key-management
# As non-root user, possibly in a startup script:
/usr/bin/mongod \
--fork \
--logpath=/tmp/mdb.log \
--dbpath=/data/db \
--enableEncryption \
--encryptionKeyFile <( curl -s https://some.web.service/keys/mykey )
# Alternatively, as root:
KEYTMP=/dev/shm/mbd/keys
mkdir -p $KEYTMP
curl -s https://some.web.service/keys/mykey > $KEYTMP/key1
chmod 0600 $KEYDIR/key1
chown mongodb.mongodb $KEYTMP/key1
runuser -u mongodb -- /usr/bin/mongod \
--fork \
--logpath=/tmp/mdb.log \
--dbpath=/data/db \
--enableEncryption \
--encryptionKeyFile $KEYTMP/key1
# Remove the temporary key from non-persistent memory
echo > $KEYTMP/key1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment