x.509 certificate
is authorization method which securer than SCRAM
. Note that x.509
required TLS
support to authenticate certificate
.
- Check that current MongoDB environment required
TLS
support by looking information provided by commandmongod --version
. If themongod --version
return similar to below output:
...
OpenSSL version: OpenSSL xxxx xx xxxx xxxx
...
Then, you good to go.
2. Provide some TLS
certificates:
- ca.pem is Certificate Authority (CA) file
- client.pem is client certificate
- server.pem is server certificate
3. Activate mongod
with x.509
support:
mongod --ssl --sslPEMKeyFile server.pem --sslCAFile ca.pem
- To inspect issued certificate and authorization server in
client.pem
, use command below to decodeclient.pem
:
openssl x509 -in client.pem -inform PEM -subject -nameopt RFC2253 -noout
- Connect to
mongo
withssl
enable which also automatically enablingx.509 certificate
:
mongo --ssl --sslPEMKeyFile client.pem --sslCAFile ca.pem
- Create a user with credential defined in
client.pem
:
db.getSiblingDB("$external").runCommand({createUser: "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=client", roles: [{role: 'root', db: 'admin'}]})
Note that we used $external
since all credential meta data stored in external database defined in server.pem
7. To be authenticated, execute this command:
db.getSiblingDB("$external").auth({user: "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=client", mechanism: "MONGODB-X509"})