[BUG] Blob storage service/container/blob clients drop account name for emulator connection string with custom domain name and port number
See original GitHub issueDescribe the bug
Give the following connection string:
AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10010/devstoreaccount1;
BlobServiceClient
is constructed incorrectly, with missing AccountName
As a result of that, the subsequent BlobContainerClient
and BlobClient
created from the service client, are also malformed.
var serviceClient = new BlobServiceClient(connectionString);
var containerClient = serviceClient.GetBlobContainerClient("containername");
var blobClient = containerClient.GetBlobClient("abc.txt");
results in
and
The missing AccountName
is causing the blob URI to be malformed: http://host.docker.internal:10010/devstoreaccount1/abc.txt
, resulting in blob operations failing.
Expected behavior
BlobClient
should have account name should be detected properly (known emulator account name), preserved and blob operations succeed.
Actual behavior (include Exception or Stack Trace)
To Reproduce
[Fact]
public void Use_custom_host_name_and_port_for_emulator()
{
var connectionString = string.Format("AccountName={0};AccountKey={1};BlobEndpoint={2};",
"devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "http://host.docker.internal:10010/devstoreaccount1");
var containerName = "containername";
var blobName = "abc.txt";
var serviceClient = new BlobServiceClient(connectionString);
var containerClient = serviceClient.GetBlobContainerClient(containerName); //new BlobContainerClient(connectionString, containerName);
var blobClient = containerClient.GetBlobClient(blobName);
Assert.Equal(10_010, blobClient.Uri.Port);
Assert.Equal("devstoreaccount1", blobClient.AccountName); // ❌ ""
Assert.Equal("containername", blobClient.BlobContainerName); // ❌ "devstoreaccount1"
Assert.Equal("abc.txt", blobClient.Name); // ❌ "containername/abc.txt"
}
Environment:
- Name and version of the Library package used: Azure.Storage.Blobs 12.x
- Windows 10
- .NET Core 3.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top GitHub Comments
Hi,
We also encounter the same issue with the default connection string given by Azurite:
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
From what I can see, the logic is failing in the following callStack:
extractConnectionStringParts(connectionString) getAccountNameFromUrl(blobEndpoint) isIpEndpointStyle(parsedUrl)
In this later function, there is an exception for localhost, but not for host.docker.internal:
Changing the regex to
/^.*:.*:.*$|^(localhost|host.docker.internal)(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/
solves our issue.OR better yet, in
extractConnectionStringParts(connectionString)
, we could check if there is an AccountName before checking from the URL:original:
suggestion:
Hi @SeanFeldman. Happy to offer what context I can. In this case, my contribution is purely procedural. Any issue tagged with
bug
orfeature
is required to have a milestone associated with it. Issues are also required to have only one ofbug
,feature
, andquestion
. Weekly, validation takes place and generates a report listing issues in an invalid state.Once the
bug
label was added, the issue started failing validation and alerting the triage team. Sincebug
was added by the team that owns the issue, it was given precedence andquestion
was removed. By default issues with no milestone are shifted tobacklog
until the team that owns them decides to schedule them. Each team has a different process for triage and scheduling, so with respect to how this will be prioritized and scheduled by the Storage team, I’ll need to defer to @kasobol-msft.