Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added proper error message for system to system container copy #2883

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,17 @@ func (cca *CookedCopyCmdArgs) processCopyJobPartOrders() (err error) {
return fmt.Errorf("S2S copy from Azure File authenticated with Azure AD to Blob/BlobFS is not supported")
}

// Check if destination is system container
if cca.FromTo.IsS2S() {
dstContainerName, err := GetContainerName(cca.Destination.Value, cca.FromTo.To())
if err != nil {
return fmt.Errorf("failed to get container name from destination (is it formatted correctly?): %w", err)
}
if common.IsSystemContainer(dstContainerName) {
return fmt.Errorf("cannot copy to system container '%s'", dstContainerName)
}
}

switch {
case cca.FromTo.IsUpload(), cca.FromTo.IsDownload(), cca.FromTo.IsS2S():
// Execute a standard copy command
Expand Down
11 changes: 11 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ func (cca *cookedSyncCmdArgs) process() (err error) {
return fmt.Errorf("S2S sync from Azure File authenticated with Azure AD to Blob/BlobFS is not supported")
}

// Check if destination is system container
if cca.fromTo.IsS2S() {
dstContainerName, err := GetContainerName(cca.destination.Value, cca.fromTo.To())
if err != nil {
return fmt.Errorf("failed to get container name from destination (is it formatted correctly?)")
}
if common.IsSystemContainer(dstContainerName) {
return fmt.Errorf("cannot copy to system container '%s'", dstContainerName)
}
}

enumerator, err := cca.initEnumerator(ctx)
if err != nil {
return err
Expand Down
18 changes: 18 additions & 0 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,21 @@ func DoWithOverrideReadOnlyOnAzureFiles(ctx context.Context, action func() (inte
_, err = action()
return err
}

// @brief Checks if the container name provided is a system container or not
func IsSystemContainer(containerName string) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that the input $ is encoded when it gets here? Would be good to check that case as well

// Decode the container name in case it's URL-encoded
decodedName, err := url.QueryUnescape(containerName)
if err != nil {
// If decoding fails, it's unlikely the name matches a system container
return false
}
// define the system variables for the system containers
systemContainers := []string{"$blobchangefeed", "$logs"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These containers as destination of copy shall be errored out but as source it shall still work. Add test cases around such combinations in E2E

for _, sys := range systemContainers {
if decodedName == sys {
return true
}
}
return false
}
53 changes: 52 additions & 1 deletion e2etest/zt_newe2e_s2s_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package e2etest

import (
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"github.com/Azure/azure-storage-azcopy/v10/common"
"strconv"
)

func init() {
Expand Down Expand Up @@ -619,3 +621,52 @@ func (s *S2STestSuite) Scenario_S2SDirectoryMultipleFilesStripTopDirNonRecursive
Objects: dstObjs,
}, true)
}

func (s *S2STestSuite) Scenario_SystemContainerCopy(svm *ScenarioVariationManager) {
azCopyVerb := ResolveVariation(svm, []AzCopyVerb{AzCopyVerbCopy, AzCopyVerbSync}) // Calculate verb early to create the destination object early
// Scale up from service to object
containerName := "$blobchangefeed"
dstObj := CreateResource[ContainerResourceManager](svm, GetRootResource(svm, ResolveVariation(svm, []common.Location{common.ELocation.Blob()})), ResourceDefinitionContainer{
ContainerName: &containerName,
}).GetObject(svm, "test", common.EEntityType.File())

// The object must exist already if we're syncing.
if azCopyVerb == AzCopyVerbSync {
dstObj.Create(svm, NewZeroObjectContentContainer(0), ObjectProperties{})

if !svm.Dryrun() {
// Make sure the LMT is in the past
time.Sleep(time.Second * 10)
}
}

body := NewRandomObjectContentContainer(SizeFromString("10K"))
// Scale up from service to object
srcObj := CreateResource[ObjectResourceManager](svm, GetRootResource(svm, ResolveVariation(svm, []common.Location{common.ELocation.Local(), common.ELocation.Blob(), common.ELocation.File(), common.ELocation.BlobFS()})), ResourceDefinitionObject{
ObjectName: pointerTo("test"),
Body: body,
})

sasOpts := GenericAccountSignatureValues{}

stdOut, _ := RunAzCopy(
svm,
AzCopyCommand{
Verb: azCopyVerb,
Targets: []ResourceManager{
TryApplySpecificAuthType(srcObj, EExplicitCredentialType.SASToken(), svm, CreateAzCopyTargetOptions{
SASTokenOptions: sasOpts,
}),
TryApplySpecificAuthType(dstObj, EExplicitCredentialType.SASToken(), svm, CreateAzCopyTargetOptions{
SASTokenOptions: sasOpts,
}),
},
Flags: CopyFlags{
CopySyncCommonFlags: CopySyncCommonFlags{
Recursive: pointerTo(true),
},
},
ShouldFail: true,
})
ValidateMessageOutput(svm, stdOut, "cannot copy to system container")
}
Loading