GCP Google 云平台 - 云 运行 - .NET 5.0 - 来自秘密或转换的应用程序设置 appsettings.json
GCP Google Cloud Platform - Cloud Run - .NET 5.0 - Application settings from secrets or transform appsettings.json
使用 Azure App Service
我可以编辑 Configuration
并从 Key vault
中读取一个值并将其设置为来自 appsettings.json
的 ConnectionStrings:DefaultConnection
,如下所示:
@Microsoft.KeyVault(VaultName=My-KeyVault;SecretName=Db-Connection)
这非常有效,数据库连接字符串和其他秘密都得到了保护。
我想做与 GCP Cloud Run
类似的事情。
我按照本指南启动了一个应用程序,运行 它运行良好:
https://cloud.google.com/blog/topics/developers-practitioners/net-50-google-cloud
然后它变得有点棘手。我一直在阅读 Preview — Support for Secret Manager secrets in Cloud Run
https://cloud.google.com/run/docs/configuring/secrets
我最初的想法是简单地用一个秘密文件替换 appsettings.json
。这是最好的方法还是有其他更好的选择?
是的,目前,Secret Manager
到 Google Cloud Console 和客户端库是您管理机密的最佳选择。您可以访问 Secret Manager 机密并将它们公开为 环境变量 或通过云 运行 服务中的 文件系统。
确保你 Configure Secret Manager first before you can create, access and manage secrets.
正如@RobertG 所说然后@Dondi 编辑的那样,使用环境变量。
使用 ConnectionStrings:DefaultConnection
作为环境变量并像这样从 Secret Manager 获取值:
使用 Azure App Service
我可以编辑 Configuration
并从 Key vault
中读取一个值并将其设置为来自 appsettings.json
的 ConnectionStrings:DefaultConnection
,如下所示:
@Microsoft.KeyVault(VaultName=My-KeyVault;SecretName=Db-Connection)
这非常有效,数据库连接字符串和其他秘密都得到了保护。
我想做与 GCP Cloud Run
类似的事情。
我按照本指南启动了一个应用程序,运行 它运行良好:
https://cloud.google.com/blog/topics/developers-practitioners/net-50-google-cloud
然后它变得有点棘手。我一直在阅读 Preview — Support for Secret Manager secrets in Cloud Run
https://cloud.google.com/run/docs/configuring/secrets
我最初的想法是简单地用一个秘密文件替换 appsettings.json
。这是最好的方法还是有其他更好的选择?
是的,目前,Secret Manager
到 Google Cloud Console 和客户端库是您管理机密的最佳选择。您可以访问 Secret Manager 机密并将它们公开为 环境变量 或通过云 运行 服务中的 文件系统。
确保你 Configure Secret Manager first before you can create, access and manage secrets.
正如@RobertG 所说然后@Dondi 编辑的那样,使用环境变量。
使用 ConnectionStrings:DefaultConnection
作为环境变量并像这样从 Secret Manager 获取值: