我有一个 Xamarin.Forms 应用程序。我需要 Azure 存储来存储一些数据。显然,我不想在我的应用程序中存储共享访问签名 (SAS)。
在我的应用程序中,我开发了一个
KeyVaultService
:
private readonly Azure.Security.KeyVault.Secrets.SecretClient _keyVaultSecretClient;
public KeyVaultService()
=> _keyVaultSecretClient = new(
new Uri("https://foo.vault.azure.net/"),
new DefaultCredential());
// ...
public async Task<string> GetSecretAsync(string secretName)
{
// ...
var response = await _keyVaultSecretClient.GetSecretAsync(secretName);
// ...
return response.Value.Value;
}
A
AzureStorageService
:
private readonly IKeyVaultService _keyVaultService;
public AzureStorageService() => _keyVaultService = DependencyService.Get<IKeyVaultService>();
public async Task<byte[]> GetFooAsync()
{
var connectionString = await _keyVaultService.GetSecretAsync(STORAGE_CONNECTIONSTRING);
_blobContainerClient = new BlobContainerClient(connectionString, CONTAINER_NAME);
}
它的名字是这样的:
byte[]? fooBytes = await _azureStorageService.GetFooAsync();
await DoSomething(fooBytes);
SecretClient
的第二个参数是Azure.Identity.TokenCredential
派生类。对于我的 _keyVaultSecretClient
实例,在我的 KeyVaultService
中,我尝试使用一些类(DefaultAzureCredential
,ClientSecretCredential
,...):
DefaultAzureCredential
和 ClientSecretCredential
public KeyVaultService() => new(new Uri("foo...."), new DefaultAzureCredential())
和
public KeyVaultService() => new(new Uri("foo...."), new ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET))
抛出异常:
Azure.Identity.AuthenticationFailedException:
'ClientSecretCredential authentication failed: Confidential Client flows are not available on mobile platforms or on Mac.See https://aka.ms/msal-net-confidential-availability for details.'
Inner Exception:
PlatformNotSupportedException: Confidential Client flows are not available on mobile platforms or on Mac.See https://aka.ms/msal-net-confidential-availability for details.
我不想在我的代码中保留租户 ID、客户端 ID 或秘密 ID
EnvironmentCredential
public KeyVaultService() => new(new Uri("foo...."), new EnvironmentCredential())
我在 Windows 上添加了 3 个环境变量:
AZURE_CLIENT_ID
、AZURE_CLIENT_SECRET
和 AZURE_TENANT_ID
。
再次抛出AuthenticationFailedException
。
public KeyVaultService() => new(new Uri("foo...."), new ManagedIdentityCredential(CLIENT_ID))
另一个异常抛出:
Azure.Identity.CredentialUnavailableException:
'ManagedIdentityCredential authentication unavailable. No Managed Identity endpoint found.'
在哪里以及如何添加
Identity endpoint
?
客户 ID 在代码中!不:(
移动应用程序 + Key Vault 不要这样做
我已阅读此博文:https://codemilltech.com/mobile-apps-azure-keyvault-dont-do-it/,但是...如果匿名用户找到了我的 Azure Function 的 url.. .他可以读取我的 Key Vault 地址...并且我的应用程序抛出相同的异常...我认为这是我的方法。
开发一个 Azure 函数来访问 Key Vault 及其秘密,然后通过 API 将它们发送回给我?哦:我所有的秘密都可能被泄露。不,谢谢。
我已阅读异常提供的链接 (https://aka.ms/msal-net-confidential-availability)。 MSAL?为什么选择 Azure?据我了解,MSAL 允许连接到 Microsoft Graph 和 Office 365 API...
我知道我的方法不适用于移动平台(例外情况是不言自明的,足以猜测,我保证)-因为手机不是完全安全的设备?
所以, 使用 Azure Key Vault 或其他解决方案安全访问我的 Azure 存储的实现是什么?
事实上,
有人有主意吗?
提前致谢:-)
我有同样的要求吗?有没有人找到解决办法了