Skip to content

[BUG] azure-storage-blob-nio can't copy file with SAS token creds #35340

Open
@jgainerdewar

Description

@jgainerdewar

Describe the bug
I cannot use the Azure Storage Blob NIO library to copy a file within a container when using SAS token credentials. When I try, I get the below error. I believe the NIO library needs to attach the SAS token to the source URL when performing the copy operation, since the underlying blob client copy inherits shared key creds but not SAS token.

Exception or Stack Trace
com.azure.storage.blob.models.BlobStorageException: Status code 401, "<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Please refer to the information in the www-authenticate header.

Error is being thrown from here: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-blob-nio/src/main/java/com/azure/storage/blob/nio/AzureFileSystemProvider.java#L766

To Reproduce

  • Instantiate an Azure Blob NIO filesystem with a single container, passing a container-level SAS token as credential.
  • Determine the path to a file in the container (or create a file)
  • Attempt to copy this file to another path in the container using Files.copy(src, dest, StandardCopyOption.COPY_ATTRIBUTES)

Code Snippet
Scala

val config = Map((AzureFileSystem.AZURE_STORAGE_SAS_TOKEN_CREDENTIAL, "mySAStoken"),
      (AzureFileSystem.AZURE_STORAGE_FILE_STORES, "my-container-name"),
      (AzureFileSystem.AZURE_STORAGE_SKIP_INITIAL_CONTAINER_CHECK, java.lang.Boolean.TRUE))

val fs = FileSystems.newFileSystem("azb://?endpoint=https://<my storage account>.blob.core.windows.net", config.asJava)
val srcpath = fs.getPath("my-container-name:/foo/bar/myfile.txt") # this file exists
val dstpath = fs.getPath("my-container-name:/foo/bar/myfile_again.txt") # this file does not exist
Files.copy(srcpath, dstpath, StandardCopyOption.COPY_ATTRIBUTES)

Expected behavior
I expect the file to be copied without error

Screenshots
If applicable, add screenshots to help explain your problem.
N/A

Setup (please complete the following information):

  • OS: OSX
  • IDE: IntelliJ
  • Library/Libraries: azure-storage-blob-nio:12.0.0-beta.19
  • Java version: 11
  • App Server/Environment:
  • Frameworks: Akka

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [ X] Bug Description Added
  • [ X] Repro Steps Added
  • [ X] Setup information Added

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-triageWorkflow: This issue needs the team to triage.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions