Skip to content

Commit db17374

Browse files
[Supportability] Improve error message when performing uploads with a missing SAS token (#2644)
* initial changes for sas supportability * addressing comments --------- Co-authored-by: Gauri Lamunion <51212198+gapra-msft@users.noreply.github.com>
1 parent 8554594 commit db17374

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

cmd/credentialUtil.go

+3
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ func logAuthType(ct common.CredentialType, location common.Location, isSource bo
345345
name = "Azure AD (Managed Disk)"
346346
}
347347
message := fmt.Sprintf("Authenticating to %s using %s", resource, name)
348+
if ct == common.ECredentialType.Unknown() && location.IsAzure() {
349+
message += ", Please authenticate using Microsoft Entra ID (https://aka.ms/AzCopy/AuthZ), use AzCopy login, or append a SAS token to your Azure URL."
350+
}
348351
if _, exists := authMessagesAlreadyLogged.Load(message); !exists {
349352
authMessagesAlreadyLogged.Store(message, struct{}{}) // dedup because source is auth'd by both enumerator and STE
350353
if jobsAdmin.JobsAdmin != nil {

common/fe-ste-models.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ func (l Location) IsLocal() bool {
553553
}
554554
}
555555

556+
// IsAzure checks if location is Azure (BlobFS, Blob, File)
557+
func (l Location) IsAzure() bool {
558+
return l == ELocation.BlobFS() || l == ELocation.Blob() || l == ELocation.File()
559+
}
560+
556561
// IsFolderAware returns true if the location has real folders (e.g. there's such a thing as an empty folder,
557562
// and folders may have properties). Folders are only virtual, and so not real, in Blob Storage.
558563
func (l Location) IsFolderAware() bool {
@@ -931,7 +936,7 @@ func (CredentialType) MDOAuthToken() CredentialType { return CredentialT
931936
func (CredentialType) Anonymous() CredentialType { return CredentialType(2) } // For Azure, SAS or public.
932937
func (CredentialType) SharedKey() CredentialType { return CredentialType(3) } // For Azure, SharedKey
933938
func (CredentialType) S3AccessKey() CredentialType { return CredentialType(4) } // For S3, AccessKeyID and SecretAccessKey
934-
func (CredentialType) GoogleAppCredentials() CredentialType { return CredentialType(5) }
939+
func (CredentialType) GoogleAppCredentials() CredentialType { return CredentialType(5) } // For GCP, App Credentials
935940
func (CredentialType) S3PublicBucket() CredentialType { return CredentialType(6) } // For S3, Anon Credentials & public bucket
936941

937942
func (ct CredentialType) IsAzureOAuth() bool {

e2etest/zt_newe2e_basic_functionality_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2etest
22

33
import (
44
"github.com/Azure/azure-storage-azcopy/v10/common"
5+
"strings"
56
"time"
67
)
78

@@ -64,3 +65,42 @@ func (s *BasicFunctionalitySuite) Scenario_SingleFileUploadDownload(svm *Scenari
6465
Body: body,
6566
}, true)
6667
}
68+
69+
func (s *BasicFunctionalitySuite) Scenario_SingleFileUploadDownload_EmptySAS(svm *ScenarioVariationManager) {
70+
azCopyVerb := ResolveVariation(svm, []AzCopyVerb{AzCopyVerbCopy, AzCopyVerbSync})
71+
72+
dstObj := CreateResource[ContainerResourceManager](svm, GetRootResource(svm, ResolveVariation(svm, []common.Location{common.ELocation.Local(), common.ELocation.Blob(), common.ELocation.File(), common.ELocation.BlobFS()})), ResourceDefinitionContainer{}).GetObject(svm, "test", common.EEntityType.File())
73+
74+
// Scale up from service to object
75+
srcObj := CreateResource[ObjectResourceManager](svm, GetRootResource(svm, ResolveVariation(svm, []common.Location{common.ELocation.Local(), common.ELocation.Blob(), common.ELocation.File(), common.ELocation.BlobFS()})), ResourceDefinitionObject{})
76+
77+
// no local <-> local
78+
if srcObj.Location().IsLocal() == dstObj.Location().IsLocal() {
79+
svm.InvalidateScenario()
80+
return
81+
}
82+
83+
stdout, _ := RunAzCopy(
84+
svm,
85+
AzCopyCommand{
86+
Verb: azCopyVerb,
87+
Targets: []ResourceManager{
88+
TryApplySpecificAuthType(srcObj, EExplicitCredentialType.PublicAuth(), svm, CreateAzCopyTargetOptions{}),
89+
TryApplySpecificAuthType(dstObj, EExplicitCredentialType.PublicAuth(), svm, CreateAzCopyTargetOptions{}),
90+
},
91+
Flags: CopyFlags{
92+
CopySyncCommonFlags: CopySyncCommonFlags{
93+
Recursive: pointerTo(true),
94+
},
95+
},
96+
ShouldFail: true,
97+
})
98+
99+
for _, line := range stdout.RawStdout() {
100+
if strings.Contains(line, "Please authenticate using Microsoft Entra ID (https://aka.ms/AzCopy/AuthZ), use AzCopy login, or append SAS to your Azure URL.") {
101+
return
102+
}
103+
}
104+
105+
svm.Error("expected output not found in azcopy output")
106+
}

0 commit comments

Comments
 (0)