{"id":44,"date":"2021-11-02T21:12:00","date_gmt":"2021-11-03T01:12:00","guid":{"rendered":"https:\/\/www.jumpcloud.com\/engineering-blog\/?p=44"},"modified":"2024-01-29T14:34:50","modified_gmt":"2024-01-29T19:34:50","slug":"using-ldap-authenticate-mysql","status":"publish","type":"post","link":"https:\/\/jumpcloud.com\/blog\/using-ldap-authenticate-mysql","title":{"rendered":"Manage MySQL and Related Database Servers with LDAP"},"content":{"rendered":"\n
This is a refreshed article which initially only focused on integrating the community edition of MySQL with LDAP. That\u2019s no longer possible, so we\u2019ve provided guidance to connect to a variety of popular relational databases that are similar or compatible. You should choose the one that works best for your use case. This article was contributed to by TJ Webb, Cody Pritchard, and Stephen Brown.<\/em><\/p>\n\n\n\n MySQL<\/a> is a leading relational database system that\u2019s available in commercial and open source offerings that are driven by Oracle. Its ubiquity has spawned several forks, providing several distinct alternatives. Managing users for MySQL is typically a manual chore resulting in extra time, systems, and effort \u2014 and, potentially a security risk when users created in the database are independent of a business’s identity management system and user provisioning process. The commercial distribution of MySQL supports external user authentication including LDAP using its bundled connectors. The community edition has fewer native options, but LDAP management is still possible when very specific prerequisites and security requirements are met. An unsupported GitHub project can be used to configure a free Linux PAM<\/a> plugin. <\/p>\n\n\n\n There are other choices for your project within the MySQL \u201cfamily\u201d such as MariaDB and Percona, or another open source SQL database such as Postgres. MariaDB is a free and open source software (FOSS) fork of the MySQL database that has a PAM authentication option. It\u2019s evolved in its own direction<\/a> and, while compatible, isn\u2019t a direct substitution of MySQL. Percona is a performance-tuned edition of MySQL that also provides a plugin. We\u2019ve included Postgres as an alternative relational database. Your requirements and budget will determine what solution is the best fit for the job at hand. The common thread is the user management benefits of LDAP, a common user directory that organizations may have, based upon mature and open standards. Connecting SQL databases to LDAP services benefits IT admins in a number of ways:<\/p>\n\n\n\n JumpCloud\u2019s cloud directory platform<\/a> makes it easy to manage, authenticate, and authorize MySQL users. The platform\u2019s LDAP service makes it possible for users to be populated in our directory and then MySQL can authenticate via a secure LDAP endpoint<\/a> requiring only minimal configuration necessary on the application side. Multi-factor authentication (MFA) then adds an additional layer of security.<\/p>\n\n\n\n This article covers:<\/p>\n\n\n\n Considerations:<\/p>\n\n\n\n If you haven’t done so already, please sign up for the JumpCloud service here<\/a>. You can evaluate this entire process below with no commitment. We give you 10 free users forever with the full functionality of the JumpCloud platform and the option for 10 days of live chat support to help you along the way if you get stuck with the integration(s).<\/p>\n\n\n\n First, you’ll need to have an LDAP server to manage your users. You can easily leverage JumpCloud for this purpose by following the steps below. You may also manually provision and configure LDAP if you prefer using OpenLDAP, as an example LDAP server. That configuration option is also outlined here.<\/p>\n\n\n\n Before MySQL can be integrated with JumpCloud’s LDAP endpoint, the following steps need to be completed to ensure it can communicate effectively via ldapsearch.<\/p>\n\n\n\n You may see the message: \u201cTo enable LDAP, you need to have at least one user that\u2019s enabled as LDAP Bind DN.\u201d A Bind DN is a Distinguished Name (DN). This is a credential you\u2019ll authenticate against<\/a> in LDAP and you may consider creating a \u201cservice\u201d user account specifically for this purpose with a very strong password.<\/p>\n\n\n\n Create an LDAP Binding user<\/strong><\/p>\n\n\n\n The LDAP Binding user is created to allow the application to gain access to the LDAP directory in order to facilitate authentication requests when a regular LDAP user is attempting to login. JumpCloud does not support anonymous binds. When a user is designated as the Bind DN, they are automatically bound to the JumpCloud LDAP directory. It\u2019s advisable to have a dedicated service account, with a strong password, separate from your regular user accounts.<\/p>\n\n\n\n Considerations:<\/p>\n\n\n\n Adding users to the JumpCloud directory<\/strong><\/p>\n\n\n\n In this next step, you will add users to the directory. These will be the users you desire to provision to MySQL and elsewhere. Follow the steps above in Step 1, yet in this case, you do not need to elect these users as an LDAP Binding account. The MySQL documentation notes that users that will be managed by LDAP must already exist within the directory.<\/p>\n\n\n\n Every cloud LDAP integration discussed below requires implementing the steps outlined above.<\/em><\/p>\n\n\n\n The other option is to do it yourself where you\u2019ll be required to stand up and manage an LDAP server to utilize these authentication methods. You’ll have to manage uptime and maintenance, which creates the potential for a single point of failure (directory availability) within the authentication chain. Rolling your own MFA for added security will involve installing and configuring a FreeRADIUS server and LinOTP to establish a second authentication factor for LDAP. <\/p>\n\n\n\n Linux distributions are capable of configuring<\/a> LDAP to use STARTTLS to secure authentication between the LDAP client and server, but you\u2019ll have to also take on the management of provisioning the certificate and managing keys yourself. For Windows environments, you can configure the Windows native LDAP library either in Windows Server or a VM hosted by a cloud provider through the Add Roles and Features Wizard interface. AD LDS (Active Directory Lightweight Directory Services) must be set up as well as LDAPS.<\/p>\n\n\n\n Here are the commands required to install the packages in Ubuntu Linux<\/strong>.<\/p>\n\n\n\n sudo apt update<\/p>\n\n\n\n<\/code>\n\n\n\n sudo apt install slapd ldap-utils<\/p>\n\n\n\n<\/code>\n\n\n\n The subsequent steps can be found here<\/a>.<\/p>\n\n\n\n Windows users<\/strong> can configure the Windows native LDAP library either in Windows Server or a VM hosted by a cloud provider through the Add Roles and Features Wizard interface. AD LDS (Active Directory Lightweight Directory Services) must be set up as well as LDAPS.<\/p>\n\n\n\n Microsoft\u2019s documentation is available here<\/a>.<\/p>\n\n\n\n You can easily leverage JumpCloud\u2019s hosted LDAP service instead of standing up your own LDAP server and managing it, all part of Directory-as-a-Service. Connect it to all of your critical apps, and you are good to go. Your users will also appreciate this, as their single account can now be used for technical applications as well. <\/a>If you are utilizing MySQL within your organization, give JumpCloud a try<\/a> to simplify user management and increase database security.<\/p>\n\n\n\n Oracle provides MySQL Enterprise as a subscription-based service, which you can configure MySQL to authenticate to the JumpCloud LDAP endpoint. There are two basic options to integrate the commercial MySQL edition with an LDAP directory: <\/p>\n\n\n\n LDAP Pluggable Authentication is the most secure method out of the box, using TLS to communicate with the cloud directory<\/em>. However, all approaches listed here do not use encryption<\/strong> on the client side<\/em> and must be configured correctly to not become a security problem. The involved plugin must also be explicitly enabled to avoid inadvertent password exposure. <\/p>\n\n\n\n Please note<\/em> that you won\u2019t be able to install the plugins for LDAP Pluggable Authentication <\/strong>if you\u2019re running the community build, which lacks the necessary server-side functionality. There are additional steps involved to successfully deploy TLS with the other two methods.<\/p>\n\n\n\n This diagram<\/a> shows all the components except the LDAP server (or ldap.jumpcloud.com) itself: The PAM icon is replaced with the LDAP server since it connects directly.<\/p>\n\n\n\n Please be mindful of this warning and follow all directions. <\/strong>MySQL provides several options for authentication and each has its own documentation as well as advanced options.<\/p>\n\n\n\n Just like with the HTTP protocol, the LDAP protocol can be written using a Uniform Resource Locator or Identifier (URL\/URI) and contain additional information about the directory and associated queries. The customer\u2019s JumpCloud LDAP Directory will always need to point to the DNS name of our OpenLDAP-based Directory Servers: ldap.jumpcloud.com<\/p>\n\n\n\n LDAP URL for unencrypted LDAP Directory Access: <\/p>\n\n\n\n (ldap:\/\/ implies port 389 so specifying the port is not required in most cases.)<\/p>\n\n\n\n ldap:\/\/ldap.jumpcloud.com<\/p>\n\n\n\n ldap:\/\/ldap.jumpcloud.com:389<\/p>\n\n\n\n LDAPS URL for encrypted LDAP Directory Access:<\/p>\n\n\n\n (ldaps:\/\/ implies port 636 so specifying the port is not required in most cases.)<\/p>\n\n\n\n ldaps:\/\/ldap.jumpcloud.com<\/p>\n\n\n\n ldaps:\/\/ldap.jumpcloud.com:636<\/p>\n\n\n\n JumpCloud\u2019s LDAP services would be the hostname used in this configuration.<\/p>\n\n\n\n Port 389 will operate over plain-text if StartTLS is not negotiated.<\/strong><\/p>\n\n\n\n Since there are no server-side plugins available in this distribution, another possibility is to use an open source plugin<\/a> for the community version that\u2019s developed and maintained by an open source development company<\/a>. The caveat is that the community isn\u2019t large and a single vendor is the primary contributor. The configuration file<\/strong> looks like this with the cacert file being required for an LDAPS connection, which will encrypt LDAP data. It\u2019s an extra step (highlighted below), but is a requisite for good security practice:<\/p>\n\n\n\n The capitalized letters in the bind_dn indicate where to enter your organization\u2019s parameters.<\/em><\/p>\n\n\n\n Note that the password between the client and server is in plaintext by default just as with the MySQL Enterprise PAM module. The LDAP server performs hashing and authentication versus the default of the password being sent onto the MySQL itself.<\/strong><\/p>\n\n\n\n Please see this <\/strong>knowledge base article<\/strong><\/a> for more information about including a certificate.<\/strong><\/p>\n\n\n\n
\n\n\n\n\n
\n
\n
Setting Up an LDAP Server<\/h2>\n\n\n\n
Cloud LDAP Using JumpCloud<\/h3>\n\n\n\n
Step 1: Preparing JumpCloud as the LDAP Directory<\/h4>\n\n\n\n
\n
Step 2: Create an LDAP Service User Account<\/h4>\n\n\n\n
\n
\n
\n
\n
Manual Setup<\/h3>\n\n\n\n
Linux<\/h4>\n\n\n\n
\n\n\n\n
\n\n\n\n
Windows Server<\/h4>\n\n\n\n
MySQL Commercial Edition<\/h2>\n\n\n\n
\n
\n
\n
\n
MySQL Community Edition<\/h2>\n\n\n\n
\n\n\n\n
ldap:<\/td> <\/td><\/tr> <\/td> {<\/td><\/tr> <\/td> uri = “ldaps:\/\/ldap.jumpcloud.com:636”;<\/td><\/tr> <\/td> user_base = “dc=sample_company,dc=com”;<\/td><\/tr> <\/td> cacert_file = “\/etc\/ssl\/ldap\/ca.crt”;<\/td><\/tr> <\/td> bind_dn = “uid=<JC LDAP BIND DN username>,o=<JC Org ID>,ou=users,dc=jumpcloud,dc=com”;<\/td><\/tr> <\/td> bind_pw = “sample_password”;<\/td><\/tr> <\/td> login_attribute = “uid”;<\/td><\/tr> <\/td> search_filter = “(objectClass=inetOrgPerson)”;<\/td><\/tr> <\/td> libldap = “\/usr\/local\/lib\/libldap.so”;<\/td><\/tr> <\/td> log_level = “normal”; # can be “normal” or “debug”<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<\/code>\n\n\n\n