共用方式為


auth 命令群組

注意

此資訊適用於 Databricks CLI 0.205 版和更新版本。 Databricks CLI 處於 公開預覽狀態

Databricks CLI 使用受限於 Databricks 授權Databricks 隱私權注意事項,包括任何使用量數據布建。

auth 內的 命令群組可讓您:

  • 列出任何可用的驗證組態配置檔。
  • 取得單一驗證組態配置檔的資訊。
  • 使用 OAuth 使用者對機器 (U2M) 驗證,向 Azure Databricks 帳戶和工作區驗證 Databricks CLI。
  • 取得有關 Databricks CLI 可能已快取的任何 OAuth 存取令牌的資訊。
  • 取得 Databricks CLI 用來驗證之設定的詳細數據。

您可以將 auth 命令附加至 databricks auth 來執行這些命令。 若要顯示 auth 命令的說明,請執行 databricks auth -h

列出組態配置檔

若要取得所有可用組態配置檔的清單,並檢查它們是否有效,請執行 auth profiles 命令,如下所示:

databricks auth profiles

輸出 (為了簡潔起見,省略符號代表省略的內容):

Name            Host                Valid
DEFAULT         https://<host-url>  YES
<profile-name>  https://<host-url>  NO

若要判斷每個配置檔是否有效,Databricks CLI 會針對每個帳戶層級配置檔執行清單工作區命令,並針對每個工作區層級配置檔執行取得目前的使用者命令。 如果指令成功,則會顯示 YES,否則會顯示 NO

auth profiles 命令的輸出不會顯示任何存取權杖。 若要顯示存取令牌,請參閱 取得組態設定檔的相關資訊

根據預設,組態設定檔在 Linux 或 macOS 會儲存在檔案 ~/.databrickscfg 中,在 Windows 上會儲存在檔案 %USERPROFILE%\.databrickscfg 中。 您可以藉由設定環境變數 DATABRICKS_CONFIG_FILE 來變更此檔案的預設路徑。 若要瞭解如何設定環境變數,請參閱作業系統的檔。

若要建立組態設定檔,請參閱設定命令群組

取得組態檔案的相關資訊

若要取得現有組態配置檔的相關信息,請執行 auth env 命令,其中 <profile-name> 代表配置檔的名稱,<account-or-workspace-url> 代表 Azure Databricks 帳戶控制台 URL 或 Azure Databricks 工作區 URL,如下所示:

databricks auth env --profile <profile-name>

# Or:
databricks auth env --host <account-or-workspace-url>

提示

您可以在 --profile-p 之後按 Tab,以顯示現有可用組態配置檔的清單,以便從中選擇,而不是手動輸入組態配置檔名稱。

例如,以下是使用 Azure Databricks 存取權杖驗證設定之設定檔的輸出:

{
  "env": {
    "DATABRICKS_AUTH_TYPE": "pat",
    "DATABRICKS_CONFIG_PROFILE": "<profile-name>",
    "DATABRICKS_HOST": "<workspace-url>",
    "DATABRICKS_TOKEN": "<token-value>"
  }
}

注意

如果有多個設定檔符合 --host 值,就會顯示錯誤,指出找不到單一符合的設定檔。 例如,您可能有一個設定檔只有主機值,另一個設定檔具有相同主機值,但也有權杖值。 在此情況下,Databricks CLI 不會選擇設定檔,並且會停止。 要協助 Databricks CLI 選擇所需的設定檔,請嘗試指定不同的 --host 值。 針對帳戶主控台 URL 的 --host 值,請嘗試指定 --account-id 值,而不是 --host 值。

若要建立組態設定檔,請參閱設定命令群組

使用 OAuth 進行驗證

您可以使用 OAuth 使用者對機器 (U2M) 驗證,而不是使用存取權杖和組態設定檔向 Azure Databricks 進行驗證。 OAuth 提供比 Azure Databricks 個人存取權杖更快的到期時間,並提供更好的伺服器端工作階段失效和範圍界定。 由於 OAuth 存取權杖會在不到一小時內到期,因此可降低不小心將權杖簽入原始檔控制的風險。 請參閱使用 OAuth (OAuth U2M) 透過使用者帳戶對 Azure Databricks 的存取進行驗證

若要設定及設定 OAuth U2M 驗證,請參閱 OAuth 使用者對計算機 (U2M) 驗證

取得 OAuth 存取令牌詳細數據

如果您想要查看先前針對 Azure Databricks 工作區產生的 Databricks CLI 所快取 OAuth 存取令牌的相關信息,請執行 auth token 命令,其中 <workspace-url> 代表 Azure Databricks 工作區的 URL,如下所示:

databricks auth token <workspace-url>

輸出:

{
  "access_token": "<token-value>",
  "token_type": "Bearer",
  "expiry": "<token-expiration-date-time>"
}

取得驗證詳細數據

若要取得 Databricks CLI 用來驗證之設定的詳細數據,請執行 auth describe 命令。

如果未指定任何選項,auth describe 命令會遵循用戶端統一驗證的預設方法

databricks auth describe

輸出:

Host: https://<workspace-instance-name>
User: <user-name>@<domain>
Authenticated with: <authentication-type>
-----
Current configuration:
  ✓ host: https://<workspace-instance-name> (from <path>/<to>/.databrickscfg config file)
  ✓ profile: default
  ✓ auth_type: <authentication-type> (from <path>/<to>/.databrickscfg config file)

若要指定使用特定 Azure Databricks 工作區的相關資訊,請指定 --host 選項以及工作區的 URL。

databricks auth describe --host https://<workspace-instance-name>

輸出:

Host: https://<workspace-instance-name>
User: <user-name>@<domain>
Authenticated with: <authentication-type>
-----
Current configuration:
  ✓ host: https://<workspace-instance-name> (from --host flag)
  ✓ profile: default
  ✓ auth_type: <authentication-type>

若要指定使用特定 Azure Databricks 帳戶的相關資訊,請指定 --host 選項以及 Azure Databricks 帳戶主控台 URL https://accounts.azuredatabricks.net

databricks auth describe --host <account-console-url>

輸出:

Host: <account-console-url>
User: <user-name>@<domain>
AccountId: <account-id>
Authenticated with: <authentication-type>
-----
Current configuration:
  ✓ host: <account-console-url> (from --host flag)
  ✓ account_id: <account-id>
  ✓ profile: default
  ✓ auth_type: <authentication-type>

若要指定使用特定 Azure Databricks 組態設定檔的相關資訊,請指定 -p--profile 選項以及設定檔的名稱。

databricks auth describe -p <profile-name>

輸出:

Host: https://<workspace-instance-name>
User: <user-name>@<domain>
Authenticated with: <authentication-type>
-----
Current configuration:
  ✓ host: https://<workspace-instance-name> (from <path>/<to>/.databrickscfg config file)
  ✓ token: ******** (from <path>/<to>/.databrickscfg config file)
  ✓ profile: <profile-name> (from --profile flag)
  ✓ auth_type: <authentication-type>

若要在輸出中包含敏感性資訊 (例如 Azure Databricks 個人存取權杖和用戶端密碼),請指定 --sensitive 選項。

databricks auth describe --sensitive

輸出:

Host: https://<workspace-instance-name>
User: <user-name>@<domain>
Authenticated with: pat
-----
Current configuration:
  ✓ host: https://<workspace-instance-name> (from <path>/<to>/.databrickscfg config file)
  ✓ token: <token-value> (from <path>/<to>/.databrickscfg config file)
  ✓ profile: <profile-name>
  ✓ auth_type: pat