需要有关将机密更新到 KeyVault 的建议

Need recommendation on updating secrets to KeyVault

我正在部署调用后端 api 的 Azure 函数应用程序,它由 API 密钥保护。该应用程序将使用 Azure DevOps 管道进行部署; API 密钥将作为秘密存储在 KeyVault 中,我使用 Bicep 文件进行基础设施定义,使用 Yaml 管道部署基础设施和应用程序。以下是我 w.r.t 的问题。 KeyVault 更新,

  1. 管道是否应该负责更新 KeyVault 中的机密?如果是这样,是否建议在 DevOps 变量组中维护 Secrets(pad 锁定),或者是否有 better/more 安全方法?
  2. KeyVault 中的机密是否应该手动 updated/maintained?采用这种方法,我们的管道将不太成熟,因为仍然需要手动 intervention/not-immutable - 考虑到环境的重建。

我想知道上面的最佳实践,谢谢。

可能答案是这取决于。这使得这个问题可能会得到一些基于意见的答案。如果您查看 Microsoft 文档,它指出:

Don't set secret variables in your YAML file. Operating systems often log commands for the processes that they run, and you wouldn't want the log to include a secret that you passed in as an input. Use the script's environment or map the variable within the variables block to pass secrets to your pipeline.

You need to set secret variables in the pipeline settings UI for your pipeline. These variables are scoped to the pipeline in which you set them. You can also set secret variables in variable groups.

来源:Define variables - Set secret variables

尽管如此,您还是应该问问自己,这些秘密的所有权 在哪里。所有者应该是负责人。

  • 在 KeyVault 中维护这些机密意味着您甚至不需要管道中的机密。这意味着责任的明确分离。
  • 在您的管道中维护这些秘密使您能够将它们与使用它们的代码一起更新。这将秘密与消费代码联系起来。

两者都是很好的方案,具体取决于责任所在。