Percona Server for MongoDB currently has several external authentication options, such as LDAP with SASL, LDAP, Kerberos, and AWS IAM. What is amazing is that SASL can authenticate with Pluggable Authentication Modules (PAM) too. This means that you still have additional external authentication options to choose from through PAM libraries.

For a quick demonstration of PAM authentication in Oracle Enterprise Linux 9, we will authenticate with Unix users using the pam_unix.so module since this is already built-in. You can also search previous articles in the Percona blog for other examples of using PAM with different modules to authenticate to WindowsAD, Samba, Google Authenticator, and LDAP. These solutions should work as well with SASL with minimal adjustments.

Setting up the Unix users:

1. Use useradd to add the users:

2. Use passwd to change the passwords of the users:

Setting up SASL to authenticate via PAM with mongodb service:

1. Install cyrus-sasl and cyrus-sasl-plain packages:

2. Start saslauthd and ensure it runs when the OS is restarted:

By default, saslauthd authenticates to PAM modules.

We just need to add the PAM service for MongoDB to authenticate with Unix users.

3. To create the PAM service for MongoDB, create a file called /etc/pam.d/mongodb with this content:

4. Test authentication by supplying the username and password of the Unix users and service mongodb which we configured above with testsaslauthd:

Setting up MongoDB configuration with SASL

1. Install and start Percona Server for MongoDB and ensure it starts when the OS is restarted:

2. Create the Unix users in the $external database of MongoDB:

3. Create /etc/sasl2/mongodb.conf to integrate MongoDB with SASL. Ensure that the file is accessible by MongoDB:

4. Edit /etc/mongodb.conf and append the following at the bottom of the configuration file to allow MongoDB to authenticate in plaintext format and use SASL:

5. Restart MongoDB for the configuration changes to take effect:

6. Test login with MongoDB and Unix User:

Voila! Now, users can authenticate with PAM modules!

Take note that since we used PLAIN(text) as the authentication mechanism in MongoDB, you need to make sure that users connect to MongoDB over TLS/SSL. You also need to ensure that transport from SASL to the external authentication backend is secure as well. For other security considerations, it would be best to consult with your security administrators or consider Percona Professional Services.

Percona Distribution for MongoDB is a source-available alternative for enterprise MongoDB. A bundling of Percona Server for MongoDB and Percona Backup for MongoDB, Percona Distribution for MongoDB combines the best and most critical enterprise components from the open source community into a single feature-rich and freely available solution.

 

Download Percona Distribution for MongoDB Today!

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments