Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.25k stars 4.58k forks source link

[QUERY] 401 - NoAuthenticationInformation using TransferManager.StartTransferAsync #45589

Open MCMaxD opened 3 weeks ago

MCMaxD commented 3 weeks ago

Library name and version

Azure.Storage.DataMovement 12.0.0-beta.5

Query/Question

Hi there,

I'm not sure if this is a bug or if I'm missing something but, I try to use the TransferManager.StartTransferAsync to copy an existing ShareFile (File shares storage) to a new BlockBlob (Blob container) and I get a 401 - NoAuthenticationInformation error.

    public async Task CopyFileToBlob(string fileUri, string blobUri)
    {
        var files = new ShareFilesStorageResourceProvider(new StorageSharedKeyCredential(_storageAccountName, _storageAccountKey));
        var blobs = new BlobsStorageResourceProvider(new StorageSharedKeyCredential(_storageAccountName, _storageAccountKey));

        var source = files.FromFile(fileUri);
        var dest = blobs.FromBlob(blobUri);

        var transferManager = new TransferManager();

        var dataTransferOptions = new DataTransferOptions { CreationPreference = StorageResourceCreationPreference.OverwriteIfExists };
        dataTransferOptions.ItemTransferFailed += DataTransferOption_ItemTransferFailed;

        var dataTransfer = await transferManager.StartTransferAsync(source, dest, dataTransferOptions);

        await dataTransfer.WaitForCompletionAsync();

        if (!dataTransfer.TransferStatus.HasCompletedSuccessfully)
            throw new Exception($"The file wasn't copied to the blob storage.");
    }

    private Task DataTransferOption_ItemTransferFailed(TransferItemFailedEventArgs e)
    {
        var test = $"Exception occured with TransferId: {e.TransferId}," +
        $"Source Resource: {e.SourceResource.Uri}, +" +
        $"Destination Resource: {e.DestinationResource.Uri}," +
        $"Exception Message: {e.Exception.Message}";

        return Task.CompletedTask;
    }

The error code I receive is

Exception occured with TransferId: 91c326fa-a684-47be-a12a-ebf06d5cc071, Source Resource: https://xyz.file.core.windows.net/qwerty/data/source.tst, +Destination Resource: https://xyz.blob.core.windows.net/qwerty/dest.tst, Exception Message: Server failed to authenticate the request. Please refer to the information in the www-authenticate header. RequestId:0c214242-001e-0011-6358-f20b36000000 Time:2024-08-19T16:58:12.4645982Z Status: 401 (Server failed to authenticate the request. Please refer to the information in the www-authenticate header.) ErrorCode: CannotVerifyCopySource

Additional Information: CopySourceStatusCode: 401 CopySourceErrorCode: NoAuthenticationInformation CopySourceErrorMessage: Server failed to authenticate the request. Please refer to the information in the www-authenticate header.

Content: <?xml version="1.0" encoding="utf-8"?>CannotVerifyCopySourceServer failed to authenticate the request. Please refer to the information in the www-authenticate header. RequestId:0c214242-001e-0011-6358-f20b36000000 Time:2024-08-19T16:58:12.4645982Z401NoAuthenticationInformationServer failed to authenticate the request. Please refer to the information in the www-authenticate header.

Headers: x-ms-request-id: 0c214242-001e-0011-6358-f20b36000000 x-ms-client-request-id: 26997bec-543e-4ef2-8935-1b60e508b762 x-ms-version: 2024-08-04 x-ms-copy-source-status-code: 401 x-ms-copy-source-error-code: NoAuthenticationInformation x-ms-error-code: CannotVerifyCopySource Content-Length: 570 Content-Type: application/xml Date: Mon, 19 Aug 2024 16:58:11 GMT Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0

I'm sure that my _storageAccountName and _storageAccountKey are configured correctly, because I'm able to access the File Shares and upload a file using the TransferManager using the same values.

Any advice on how to copy an existing File to a new Blob ?

Thanks!

Maxime.

Environment

No response

github-actions[bot] commented 3 weeks ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

amnguye commented 3 weeks ago

Looks like an authorization error in an attempt to access the source blob. It might be related to the fact that when copying from blob to share file, Shared Key cannot be used for authorization.

You can try using SAS or Entra ID in order to authenticate. We recommend using Entra ID over Shared Key in general because it is more secure.