Skip to content

DB2 - LDAP

DB2 - Integrating with LDAP for Centralized Authentication

Section titled “DB2 - Integrating with LDAP for Centralized Authentication”

Introduction to Centralized Authentication

Section titled “Introduction to Centralized Authentication”

In modern IT environments, managing user accounts individually on each server (Operating System-based authentication) is inefficient and insecure. A centralized user directory service solves this by providing a single source of truth for user identities. Lightweight Directory Access Protocol (LDAP) is the industry standard for interacting with these directory services, such as OpenLDAP or Microsoft Active Directory.

By integrating Db2 with an LDAP server, you can delegate user authentication and group lookups to your central directory. This simplifies user management, enhances security by enforcing consistent password policies, and streamlines access control. This tutorial will guide you through configuring Db2 to use an LDAP directory for authentication.

Db2 supports LDAP integration via a security plug-in model. We will focus on the most common and secure approach: transparent server-side authentication.

Prerequisites: Preparing Your LDAP Directory

Section titled “Prerequisites: Preparing Your LDAP Directory”

Before configuring Db2, you must ensure your LDAP directory is structured to support it. Db2 needs to find user and group objects. While the specific schema may vary, the core requirements are consistent.

You will need entries for your Db2 users and groups. Typically, these use standard object classes like posixAccount for users and posixGroup or groupOfNames for groups. Below is an example in LDAP Data Interchange Format (LDIF) showing a user db2inst1 and a group db2adms.

## User Entry for 'db2inst1'
dn: uid=db2inst1,ou=users,dc=example,dc=com
objectClass: top
objectClass: inetOrgPerson
objectClass: posixAccount
uid: db2inst1
sn: db2inst1
cn: Db2 Instance One
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/db2inst1
## Group Entry for 'db2adms'
dn: cn=db2adms,ou=groups,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
cn: db2adms
member: uid=db2inst1,ou=users,dc=example,dc=com

Note: Your Distinguished Names (DNs), such as dc=example,dc=com, will depend on your LDAP server’s configuration. Ensure these users and groups are created on your LDAP server before proceeding.

The integration process involves three main steps: copying the plug-in files, creating a configuration file for the plug-in, and updating the Db2 Database Manager (DBM) configuration to use the plug-in.

Db2 provides the necessary plug-in libraries with its installation. You need to copy them from the installation path to the instance’s security plug-in directory. Connect as the instance owner to perform these steps.

# The path may vary based on your Db2 version and installation location
SQLLIB_PATH=$(db2 get dbm cfg | grep 'Path to database directory' | awk -F'= ' '{print $2}')/sqllib
PLUGIN_SOURCE_PATH=/opt/ibm/db2/V11.5/security/plugin
# Copy server-side authentication and group lookup plug-ins
cp ${PLUGIN_SOURCE_PATH}/server/IBMLDAPauthserver.so ${SQLLIB_PATH}/security/plugin/server/
cp ${PLUGIN_SOURCE_PATH}/group/IBMLDAPgroups.so ${SQLLIB_PATH}/security/plugin/group/

Step 2: Create the Plug-in Configuration File

Section titled “Step 2: Create the Plug-in Configuration File”

Create a file named IBMLDAPSecurity.ini inside the <instance_home>/sqllib/cfg/ directory. This file tells the Db2 plug-in how to connect to and search your LDAP server.

# Location: <instance_home>/sqllib/cfg/IBMLDAPSecurity.ini
# --- SERVER RELATED VALUES ---
# Your LDAP server hostname or IP. For multiple servers, separate with spaces.
# For secure LDAP (LDAPS), use port 636 and set SSL_ENABLE=true.
LDAP_HOST = myldap.server.com:389
# Set to TRUE to use LDAPS for encrypted communication
SSL_ENABLE = FALSE
# --- USER RELATED VALUES ---
# The base DN where user searches should start.
USER_BASEDN = ou=users,dc=example,dc=com
# The LDAP attribute that holds the user ID (e.g., 'uid', 'sAMAccountName').
USERID_ATTRIBUTE = uid
# The object class that defines a user entry.
USER_OBJECTCLASS = posixAccount
# --- GROUP RELATED VALUES ---
# The base DN where group searches should start.
GROUP_BASEDN = ou=groups,dc=example,dc=com
# The LDAP attribute that holds the group name.
GROUPNAME_ATTRIBUTE = cn
# The object class that defines a group entry.
GROUP_OBJECTCLASS = groupOfNames
# The attribute within a group that lists its members.
GROUP_LOOKUP_ATTRIBUTE = member

Best Practice: For production systems, always use LDAPS. This requires setting SSL_ENABLE = TRUE and may require configuring a keystore for the SSL certificate using the SSL_KEYDB and SSL_STASH parameters. Refer to the official Db2 documentation for details.

Step 3: Update the Database Manager Configuration

Section titled “Step 3: Update the Database Manager Configuration”

Finally, tell Db2 to use the new plug-ins for authentication and group management. These changes require an instance restart to take effect.

# As the Db2 instance owner:
db2 UPDATE DBM CFG USING AUTHENTICATION SERVER_ENCRYPT
db2 UPDATE DBM CFG USING SRVCON_PW_PLUGIN IBMLDAPauthserver
db2 UPDATE DBM CFG USING GROUP_PLUGIN IBMLDAPgroups
# Restart the Db2 instance for changes to take effect
db2stop
db2start

After restarting the instance, you can validate the configuration by attempting to connect to a database using an LDAP user’s credentials.

# Connect using an LDAP user ID and password
db2 CONNECT TO mydatabase USER ldapuser1 USING 'password123'
  • Connection Fails: If db2start fails or connections are rejected, check the db2diag.log file. It often contains detailed error messages from the LDAP plug-in.
  • Invalid Credentials: This means the LDAP server rejected the username/password. Verify the credentials and ensure the USERID_ATTRIBUTE in your .ini file is correct (e.g., uid for OpenLDAP, sAMAccountName for Active Directory).
  • User Not Found: If the user is valid but Db2 can’t find it, double-check the USER_BASEDN and USER_OBJECTCLASS settings. Ensure the Db2 server can reach the LDAP_HOST on the specified port.
  • Group Issues: If a user can connect but lacks expected permissions, verify the group-related settings (GROUP_BASEDN, GROUPNAME_ATTRIBUTE, etc.) and ensure the user is correctly listed as a member in the LDAP group.
  • Debugging Tool: Use a command-line tool like ldapsearch from the Db2 server machine to manually query the LDAP server. This helps confirm connectivity and that your search filters and base DNs are correct, independent of Db2.

This tutorial covers transparent LDAP authentication. Db2 also supports mapping LDAP users to different Db2 authorization IDs and more complex directory schemas. For advanced configurations and security hardening, always consult the latest IBM Db2 Knowledge Center for your specific version.