[英]WebJobs storage with Managed Identity
By default WebJobs requires to specify Azure Storage account using AzureWebJobsStorage connection string. 默认情况下,WebJobs要求使用AzureWebJobsStorage连接字符串指定Azure存储帐户。
But I already have access to my storage with Managed Identity: 但是我已经可以使用托管身份访问我的存储了:
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://storage.azure.com/");
StorageCredentials storageCredentials = new StorageCredentials(new TokenCredential(accessToken));
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, "mystorageaccount", "core.windows.net", true);
Can I configure WebJobs to use this cloudStorageAccount instead of AzureWebJobsStorage connection string? 是否可以将WebJobs配置为使用此cloudStorageAccount代替AzureWebJobsStorage连接字符串?
Can I configure WebJobs to use this cloudStorageAccount instead of AzureWebJobsStorage connection string?
是否可以将WebJobs配置为使用此cloudStorageAccount代替AzureWebJobsStorage连接字符串?
Yes, you could use cloudStorageAccount
to get blob account and do some operation on blobs. 是的,您可以使用
cloudStorageAccount
获取Blob帐户并对Blob进行一些操作。 However, you still need to provide AzureWebJobsDashboard
and AzureWebJobsStorage
when you use Webjob. 但是,您仍然需要提供
AzureWebJobsDashboard
和AzureWebJobsStorage
当您使用Webjob。 Because they are not only connectionstring, they are also the log path. 因为它们不仅是连接字符串,所以它们也是日志路径。
In my test, I set AzureWebJobsStorage
value with storage1
connection and in code I get storage2
account and it works. 在我的测试中,我使用
storage1
连接设置AzureWebJobsStorage
值,在代码中我获得storage2
帐户并且它可以工作。
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
string accessToken = azureServiceTokenProvider.GetAccessTokenAsync("https://storage.azure.com/").Result;
StorageCredentials storageCredentials = new StorageCredentials(new TokenCredential(accessToken));
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, "storage2", "core.windows.net", true);
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("mycontainer");
CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("hello.txt");
cloudBlockBlob.UploadTextAsync("aaaaaaaa").Wait();
For more details about assign role and get access token you could refer to this article . 有关分配角色和获取访问令牌的更多详细信息,请参阅本文 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.