Description
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