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

Access Key Vault from local Service Fabric cluster with MSI

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

据我所知,我可以在 Azure CLI 中授予自己访问 Key Vault 和 运行 az login 的权限。唉,这在 运行 在本地 Service Fabric 集群中运行应用程序时不起作用。我假设这是因为 NETWORK SERVICE 帐户下的本地集群 运行s。

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

托管服务标识专注于 Azure 上 运行 的资源。我们没有办法支持本地开发环境。

谢谢, -阿图罗

我假设您使用的是 Microsoft.Azure.Services.AppAuthentication library to get a token using MSI to authenticate to Key Vault, and this is working on Azure. If so, you can run the same exact code on local development environment. The library will automatically switch to using MSI on Azure. You can find documentation 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 的访问权限。 你有两个选择。证书是更好的 w.r.t 安全性,但更难做到。

    选项 1:Create a service principal with a certificate. Make sure you give Network Service account or whatever account is used to run fabric locally access to the 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}

如果上述步骤不起作用,请post您得到的错误。