

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 为 LDAP 用户配置 Hue
<a name="hue-ldap"></a>

通过与 LDAP 集成，用户可以使用存储在 LDAP 目录中的现有凭证登录 Hue。将 Hue 与 LDAP 集成时，不需要在 Hue 中独立管理用户信息。以下信息演示了 Hue 与 Microsoft Active Directory 的集成，但配置选项类似于任何 LDAP 目录。

LDAP 身份验证首先需要绑定到服务器并建立连接。然后，建立的连接将用于任何后续查询，从而搜索 LDAP 用户信息。除非您的 Active Directory 服务器允许匿名连接，否则需要使用绑定可分辨名称和密码建立连接。绑定可分辨名称（DN）由 `bind_dn` 配置设置定义。绑定密码由 `bind_password` 配置设置定义。Hue 有两种绑定 LDAP 请求的方法：搜索绑定和直接绑定。将 Hue 与 Amazon EMR 一起使用的首选方法是搜索绑定。

在 Active Directory 中使用搜索绑定时，Hue 会通过用户名属性（由 `user_name_attr config` 定义）来查找需要从基本可分辨名称（或 DN）中检索的属性。当 Hue 用户不知道完整 DN 时，搜索绑定非常有用。

例如，您可能已将 `user_name_attr config` 设置为使用通用名称（CN）。在这种情况下，Active Directory 服务器使用登录期间提供的 Hue 用户名在目录树中搜索匹配的通用名称，从基本可分辨名称开始。如果找到 Hue 用户的通用名称，则服务器返回用户的可分辨名称。然后，Hue 构造一个可分辨名称，用于通过执行绑定操作对用户进行身份验证。

**注意**  
搜索绑定可搜索所有目录子树中的用户名，从基本可分辨名称开始。在 Hue LDAP 配置中指定的基本可分辨名称应该是用户名的最近父级，否则 LDAP 身份验证性能可能会受到影响。

在 Active Directory 中使用直接绑定时，必须使用精确的 `nt_domain` 或 `ldap_username_pattern` 进行身份验证。当使用直接绑定时，如果 nt 域（由 `nt_domain` 配置设置定义）属性已定义，则使用以下形式创建用户可分辨名称模板：`<login username>@nt_domain`。此模板用于搜索以基本可分辨名称开始的所有目录子树。如果未配置 nt 域，Hue 会为用户搜索精确的可分辨名称模式（由 `ldap_username_pattern` 配置设置定义）。在这种情况下，服务器在所有目录子树中搜索匹配的 `ldap_username_pattern` 值，从基本可分辨名称开始。

**要启动具有 Hue 的 LDAP 属性的集群，请使用 AWS CLI**
+ 要为 `hue-ini` 指定 LDAP 属性，请创建一个安装了 Hue 的集群并引用包含 LDAP 的配置属性的 json 文件。下面显示了一个示例命令，此命令引用 Amazon S3 中存储的配置文件 `myConfig.json`。

  ```
  aws emr create-cluster --release-label emr-7.12.0 --applications Name=Hue Name=Spark Name=Hive \
  --instance-type m5.xlarge --instance-count 3 --configurations https://s3.amazonaws.com/amzn-s3-demo-bucket/myfolder/myConfig.json.
  ```

  下面显示的是 `myConfig.json` 的内容示例。

  ```
  [
      {
          "Classification": "hue-ini",
          "Properties": {},
          "Configurations": [
              {
                  "Classification": "desktop",
                  "Properties": {},
                  "Configurations": [
                      {
                          "Classification": "ldap",
                          "Properties": {},
                          "Configurations": [
                              {
                                  "Classification": "ldap_servers",
                                  "Properties": {},
                                  "Configurations": [
                                      {
                                          "Classification": "yourcompany",
                                          "Properties": {
                                              "base_dn": "DC=yourcompany,DC=hue,DC=com",
                                              "ldap_url": "ldap://ldapurl",
                                              "search_bind_authentication": "true",
                                              "bind_dn": "CN=hue,CN=users,DC=yourcompany,DC=hue,DC=com",
                                              "bind_password": "password"
                                          },
                                          "Configurations": []
                                      }
                                  ]
                              }
                          ]
                      },
                      {
                          "Classification": "auth",
                          "Properties": {
                           "backend": "desktop.auth.backend.LdapBackend"
                                }
                      }
                  ]
              }
              
          ]
      }
  ]
  ```

**注意**  
对于 Amazon EMR 5.21.0 及更高版本，您可以覆盖集群配置，并为运行的集群中的每个实例组指定额外的配置分类。您可以使用 Amazon EMR 控制台、 AWS Command Line Interface (AWS CLI) 或软件开发工具包来完成此操作。 AWS 有关更多信息，请参阅[为运行的集群中的实例组提供配置](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps-running-cluster.html)。

**在 Hue 中查看 LDAP 设置**

1. 验证您是否有到 Amazon EMR 集群主节点的活动 VPN 连接或 SSH 隧道。然后，在浏览器中键入:8888 *master-public-dns* 以打开 Hue 网页界面。

1. 使用 Hue 管理员凭证登录。如果 **Did you know? (您知道吗？)** 窗口打开，单击 **Got it, prof\$1 (明白了，教授！)** 可关闭该窗口。

1. 在工具栏中，单击 **Hue** 图标。

1. 在**关于 Hue** 页面上，选择**配置**。

1. 在 **Configuration Sections and Variables (配置部分和变量)** 部分，单击 **Desktop (桌面)**。

1. 滚动到 **ldap** 部分以查看您的设置。