简体   繁体   English

具有托管身份的WebJobs存储

[英]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. 但是,您仍然需要提供AzureWebJobsDashboardAzureWebJobsStorage当您使用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.

相关问题 Hack:Azure WebJobs连接到存储模拟器 - Hack: Azure WebJobs connect to Storage Emulator 将webjobs功能公开到仪表板,无需天蓝色存储 - Expose webjobs functions to dashboard without azure storage 如何使用WebJobs处理存储队列 - How to handle the Storage Queue using the WebJobs 在Azure WebJobs中写入和读取本地存储 - Writing and Reading to Local Storage in Azure WebJobs 使用Azure webjobs和队列存储在给定时间执行 - Use Azure webjobs and queue storage to execute at a given time Azure WebJobs是否可以使用非经典存储帐户 - Can Azure WebJobs work with the non-classic storage accounts Azure WebJobs SDK是否专门用于Azure存储? - Is the Azure WebJobs SDK specifically meant for working with Azure Storage? 带有Microsoft.WindowsAzure.Storage.StorageException的Azure WebJobs FunctionIndexingException禁止403 - Azure WebJobs FunctionIndexingException with Microsoft.WindowsAzure.Storage.StorageException 403 Forbidden 通过WebJobs重新排队或删除Azure存储队列中的邮件 - Requeue or delete messages in Azure Storage Queues via WebJobs 使用 .NET Core 2 的 Azure WebJobs 因“存储帐户无效”而失败 - Azure WebJobs using .NET Core 2 failing with "Invalid storage account"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM