Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
MongoDB 4 Quick Start Guide

You're reading from  MongoDB 4 Quick Start Guide

Product type Book
Published in Sep 2018
Publisher Packt
ISBN-13 9781789343533
Pages 192 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Doug Bierer Doug Bierer
Profile icon Doug Bierer

Securing MongoDB

This chapter explains how to secure the database itself, add users, and adjust permissions to specific collections. You will also learn how to enforce authentication and create an admin user. In addition, we will address how to configure MongoDB to use SSL/TLS.

The topics that are going to be covered in this chapter are as follows:

  • MongoDB security overview
  • Transport Layer Security
  • Authentication
  • Access control

MongoDB security overview

By default, after first installing the MongoDB database, there will be no security. Unlike earlier versions, however, as of MongoDB version 4.0, mongod binds to localhost, which provides a limited measure of safety. This lack of security facilitates initial administration and development. A production server, of course, will need a full measure of security.

Before deploying any measures (for example, replication or sharding) which would cause the database to be exposed to the company network, you should first implement proper security measures. MongoDB security encompasses several aspects, all of which are covered in this chapter. These include transport layer security, authentication, and access control.

The basic checklist for establishing security is as follows:

  • Configuring MongoDB for TLS (Transport Layer Security)
  • Defining the authentication mechanism...

Transport Layer Security

Contrary to what you would expect from its name, Transport Layer Security (https://en.wikipedia.org/wiki/Transport_Layer_Security) does not concern the TCP (Transmission Control Protocol) layer of the TCP/IP protocol stack. Instead, TLS in this context applies to the application (https://en.wikipedia.org/wiki/Application_layer) (top) layer. The data at this layer is transmitted using end-to-end encryption based on a secret which the sender and receiver share, thus ensuring the privacy of the communication. In addition, depending on how the protocol is configured, one or both sides can be authenticated, and a message integrity check can be enabled to ensure the reliability of the message.

Two protocols are used to ensure transport layer security: SSL (Secure Sockets Layer) and TLS . Of the two, only TLS should be used, and even at that, the later the version...

Authentication

Authentication is the process of determining are you who you say you are?. Authentication is not required until you enable access control (covered in the next section). At first, it might appear that authentication and access control are the same thing. They are both aspects of security, but authentication occurs before access control. In other words, MongoDB needs to first confirm you are who you say you are before deciding what actions you are allowed to perform.

Authentication itself takes different forms. In one case, you might be a user who wishes to run commands via the mongo shell. Another case would be a series of database commands being issued by an application using a MongoDB programming language driver. There is yet a third form of authentication whereby you can configure authentication between servers in a replica set or a sharded cluster (see Chapter...

Access control

Access control (also referred to as authorization) defines and enforces what actions a database user is allowed to perform once authenticated. Access control follows authentication: you cannot have one without the other! As you may recall from our previous discussion, authentication is the process of determining the identity of a user. Access control, on the other hand, determines what the user can do.

You establish access control over one or more databases by assigning privilege actions (https://docs.mongodb.com/manual/reference/privilege-actions/#privilege-actions) to roles. Privileges fall into three general categories: CRUD (Create Read Update Delete) operations, Database Management (for example, managing database users), and Infrastructure Management (for example, replication and sharding operations).

...

Summary

In this chapter, you learned about the different aspects of security in a MongoDB installation. After an initial overview, you learned about transport layer security, and how to configure MongoDB for TLS/SSL. After that, you learned about the different authentication mechanisms available, including SCRAM and x.509 certificates. You also learned about Kerberos and LDAP, which are only available in the MongoDB Enterprise Edition. After that, you learned how to enable authentication and create an admin user. You then learned about the various database privilege actions which can be applied to roles. You also learned about some of the built-in roles and how to define your own. Finally, you learned how to create database users and assign them to one or more roles.

In the next chapter, you will be given a walkthrough of a complete application based upon MongoDB, including capturing...

lock icon The rest of the chapter is locked
You have been reading a chapter from
MongoDB 4 Quick Start Guide
Published in: Sep 2018 Publisher: Packt ISBN-13: 9781789343533
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}