gpt4 book ai didi

gcloud - 如何通过 gcloud shell 在 Cloud Run 部署中正确使用来自 Secret Manager 的 secret

转载 作者:行者123 更新时间:2023-12-05 06:03:59 25 4
gpt4 key购买 nike

我正在尝试构建一个 gcloud 脚本来部署我的云运行服务。此服务可以访问托管的 MongoDB,因此我必须通过环境变量提供密码凭据。

我想通过 secret 管理器传递此密码。我通过 GCP 控制台这样做:

enter image description here

所以 secret 名称是 mongodb-password 和值 mypassword。现在,我按照 gcloud run 文档 ( https://cloud.google.com/sdk/gcloud/reference/run/deploy ) 了解如何将 key 添加到运行服务部署中。

在设置 secret 部分解释如下:

Specify secrets to mount or provide as environment variables. Keysstarting with a forward slash '/' are mount paths. All other keyscorrespond to environment variables. The values associated with eachof these should be in the form SECRET_NAME:KEY_IN_SECRET; you may omitthe key within the secret to specify a mount of all keys within thesecret. For example:'--update-secrets=/my/path=mysecret,ENV=othersecret:key.json' willcreate a volume with secret 'mysecret' and mount that volume at'/my/path'. Because no secret key was specified, all keys in'mysecret' will be included. An environment variable named ENV willalso be created whose value is the value of 'key.json' in'othersecret'. At most one of these may be specified

这让我有些困惑。我不知道 KEY_IN_SECRET 是什么意思。 secret 名称显然是 mongodb-password 但我不知道现在如何引用 secret 的值。

我试图弄清楚是否有关于如何定义 secret 值的约定。可能类似于 key=value。但没有任何规定我必须那样做。

所以现在我想知道我应该为 gcloud run deploy 命令的 --set-secrets=[KEY=VALUE,…] 标志做什么。

根据给出的信息,我只能这样做:

--set-secrets=[mongodb-password=*]

我知道这是错误的,但我想解释一下目前让我感到困惑的是什么

最佳答案

你很困惑,这很正常。 secret 管理器集成目前仅适用于 Cloud Run on Anthos(例如,部署在 GKE 集群上)。

如果您使用完全管理版本,Cloud Run 尚不支持 secret 管理器集成(Alpha 版本应该很快开始,您可以期待在今年晚些时候公开推出)。

所以你需要直接在你的代码中获取你的 secret 。或者,我创建了一个包装器来帮助您 load the secret from secret manager and to set them in environment variable .


在 GKE 中, secret 在 Kubernetes secrets documentation 中描述。 .您可以在 linux 目录树 /path/to/mysecret 的路径中挂载 secret 。这是一个最佳实践,它应该与完全管理版本相同(以确保可移植性和 Knative 合规性)。

这就是为什么你可以在文档中这样写 --update-secrets=/my/path=mysecret

关于gcloud - 如何通过 gcloud shell 在 Cloud Run 部署中正确使用来自 Secret Manager 的 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66489202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com