IBM Db2 credential management
Vault provides credential lifecycle management for a wide range of database systems. This tutorial demonstrates the use of the LDAP secrets engine to manage dynamic and static credentials for access to IBM Db2.
Challenge
Access to Db2 is managed by facilities that reside outside the Db2 database system. By default, user authentication is completed by a security facility that relies on operating system based authentication of users and passwords. This means that the lifecycle of user identities in Db2 aren't capable of being managed using SQL statements, which creates an operational challenge for credential lifecycle management.
To provide flexibility in accommodating authentication needs, Db2 ships with authentication plugin modules for Lightweight Directory Access Protocol (LDAP). This enables the Db2 database manager to authenticate users and obtain group membership defined in an LDAP directory, removing the requirement that users and groups be defined to the operating system.
Central management of Db2 user authentication and group membership in LDAP solves some operational challenges. However, the following credential lifecycle management challenges still exist:
- Generating short-lived credentials
- Revoking credentials after a time-to-live (TTL)
- Renewing credentials to extend the time-to-live (TTL)
- Rotating the passwords for pre-existing credentials
Solution
Using Vault's LDAP secrets engine, we can solve the challenges of credential lifecycle management for Db2 environments that have been configured to delegate user authentication and group membership to an LDAP server. This allows Vault to manage the lifecycle of credentials used to access the Db2 database system.
Note
The architecture for implementing this solution is highly context dependent. The assumptions made in this tutorial help to provide a practical example of how this could be configured. Be sure to read the LDAP plugin module documentation to understand the tradeoffs and security implications.
The solution presented in this tutorial makes the following assumptions:
- Db2 is configured to authenticate users from an LDAP server using the server authentication plugin module
- Db2 is configured to retrieve group membership from an LDAP server using the group lookup plugin module
- The LDAP directory information tree (DIT) has a structure as defined below
The following diagram shows the high-level architecture of the solution presented in this tutorial:
Personas
The solution described in this tutorial involves four personas:
vault-admin
an administrator of Vault with permissions to configure secrets enginesldap-admin
an administrator of the LDAP serverdb2-admin
an administrator of Db2client
a client of Vault with permissions to read credentials and a client of Db2 that needs access to data
Prerequisites
To perform the tasks described in this tutorial, you need to have:
- A Vault environment of version 1.4 or later
- A Db2 environment of version 9.7 or later
- An LDAP environment of version 3
- If missing Db2 or LDAP environments, you'll need Docker to create the tutorial environment
Policy requirements
For the purpose of this tutorial, you will use root
token to work with Vault
running in development mode.
When you are working with a non-development Vault environment, your token policy must include the following permissions:
If you are not familiar with policies, complete the policies tutorial.
Create environment
Instructions are provided to set up the environment needed for an end-to-end tutorial. If you already have environments for any of these systems, you can skip the steps and modify the appropriate values in subsequent examples. In any case, we recommend reading through each section of this tutorial to understand the various points of integration.
Prepare host environment
Create a temporary location for the Db2 storage directories.
Create a Docker network named learn-vault
. This network will allow Db2 to connect to
an OpenLDAP server.
Start Vault
(Persona: vault-admin)
In another terminal, start a Vault dev server with root
as the root token.
The Vault dev server defaults to running at 127.0.0.1:8200
. The server is
initialized and unsealed.
Insecure operation
Do not run a Vault dev server in production. This approach starts a Vault server with an in-memory database and runs in an insecure way.
Open another terminal session, and export an environment variable for the
vault
CLI to address the Vault server.
Export an environment variable for the vault
CLI to authenticate with the
Vault server.
Note
For these tasks, you can use Vault's root token. However, it is recommended that root tokens are only used for enough initial setup or in emergencies. As a best practice, use an authentication method or token that meets the policy requirements.
Start OpenLDAP
(Persona: ldap-admin)
Start an OpenLDAP container using docker run
.
After starting the container, you can verify that it is running.
Configure OpenLDAP with example data
(Persona: ldap-admin)
Next, you'll need to add some initial configuration to the OpenLDAP directory in order to eventually configure:
- Vault's LDAP secrets engine to manage dynamic and static credentials
- Db2 to read credentials and group membership for authentication
Note
The structure of the LDAP directory used in this tutorial serves as an example. The configuration will vary when using an existing LDAP environment. Be sure to read the LDAP plugin module documentation to understand which parts of the directory structure are required. For example, creation of the Db2 instance owner ID, fenced user, and any groups for authorization are required.
Finally, use the ldapadd
utility to apply this configuration.
Note
LDAPAdminPassword
was the value provided to LDAP_ADMIN_PASSWORD
when
starting the Docker container. If using an existing LDAP environment, enter the known
administrator password and an appropriate bind distinguished name (DN).
Successful output:
Start Db2
(Persona: db2-admin)
Start a Db2 container using docker run
.
After starting the container, you can verify that it is running.
After the docker run
command is executed, it will take a few minutes for the container
to finish setting up. You may run the following command to tail the logs of the Docker
entry point script. Check the logs for the message Setup has completed to confirm
that the Db2 container is ready.
Configure the Db2 LDAP plugin modules
(Persona: db2-admin, ldap-admin)
Next, you need to configure the LDAP plugin modules for Db2 by updating its configuration
file to suit your environment. In most cases, you will need to consult with ldap-admin
to determine the appropriate configuration values. See the LDAP plugin modules documentation
for the location of the configuration file on your system.
For the environment of this tutorial, the configuration file can be found at either:
${INSTHOME}/sqllib/cfg/IBMLDAPSecurity.ini.sample
from within the Db2 container${VAULT_DB2_DATA}/config/db2inst1/sqllib/cfg/IBMLDAPSecurity.ini.sample
from your host filesystem
Make a copy of IBMLDAPSecurity.ini.sample
and rename it as IBMLDAPSecurity.ini
in the
same directory. See that IBMLDAPSecurity.ini
has a number of different LDAP-related
configuration parameters. The values provided to these parameters will depend on your
environment.
Most parameters in IBMLDAPSecurity.ini
can be left with defaults for this tutorial.
However, the following parameters need to be updated:
Parameter | Value |
---|---|
LDAP_HOST | openldap:389 |
USER_BASEDN | ou=users,dc=example,dc=com |
GROUP_BASEDN | ou=groups,dc=example,dc=com |
SEARCH_DN | cn=admin,dc=example,dc=com |
SEARCH_PW | LDAPAdminPassword |
After making the appropriate modifications to IBMLDAPSecurity.ini
, you'll need to instruct
Db2 to use the IBMLDAPauthserver
and IBMLDAPgroups
plugins by updating its configuration.
First, get an interactive shell in the Db2 container using docker exec
.
Next, instruct Db2 to use the IBMLDAPauthserver
and IBMLDAPgroups
plugins by updating
its configuration.
Finally, restart Db2 to put the configuration change into effect:
Your Db2 instance is now configured to use the LDAP plugin modules to authenticate users and obtain group membership defined in the LDAP directory.
Configure the LDAP secrets engine
(Persona: vault-admin, ldap-admin)
The LDAP secrets engine needs to be configured in order the manage the lifecycle of dynamic and static credentials that'll be used to access Db2.
The first step is to enable the secrets engine.
Next, write the secrets engine configuration. We'll bind to the LDAP server using the
admin
user and password that was created when we started the OpenLDAP container.
Connect to Db2 using dynamic credentials
The LDAP secrets engine provides creation of dynamic credentials which are associated with a lease in Vault. In this section, you'll create dynamic credentials and use them to access Db2.
Create a role
(Persona: vault-admin, ldap-admin)
First, create a role
in the secrets engine. A role represents how dynamic credentials will be created in the
LDAP directory. Roles use LDIF entries
as a part of their configuration. Example LDIF entries have been provided for this tutorial.
Consult with ldap-admin
to determine the appropriate LDIF entries for your environment.
Create the role using the LDIF entries.
Connect to Db2
(Persona: client)
Next, generate dynamic credentials using the role.
Successful output:
Finally, we can use the dynamic credentials to connect to Db2.
Get an interactive shell in the Db2 container using docker exec
.
Connect to Db2 as the dynamically generated user.
Where <username>
and <password>
are the Vault-generated dynamic credentials.
Example:
You've successfully connected to a database in Db2 using dynamic credentials managed by Vault's LDAP secrets engine. See the Connecting with an LDAP user ID documentation for additional connection options, including using partial and full LDAP distinguished names (DN).
Connect to Db2 using static credentials
The LDAP secrets engine provides automatic and manual rotation of passwords for pre-existing LDAP entries. In this section, you'll onboard a pre-existing LDAP entry using static roles. This will allow Vault to manage password rotation for credentials that are used to access Db2.
Create a static role
(Persona: vault-admin, ldap-admin)
First, create a static role
in the secrets engine. A static role maps a name in Vault to an entry in an LDAP directory.
Automatic password rotation can be configured using the rotation_period
parameter. Consult with ldap-admin
to determine the appropriate values for the
distinguished name and
username for your
environment.
Connect to Db2
(Persona: client)
Next, read the rotated password of the LDAP user that was onboarded to the static role.
Successful output:
Get an interactive shell in the Db2 container using docker exec
.
Connect to Db2 as staticuser
.
Where <password>
is the Vault-rotated password.
Example:
You've successfully connected to a database in Db2 using static credentials managed by Vault's LDAP secrets engine. See the Connecting with an LDAP user ID documentation for additional connection options, including using partial and full LDAP distinguished names (DN).
Authorization from LDAP group membership
As a part of this tutorial, you've configured Db2 to retrieve group membership from an LDAP server using the group lookup plugin module. Groups provide a convenient means of performing authorization for a collection of users in Db2 without having to grant or revoke privileges for each user individually.
In sections below, you'll use group membership from an LDAP server to grant system authorities and privileges to a Db2 user that's managed by Vault.
System authorities
(Persona: db2-admin, ldap-admin)
Group membership can be mapped to system authorities
in Db2 to grant authorization. In this section, you'll add staticuser
to the DB2IADM1
LDAP group to grant a system authority in Db2.
Get an interactive shell in the Db2 container using docker exec
.
Next, observe the default mapping between system authorities and group names by running:
Successful output:
You can see that by default, the SYSADM
authority maps to the DB2IADM1
group name. You
can exit
the interactive shell.
To show how LDAP group membership enables granting of system authorities in Db2, add the
staticuser
to the DB2IADM1
group in the LDAP directory.
Next, verify that staticuser
has been added to the db2iadm1
group by performing an
LDAP search. You should see that there are now two members in the group, one of which is
staticuser
.
Successful output:
Validation
Get an interactive shell in the Db2 container using docker exec
.
Next, connect to Db2 as db2inst1
.
Finally, run the following Db2 commands to verify that staticuser
now has the SYSADM
authority. See the AUTH_LIST_AUTHORITIES_FOR_AUTHID
documentation for column descriptions.
Successful output:
You've successfully granted staticuser
the SYSADM
authority using LDAP group membership.
Privileges
(Persona: db2-admin)
Group membership can be used to assign privileges
in Db2 to grant authorization. In this section, you'll grant privileges for accessing Db2
data to staticuser
based on its LDAP group membership.
Get an interactive shell in the Db2 container using docker exec
.
Next, connect to Db2 as db2inst1
.
Observe the current group membership for staticuser
as reported by Db2.
Successful output:
You can see that staticuser
belongs to the DEV
group. This is expected from the
LDAP directory created in this tutorial.
Next, grant privileges to access sample data to the DEV
group.
Next, connect to Db2 as staticuser
which is a member of the DEV
group. Replace
<password>
with the Vault-rotated password.
Finally, execute a query to access data granted by the group privilege. Prior to the grant, authorization of the query would not succeed.
Successful output:
You've successfully granted staticuser
database privileges using LDAP group membership.