azure - 使用 MSI 从本地 Service Fabric 群集访问 Key Vault

标签 azure azure-service-fabric azure-keyvault azure-managed-identity

我想通过托管服务身份 (MSI) 从 Service Fabric 应用程序访问 Key Vault。我已在 Azure 门户中的虚拟机规模集上启用 MSI,并授予其对我的 Key Vault 资源的访问权限。这就像云端的魅力一样。但是,我的本地开发环境遇到了问题。

据我了解,我可以授予自己对 Key Vault 的访问权限并在 Azure CLI 中运行 az login。遗憾的是,当在本地 Service Fabric 群集中运行应用程序时,这不起作用。我认为这是因为本地集群在 NETWORK SERVICE 帐户下运行。

如何使用 MSI 从本地集群访问 Key Vault?

最佳答案

我假设您正在使用 Microsoft.Azure.Services.AppAuthentication library使用 MSI 获取 token 以对 Key Vault 进行身份验证,这在 Azure 上有效。如果是这样,您可以在本地开发环境中运行相同的代码。该库将自动切换为使用 Azure 上的 MSI。您可以找到文档here

Note: Local development for MSI scenarios is much easier when developing applications that run under the current user, e.g. App Services. In such cases you can use Azure CLI/ Visual Studio account for local development. You do not need to create a separate service principal. Azure CLI/ Visual Studio do not work for Service Fabric local development, since local cluster runs under Network Service account.

对于 Service Fabric 场景,请按照以下步骤操作:

  1. 创建服务主体并授予对 Key Vault 的访问权限。 你有两个选择。证书的安全性更好,但做起来稍微困难一些。

    选项 1:Create a service principal with a certificate 。确保您提供网络服务帐户或用于运行结构本地访问证书的任何帐户。 Refer for details关于如何授予访问权限。

    或者

    选项 2:Create a service principal with a password

  2. 创建一个名为“AzureServicesAuthConnectionString”的环境变量。 Refer this关于为服务结构创建环境变量。

    如果使用证书,请将“AzureServicesAuthConnectionString”设置为

    RunAs=App;AppId={AppId};TenantId={TenantId};CertificateThumbprint= {Thumbprint};CertificateStoreLocation={LocalMachine or CurrentUser}

    如果使用密码,请将“AzureServicesAuthConnectionString”设置为

    RunAs=App;AppId={AppId};TenantId={TenantId};AppKey={ClientSecret}

如果上述步骤不起作用,请发布您收到的错误。

关于azure - 使用 MSI 从本地 Service Fabric 群集访问 Key Vault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49859477/

相关文章:

reactjs - 如何指定端口在Azure Web应用程序中运行多个ReactJS应用程序?

git - 如何在没有 TreeView 的情况下查看 Azure Repos 中的分支?

Azure Application Insights - 不记录高流量情况下的所有请求

mongodb - 静态加密、MongoDB、Azure Key Vault - 无法连接到您的 AzureVault 帐户

azure - 是否可以在 Azure Pipeline Agent 上将 Azure KeyVault 与 RBAC 结合使用?

azure - QnA Maker 的元数据

Azure AD B2C - 使用电子邮件或移动设备注册/登录

c# - 服务结构错误

azure - 如何让docker融入到这个架构中呢?

azure - Renci.sshnet 未正确从 Azure Key Vault 读取 secret 私钥文件