Azurite icon indicating copy to clipboard operation
Azurite copied to clipboard

userdelegationkey feature

Open estet opened this issue 6 years ago • 14 comments

image mcr.microsoft.com/azure-storage/azurite:3.7.0

POST to /devstoreaccount1?restype=service&comp=userdelegationkey HTTP/1.1

Exception: Azure.RequestFailedException: 'Current API is not implemented yet. Please vote your wanted features to https://github.com/azure/azurite/issues RequestId:7fc4bfc5-db34-49c9-b183-a96d14c8d64a Time:2020-04-23T10:40:02.610Z Status: 500 (Current API is not implemented yet. Please vote your wanted features to https://github.com/azure/azurite/issues) ErrorCode: APINotImplemented

Headers: Server: Azurite-Blob/3.7.0 x-ms-error-code: APINotImplemented x-ms-request-id: 7fc4bfc5-db34-49c9-b183-a96d14c8d64a Date: Thu, 23 Apr 2020 10:40:02 GMT Connection: keep-alive Transfer-Encoding: chunked Content-Type: application/xml

estet avatar Apr 23 '20 12:04 estet

@estet Thanks for the raise the feature request! We will track this feature with other new features.

blueww avatar Apr 27 '20 02:04 blueww

@blueww Hi We are trying to use the batchdelete function and ended up in (azurite 3.15)

Current API is not implemented yet. Please vote your wanted features to https://github.com/azure/azurite/issues
RequestId:9a932926-a7b1-49aa-8c3e-4388844aa170
Time:2022-02-14T15:44:31.712Z
Status: 500 (Current API is not implemented yet. Please vote your wanted features to https://github.com/azure/azurite/issues)
ErrorCode: APINotImplemented

Content:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Error>
  <Code>APINotImplemented</Code>
  <Message>Current API is not implemented yet. Please vote your wanted features to https://github.com/azure/azurite/issues
RequestId:9a932926-a7b1-49aa-8c3e-4388844aa170
Time:2022-02-14T15:44:31.712Z</Message>
</Error>

Headers:
Server: Azurite-Blob/3.15.0
x-ms-error-code: APINotImplemented
x-ms-request-id: 9a932926-a7b1-49aa-8c3e-4388844aa170
Date: Mon, 14 Feb 2022 15:44:31 GMT
Connection: keep-alive
Keep-Alive: REDACTED
Transfer-Encoding: chunked
Content-Type: application/xml

chatchathu199162 avatar Feb 14 '22 15:02 chatchathu199162

@chatchathu199162 Delegation SAS is still not supported. It's listed in "features or REST APIs are NOT supported or limited supported" in https://github.com/Azure/Azurite#support-matrix

Azurite welcome contribution. It would be great if you can raise a PR to implement this in Azurite!

  • The get Delegation key API interface is: https://github.com/Azure/Azurite/blob/29395175764fc1feaa6ca8fac661c6fb7995def5/src/blob/handlers/ServiceHandler.ts#L62

  • The blob SAS validation logic is in: https://github.com/Azure/Azurite/blob/main/src/blob/authentication/BlobSASAuthenticator.ts

blueww avatar Feb 15 '22 02:02 blueww

I am still not able to use the getUserDelegationKey in my Java application, I get an internal sever error. Is the feature not yet implemented?

mynameisheisenberg avatar Nov 07 '22 10:11 mynameisheisenberg

@mynameisheisenberg This feature is still not in Azurite. We are working on it. Will update later.

blueww avatar Nov 08 '22 03:11 blueww

The feature is already released in https://github.com/Azure/Azurite/releases/tag/v3.21.0

blueww avatar Jan 09 '23 08:01 blueww

Can confirm that this now works, thank you :D

kaylumah avatar Jan 09 '23 14:01 kaylumah

I am using Azurite 3.22(runned in Docker) and C# Azure Storage SDK. When I tried to get the user's delegation key, I got a 400 Bad Request response. Do I have to do some manipulation with any configuration to use the user delegation key feature? Has anyone tried getting user delegation key using C# Azure Storage SDK?

MooWeek avatar Feb 22 '23 09:02 MooWeek

@mooweek I have it working with the C# SDK. Can you share how you are using the SDK?

kaylumah avatar Feb 22 '23 14:02 kaylumah

@MooWeek I have it working with the C# SDK. Can you share how you are using the SDK?

Connect AzureClient

services.AddAzureClients(builder =>
            { builder.AddBlobServiceClient(new Uri(https://localhost:10000/devstoreaccount1/))
                         .WithCredential(credential).WithName("BlobUpload");

credential =

new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
    ExcludeVisualStudioCredential = true,
    ExcludeVisualStudioCodeCredential = true,
    ExcludeInteractiveBrowserCredential = true,
    ExcludeSharedTokenCacheCredential = true
});

then trying to get UserDelegationKey await _blobServiceClient.GetUserDelegationKeyAsync(startsOn: null, expiresOn); Using debuggin find out that in Azure.Core.Pipeline.HttpPipeline.SendAsync()

public ValueTask SendAsync(HttpMessage message, CancellationToken cancellationToken)
        {
            message.CancellationToken = cancellationToken;
            message.ProcessingStartTime = DateTimeOffset.UtcNow;
            AddHttpMessageProperties(message);

            if (message.Policies == null || message.Policies.Count == 0)
            {
                return _pipeline.Span[0].ProcessAsync(message, _pipeline.Slice(1));
            }

            return SendAsync(message);
        }

condition if (message.Policies == null || message.Policies.Count == 0) always true, and never enters SendAsync(message) and after that getting "error 400 Bad Request"

MooWeek avatar Feb 22 '23 15:02 MooWeek

One difference I spot with my code is that you put startsOn on null can you try to change that to DateTimeOffset.UtcNow and see if it helps resolve your issue?

kaylumah avatar Feb 24 '23 07:02 kaylumah

The Start and Expiry are required in API get-user-delegation-key: https://learn.microsoft.com/en-us/rest/api/storageservices/get-user-delegation-key#request-body

blueww avatar Feb 24 '23 08:02 blueww

Now it works! Thank`s a lot

MooWeek avatar Feb 28 '23 16:02 MooWeek

FWIW the java sdk docs state that a null start parameter means an immediate start: https://learn.microsoft.com/en-us/java/api/com.azure.storage.blob.blobserviceclient?view=azure-java-stable#com-azure-storage-blob-blobserviceclient-getuserdelegationkey(java-time-offsetdatetime-java-time-offsetdatetime)

However, thanks to this thread, I found that I need to set a non-null start when working with Azurite.

lmsurpre avatar Nov 07 '23 05:11 lmsurpre