

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 針對 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 SDK 來執行此操作。如需詳細資訊，請參閱[為執行中叢集的執行個體群組提供組態](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps-running-cluster.html)。

**檢視 Hue 中的 LDAP 設定**

1. 確認您有與 Amazon EMR 叢集主節點連接的作用中 VPN 連線或 SSH 通道。然後在您的瀏覽器中輸入 *master-public-dns*:8888，以開啟 Hue Web 界面。

1. 使用 Hue 管理員登入資料登入。如果 **Did you know? (您知道嗎？)** 視窗開啟，請按一下 **Got it, prof\$1 (教授，我懂了！)** 來關閉該視窗。

1. 按一下工具列中的 **Hue (Hue)** 圖示。

1. 在**關於 Hue** 頁面上，選取**組態**。

1. 在 **Configuration Sections and Variables (組態區段與變數)** 區段中，按一下 **Desktop (桌面)**。

1. 捲動至 **ldap (ldap)** 區段，以檢視您的設定。