Databricks-我们可以为所有群集设置环境变量/使用init脚本中的秘密范围

发布于 2025-01-25 02:21:55 字数 361 浏览 2 评论 0 原文

我想在INIT脚本中使用Databricks Secret。 我可以使用 envvar = {{/secrets/myScope/mySecret}}} 手动设置环境变量,然后在init脚本中使用envvar。但是这样做,我将不得不在每个群集和任何新群集上手动设置该环境变量,而这些变量在我的情况下都无法使用。

理想情况下,我想通过集群策略对其进行管理,但是我看不到那里可用。 我还尝试使用一个单独的初始脚本 export envvar =“ {{{secrets/myScope/mySecret}}}” 但是,当我尝试回声时,这样做不会返回,所以我认为它是失败的。

有人知道我如何实现这一目标吗?

谢谢 垫

I would like to use a databricks secret in an init script.
I can manually set an environment variable with ENVVAR={{/secrets/myscope/mysecret}} and then use ENVVAR in the init script. However doing it this way I would have to manually set that environment variable on each cluster, and any new ones, which won't work in my scenario.

Ideally I would like to manage it with cluster policies, but I don't see that being available there.
I've also tried to have a separate init script with
export ENVVAR="{{secrets/myscope/mysecret}}"
But doing this when I try to echo that ENVVAR it returns nothing so I assume it is failing.

Does anyone have an idea on how I can achieve this?

Thanks
Mat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月蹉跎了容颜 2025-02-01 02:21:55

您通过使用初始脚本在正确的轨道上,但是您无法使用正常导出以来,该变量仅适用于init Script subprocess。

取而代之的是,使用INIT脚本中的以下行在全球设置环境变量:

sudo echo AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE >> /etc/environment

这将写入群集的环境文件,该文件将从群集上的任何子过程中读取。

更好的方法:
甚至比在init脚本内部设置秘密的是直接在代码中使用databricks secrets api,例如:

dbutils.secrets.get(scope="myscope", key="mysecret")

https://docs.databricks.com/dev-tools/databricks-utils.html#dbutils-secrets

You were on the right track by using an init script, but you cannot use normal export since then the variable will only be available to the init script subprocess.

Instead, use the following line in an init script to set an environment variable globally:

sudo echo AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE >> /etc/environment

This will write to the environment file of the cluster, which is read from any subprocess on the cluster.

Better way:
Even better than setting the secret inside an init script is to use Databricks secrets API directly in code, e.g. like this:

dbutils.secrets.get(scope="myscope", key="mysecret")

Read more here: https://docs.databricks.com/dev-tools/databricks-utils.html#dbutils-secrets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文