如何在Kubernetes env vars中添加金库秘密?

发布于 2025-02-03 21:44:02 字数 1105 浏览 6 评论 0原文

我正在使用oauth2-proxy使用外部OIDC提供商进行身份验证的Helm图表,以及存储库来存储秘密。现在,为了将其传递client-id& client-secret存储在保险库中的秘密,我遵循此链接 - https://www.vaultproject.io/docs/platform/k8s/inject/injementor/examples/examples#environment-varible-varible-example-example-a>

这表明如何在容器中添加这些秘密, ,但是oauth2-proxy需要这些变量首先启动(它们以args的形式传递给Docker Image的入口点)。我还尝试将源命令添加到PostStart生命周期方法,但这也会给出以下错误 -

Exec lifecycle hook ([sh -c source /vault/secrets/oidc.sh]) for Container "oauth2-proxy" in Pod "oauth2-proxy-f6c8f7b69-kgjws_istio-system(7e488c12-2964-496f-a658-47739fcf3695)" failed - error: command 'sh -c source /vault/secrets/oidc.sh' exited with 126: , message: "OCI runtime exec failed: exec failed: cannot exec a container that has stopped: unknown\r\n"

我认为这是因为Docker Image的入口点需要这些Env vars,并且该容器在该命令失败。还有其他方法吗?

I am using the OAuth2-Proxy helm chart which is authenticating using an external oidc provider, along with Vault to store the secrets. Now, in order to pass it the client-id & client-secret secrets stored in Vault, I followed this link - https://www.vaultproject.io/docs/platform/k8s/injector/examples#environment-variable-example

This shows how to add these secrets as env vars in a container, but OAuth2-Proxy needs these variables to start in the first place (They are passed as args to the docker image's entrypoint). I also tried adding the source command to the postStart lifecycle method but that also gives the following error -

Exec lifecycle hook ([sh -c source /vault/secrets/oidc.sh]) for Container "oauth2-proxy" in Pod "oauth2-proxy-f6c8f7b69-kgjws_istio-system(7e488c12-2964-496f-a658-47739fcf3695)" failed - error: command 'sh -c source /vault/secrets/oidc.sh' exited with 126: , message: "OCI runtime exec failed: exec failed: cannot exec a container that has stopped: unknown\r\n"

I think this is because the docker image's entry-point requires those env vars and the container dies off as soon as that command fails. Is there any other approach for doing this?

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

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

发布评论

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

评论(1

谁与争疯 2025-02-10 21:44:02

这是一种使用 Vault Agent Injector 方法

首先,应创建一个模板,以将保险库秘密作为环境变量导出。

spec:   template:
    metadata:
      annotations:
        # Environment variable export template
        vault.hashicorp.com/agent-inject-template-config: |
          {{ with secret "secret/data/web" -}}
            export api_key="{{ .Data.data.payments_api_key }}"
          {{- end }}

并且应用程序容器应在启动过程中摘下这些文件。

args:
  ['sh', '-c', 'source /vault/secrets/config && <entrypoint script>']

Here is a way to inject vault secrets into the k8s pod as ENV vars using vault Agent Injector method

First A template should be created that exports a Vault secret as an environment variable.

spec:   template:
    metadata:
      annotations:
        # Environment variable export template
        vault.hashicorp.com/agent-inject-template-config: |
          {{ with secret "secret/data/web" -}}
            export api_key="{{ .Data.data.payments_api_key }}"
          {{- end }}

And the application container should source those files during startup.

args:
  ['sh', '-c', 'source /vault/secrets/config && <entrypoint script>']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文