Configuring LDAP authentication for IBM Cloud Private Cloud Foundry

You can use LDAP authentication for user authentication in IBM® Cloud Private Cloud Foundry and Cloud Foundry Enterprise Environment.

You can follow these instructions to configure LDAP authentication at any time before or after you install IBM Cloud Private Cloud Foundry (see Installing IBM Cloud Private Cloud Foundry) or Cloud Foundry Enterprise Environment (see Installing Cloud Foundry Enterprise Environment). The configuration is done by adding the included extension cfp-ext-ldap to the main IBM Cloud Private Cloud Foundry deployment. See Using extensions in IBM® Cloud Private Cloud Foundry. The cfp-ext-ldap extension modifies the deployment properties for the User Account and Authentication (UAA) server.

Before you configure LDAP authentication, you must create the users in your LDAP or Active Directory domain. You can use groups to filter access to the IBM Cloud Private Cloud Foundry environment.

Preparing your configuration

The LDAP configuration is stored in a YAML-formatted file, referred to as <ldap_config_file> in these instructions. Create the file, for example ldapconfig.yml, and place the configuration details in the uiconfig: section, as shown in the example configuration.

If you prefer to use the Cloud Foundry deployment tool, the cfp-ext-ldap extension offers guided editing of the configuration values. From the States page, click Add Extension and select cfp-ext-ldap, then complete the dialog. Go to the Configuration page and locate cfp-ext-ldap in the list of extensions. Select a configuration type of Simple Binding, Search and Bind, Groups Map to Scopes, or Groups as Scopes. The Cloud Foundry deployment tool displays the required and optional configuration values for the selected scenario. The Cloud Foundry deployment tool provides descriptions, sample values, and validation of the configuration values. For information about extensions, see Managing extensions and Configurations.

To configure LDAP authentication, you must make the following choices:

Note: If you are adding LDAP for Cloud Foundry Enterprise Environment after an initial deployment, you must select upgrade for the Installer action.

Example configuration

uiconfig:
  enabled: true 
  url: 'ldap://ldap.local.bluemix.net'  # LDAP server URL (space-separated list permitted)
  add_shadow_user_on_login: true        # Enable to allow any LDAP user to log in; otherwise, accounts
                                        #   must be created manually (default value is true)

# BEGIN Include and customize the following lines to use simple-binding
  profile_type: simple-bind
  userDNPattern: 'cn={0},dc=local,dc=bluemix,dc=net;cn={0},dc=example,dc=org'
# END

# BEGIN Include and customize the following lines to use search-and-bind
  profile_type: search-and-bind
  userDN: 'cn=admin,dc=local,dc=bluemix,dc=net'
  userPassword: '**********'
  searchBase: 'dc=local,dc=bluemix,dc=net'  # Specify if only part of the directory should be searched
  searchFilter: 'cn={0}'                    # User name is inserted into this filter in place of {0}
# END

# BEGIN Include the following lines to customize which LDAP attributes are used to populate the UAA user record
  mailAttributeName: emailAddress       # Attribute containing email address of user (default is 'mail')
  mailSubstitute: 'generated-{0}@ldap'  # Form for generated email address if none found in LDAP record
                                        #   (default is {0}@user.from.ldap.cf)
  mailSubstituteOverridesLdap: false    # Enable to always use the value from mailSubstitute as user email
  attributeMappings:
    family_name: lastName               # LDAP attribute to use for family name (default value is sn)
    given_name: preferredName           # LDAP attribute to use for given name (default value is givenName)
# END

# BEGIN Include and customize the following lines to use groups-map-to-scopes or groups-as-scopes
#         (Requires using the search-and-bind binding method)
  groups:
    groupSearchFilter: 'member={0}'           # Used to find the groups a user (or group for nested search) belongs to
    searchBase: 'dc=local,dc=bluemix,dc=net'  # Specify if only part of the directory should be searched for groups
                                              #   Can be set to 'memberOf' if using Active Directory to skip group search
                                              #   and use calculated 'memberOf' field on user records
    maxSearchDepth: 2                         # Number of levels to search groups (default is 1 - no nested search)
    searchSubtree: true                       # Enable to search below the search base (default value is true)

    # BEGIN Include the following line to use groups-map-to-scopes
    profile_type: groups-map-to-scopes
    # END

    # BEGIN Include and customize the following lines to use groups-as-scopes
    profile_type: groups-as-scopes
    groupRoleAttribute: cloudFoundryScope  # Name of the LDAP attribute that holds a list (comma-separated)
                                            #   of scope names applied to members of the group
    # END

# END

  ssl:
    skipverification: false  # Enable to skip server certificate validation when using LDAPS
    tls: none                # Use value 'simple' to enable StartTLS (default value is none)
  sslCertificate: |+         # Self-signed server certificate to be trusted if using LDAPS
    -----BEGIN CERTIFICATE-----
    <BASE64_ENCODED_CERT>
    -----END CERTIFICATE-----

These instructions and example configuration cover the most common options for LDAP authentication. For the complete list of valid properties, see the uaa.ldap properties for the BOSH uaa job. For further details, see User Account and Authentication LDAP Integration.

Activating the cfp-ext-ldap extension by using the configuration manager CLI

  1. Push your configuration file to the inception container. <ldap_config_file> is the name of the LDAP configuration file that you created:

    ./cm extension -e cfp-ext-ldap save -c <ldap_config_file>
    
  2. Insert the extension in the main IBM Cloud Private Cloud Foundry or Cloud Foundry Enterprise Environment deployment. The following command adds the deployment of the LDAP extension before the deployment of the IBM Cloud Private Cloud Foundry or Cloud Foundry Enterprise Environment components. The LDAP extension is automatically inserted at the correct place in the states file.

    ./cm states insert -i cfp-ext-ldap
    
  3. Reset the engine:

    ./cm engine reset
    

Deploying Cloud Foundry with the cfp-ext-ldap extension

After you enable and configure the cfp-ext-ldap extension by using either the Cloud Foundry deployment tool or configuration manager CLI, you must relaunch the deployment of Cloud Foundry to update the affected components.

Activating users

If you chose to manually activate users, for each user that needs to access IBM Cloud Private Cloud Foundry, run the following command. <username> is an LDAP user ID that matches the userDNPattern or searchFilter property in the LDAP configuration, depending on the binding method you selected:

cf create-user <username> --origin ldap

Revoking user access

If you chose to manually activate users, you can revoke access for a user by deleting their account:

cf delete-user <username>

Otherwise, in addition to deleting the user by using the cf CLI, to revoke user access the user must be removed from LDAP. Or the user's group membership must be changed such that they no longer meet the criteria as defined by your LDAP binding configuration.

Assigning users to organizations and spaces

LDAP users cannot be automatically granted access to specific organizations or spaces, but you can grant permission before first login by first activating the user with the cf create-user <username> --origin ldap command and then assigning organization and space roles as usual. For more information, see Managing user permissions to organizations and spaces. These actions might be scripted if you have many LDAP users that you want to assign to certain organizations and spaces based on information in their LDAP records.

Mapping LDAP groups to scopes

If you chose to use groups-map-to-scopes to automatically assign extra privilege scopes to LDAP users based on the group membership, you can use the uaac CLI to manage the mappings.

  1. Install the uaac Ruby gem by using the following command:
    gem install cf-uaac
    
  2. Target the UAA server of your installation. Replace <bluemix_env_domain> with the environment domain used for your installation. Add the --skip-ssl-validation option to the command if your environment domain certificate is self-signed.
    uaac target https://uaa.<bluemix_env_domain>
    
  3. Find the UAA admin client secret.

    • For IBM Cloud Private Cloud Foundry, log in with the uaac CLI by finding the uaa_admin_client_secret value in the file <data_directory>/CloudFoundry/deployment-vars.yml.

    • For Cloud Foundry Enterprise Environment, obtain the <uaa_admin_client_secret> value by running the following command:

      kubectl get -n uaa secret secrets -o jsonpath='{.data.uaa-admin-client-secret}' | base64 --decode
      

    Substitute the UAA admin client secret into the following command:

    uaac token client get admin -s <uaa_admin_client_secret>
    

Now you can manage group mappings by issuing commands as shown in the following example:

uaac group mappings                      # List all group mappings
uaac group map --name <scope> <groupDN>  # Create a new group mapping by specifying the privilege scope
                                         #   and distinguished name (DN) of the LDAP group
uaac group unmap <scope> <groupDN>       # Delete a group mapping by specifying the privilege scope
                                         #   and distinguished name (DN) of the LDAP group
uaac user get <username>                 # Retrieve user information to verify which groups have been mapped