question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blob SaS URL generation using existing connection string "UseDevelopmentStorage=true"

See original GitHub issue

Query/Question Is there any way to create a SaS URL for a Blob using the existing Connection String mechanism?

Environment:

  • Azure.Storage.Blobs 12.4.1

Details I am currently wiring all my storage stuff up using a single Connection String passed in to the BlobServiceClient. This is very convenient as I can use the “UseDevelopmentStorage=true” in my development appSettings.json without needing to specify all the details. My ARM deployment can then simply grab the connection string at deployment time for each environment.

However, the new way of generating SaS URLs for temporary Blob access requires me to create a new instance of StorageSharedKeyCredential and there doesn’t appear to be an automatic way of getting this from an existing instance of BlobServiceClient.

This leaves me with the choices of:

  • Parse the connection string myself (the StorageConnectionString class is marked internal) including detecting “UseDevelopmentStorage=true” manually and splitting string etc.
  • Change everything to use Account Name and Account Key (which means I have to put the development account name and key in explicitly).

Would it not be simpler to have a way of creating a SaS token using a BlobServiceClient - either directly or indirectly - which already has the credentials loaded?

Or at least expose the StorageConnectionString class so I can parse the connection string again. Otherwise I will have to add all this logic again myself.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
stpatrick2016commented, Nov 21, 2020

As a workaround and instead of parsing manually can use DbConnectionStringBuilder like this:

            var conBuilder = new DbConnectionStringBuilder();
            conBuilder.ConnectionString = MyConnectionString;
            var cred = new StorageSharedKeyCredential(conBuilder["AccountName"] as string, conBuilder["AccountKey"] as string);
5reactions
fhurtacommented, Oct 30, 2020

Hello, any progress with this issue? I also found it awkward not to be able to create the StorageSharedKeyCredential from connection string or get it from already authenticated client. Both BlobServiceClient and QueueServiceClient take connection string in the constructor. You can get AccountName but not the AccountKey from them.

It would be really helpful to have some kind of consistency in the library design. I understand it might happen but this issue was reported 4 month ago…

Read more comments on GitHub >

github_iconTop Results From Across the Web

[QUERY] How to create a SAS Uri with v12 #16979
This requires me to parse the connection string, but I don't know exactly what to do with "UseDevelopmentStorage=true". The new code is: var ......
Read more >
Use the Azure Storage Emulator for development and ...
The Microsoft Azure Storage Emulator is a tool that emulates the Azure Blob, Queue, and Table services for local development purposes.
Read more >
How to generate a SAS connection string using .NET SDK
With the v12 library, I was able to get a SASUri for a particular blob ... GenerateSasUri(blobSasBuilder); var blobClientWithSasUri = new ...
Read more >
Configure a connection string - Azure Storage
Navigate to Security + networking > Access keys in your storage account's settings to see connection strings for both primary and secondary ...
Read more >
Uploading Files to Azure Blob Storage with Shared Access ...
Shared Access Signature (SAS) provides a secure way to upload and download files from Azure Blob Storage without sharing the connection string.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found