如何访问databricks initscript中的秘密

问题描述

我尝试访问 databricks 集群的高级选项卡中的秘密 {{secrets/secrectScope/Key}},并且工作正常。但是当我尝试在 databricks init 脚本中使用它时,它不起作用。

这样做的步骤是什么?

解决方法

以下是访问 databricks initscript 中的机密的步骤:

  1. 转到集群
  2. 点击集群信息旁边的编辑
  3. 在“配置集群”页面上,点击高级选项
  4. Spark 选项卡上,输入以下 Spark 配置:

enter image description here

示例 ini 代码:

 fs.azure.account.auth.type.chepragen2.dfs.core.windows.net OAuth
 fs.azure.account.oauth.provider.type.chepragen2.dfs.core.windows.net org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider
 fs.azure.account.oauth2.client.id.chepragen2.dfs.core.windows.net {<!-- -->{secrets/KeyVaultName/ClientID}}
 fs.azure.account.oauth2.client.secret.chepragen2.dfs.core.windows.net {<!-- -->{secrets/KeyVaultName/ClientSecret}}
 fs.azure.account.oauth2.client.endpoint.chepragen2.dfs.core.windows.net https://login.microsoftonline.com/<Directory_ID>/oauth2/token

有关详细信息,请参阅 Azure Databricks - configure the cluster to read secrets from the secret scope

,

关于秘密引用(所谓的“secret paths”)的语法,另一个答案是正确的,但它不适用于 init 脚本,尽管它适用于 Spark 代码本身。

要将秘密传递给 init 脚本,您需要将秘密路径放入 Spark 配置选项卡的 "Environment Variables" sections 中,如下所示:

enter image description here

然后you can use the variable by name inside the init script

if [ -n "$SECRET_VAR" ]; then
  do_something_with_it
fi