Search code examples
azureazure-storageazure-webjobs

Azure SAS Token for Webjob DashboardConnectionString and StorageConnectionString


Azure web jobs want me to set AzureWebJobsDashboard and AzureWebJobsStorage properties on startup but, i do not want to expose AccountKey in code. When I try to use SAS Token, JobHostConfiguration class trying to parse SAS Token and throws exception

 var config = new JobHostConfiguration();
            config.DashboardConnectionString = ConfigurationManager.GetSetting(KeyVaultSecrets.StorageReadWriteConnectionString);
            config.StorageConnectionString = ConfigurationManager.GetSetting(KeyVaultSecrets.StorageReadWriteConnectionString);

Exception

System.InvalidOperationException occurred HResult=0x80131509 Message=Failed to validate Microsoft Azure WebJobs SDK Dashboard connection string. The Microsoft Azure Storage account connection string is not formatted correctly. Please visit http://msdn.microsoft.com/en-us/library/windowsazure/ee758697.aspx for details about configuring Microsoft Azure Storage connection strings. Source= StackTrace: at Microsoft.Azure.WebJobs.Host.Executors.StorageAccountParser.ParseAccount(String connectionString, String connectionStringName, IServiceProvider services) at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.set_DashboardConnectionString(String value)

Is there any way to use SAS Token while creating configuration for JobHostConfiguration?


Solution

  • We can use the SAS in a connection string. Because the SAS contains the information required to authenticate the request, a connection string with a SAS provides the protocol, the service endpoint, and the necessary credentials to access the resource according to that link

    In this way, StorageAccountParser.ParseAccount(String connectionString) can parse the connection string

    BlobEndpoint=https://storagesample.blob.core.windows.net; SharedAccessSignature=sv=2015-04-05&sr=b&si=tutorial-policy-635959936145100803&sig=9aCzs76n0E7y5BpEi2GvsSv433BZa22leDOZXX%2BXXIU%3D