为 IBM Cloud Private Cloud Foundry 配置 LDAP 认证

您可以使用 LDAP 认证进行 IBM Cloud Private Cloud Foundry 中的用户认证。

您可以按照这些指示信息来配置 LDAP 认证,然后在 IBM Cloud Private Cloud Foundry 安装期间(请参阅安装 IBM Cloud Private Cloud Foundry)或安装后的任何时间运行 launch_deployment.sh 脚本。 通过将包含的扩展 cfp-ext-ldap 添加到主 IBM Cloud Private Cloud Foundry 部署来完成配置。 请参阅在 IBM® Cloud Private Cloud Foundry 中使用扩展cfp-ext-ldap 扩展修改用户帐户和认证 (UAA) 服务器的部署属性。

配置 LDAP 认证之前,您必须在 LDAP 或 Active Directory 域中创建用户。 您可以使用组来过滤对 IBM Cloud Private Cloud Foundry 环境的访问权。

准备配置

LDAP 配置存储在 YAML 格式的文件中,该文件在这些指示信息中被称为 <ldap_config_file>。 创建文件(如 ldapconfig.yml),并将配置详细信息放在 uiconfig: 部分中,如示例配置中所示。

要配置 LDAP 认证,您必须作出以下选择:

示例配置

uiconfig:
  instance_groups:
  - name: uaa
    jobs:
    - name: uaa
      properties:
        uaa:
          ldap:
            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
#         (Requires using the search-and-bind binding method)
            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
            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-----

这些指示信息和示例配置涵盖 LDAP 认证的最常见选项。 有关有效属性的完整列表,请参阅 BOSH uaa 作业的 uaa.ldap 属性。 有关更多详细信息,请参阅用户帐户和认证 LDAP 集成

使用 cfp-ext-ldap 扩展部署 IBM Cloud Private Cloud Foundry

  1. 向 Inception 容器推送配置文件 <ldap_config_file> 是您创建的 LDAP 配置文件的名称:

    ./cm extension -e cfp-ext-ldap save -c <ldap_config_file>
    
  2. 将扩展插入主 IBM Cloud Private Cloud Foundry 部署中。 在部署 IBM Cloud Private Cloud Foundry 组件之前,使用以下命令添加 LDAP 扩展的部署。 LDAP 扩展自动插入到状态文件中的正确位置。

    ./cm states insert -i cfp-ext-ldap
    
  3. 重置引擎:

    ./cm engine reset
    
  4. 重新启动 IBM Cloud Private Cloud Foundry 部署进程。<cf_config_file> 是 IBM Cloud Private Cloud Foundry 部署的主要配置文件,例如 uiconfig.yml

    ./launch_deployment.sh -c <cf_config_file>
    

激活用户

如果您选择手动激活用户,那么针对需要访问 IBM Cloud Private Cloud Foundry 的每个用户,运行以下命令。<username> 是与 LDAP 配置中的 userDNPatternsearchFilter 属性匹配的 LDAP 用户标识,具体取决于您选择的绑定方法:

cf create-user <username> --origin ldap

撤销用户访问权

如果选择手动激活用户,那么您可以通过删除给定用户的帐户来撤销该用户的访问权:

cf delete-user <username>

否则,除了使用 cf CLI 删除用户,要撤销用户访问权,必须从 LDAP 中除去该用户,或其组成员资格更改以使他们不再符合由您的 LDAP 绑定配置定义的条件。

将用户分配给组织和空间

无法为 LDAP 用户自动授予对特定组织或空间的访问权,但是通过先使用 cf create-user <username> --origin ldap 命令激活用户,然后像平常一样分配组织和空间角色,您可以在首次登录前授予许可权。 有关更多信息,请参阅管理用户对组织和空间的许可权。 如果有大量 LDAP 用户根据其 LDAP 记录要分配到特定组织和空间,那么可以使这些操作脚本化。

将 LDAP 组映射到范围

如果选择使用 groups-map-to-scopes 根据组成员资格自动将额外权限范围分配给 LDAP 用户,那么您可以使用 uaac CLI 来管理这些映射。

  1. 通过使用以下命令,安装 uaac Ruby gem:
    gem install cf-uaac
    
  2. 将 UAA 服务器作为安装的目标。 将 <bluemix_env_domain> 替换为用于安装的环境域。 如果您的环境域证书是自签名的,将 --skip-ssl-validation 选项添加到该命令。
    uaac target https://uaa.<bluemix_env_domain>
    
  3. 通过在文件 <data_directory>/CloudFoundry/deployment-vars.yml 中找到 uaa_admin_client_secret 值并将其代入以下命令,使用 uaac CLI 登录:
    uaac token client get admin -s <uaa_admin_client_secret>
    

通过发出以下示例中所示的命令,您可以管理组映射:

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