Skip to content

Commit

Permalink
Support setting DFS group/owner/perms
Browse files Browse the repository at this point in the history
  • Loading branch information
adreed-msft committed May 5, 2023
1 parent 59bb3ac commit 2be0ac7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
18 changes: 9 additions & 9 deletions common/unixStatAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ const ( // Values cloned from x/sys/unix to avoid dependency
S_IFIFO = 0x1000
S_IFLNK = 0xa000

S_IRUSR = 0x400
S_IWUSR = 0x200
S_IXUSR = 0x100
S_IRGRP = 0x040
S_IWGRP = 0x020
S_IXGRP = 0x010
S_IROTH = 0x004
S_IWOTH = 0x002
S_IXOTH = 0x001
S_IRUSR = 0400
S_IWUSR = 0200
S_IXUSR = 0100
S_IRGRP = 0040
S_IWGRP = 0020
S_IXGRP = 0010
S_IROTH = 0004
S_IWOTH = 0002
S_IXOTH = 0001

S_ALLPERM = 0x777
)
Expand Down
61 changes: 56 additions & 5 deletions ste/sender-blobFS.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-storage-blob-go/azblob"
"net/url"
"strings"
"sync"
"time"

"github.com/Azure/azure-pipeline-go/pipeline"
Expand Down Expand Up @@ -237,7 +238,9 @@ func (u *blobFSSenderBase) GetSourcePOSIXProperties() (common.UnixStatAdapter, e
}
}

func (u *blobFSSenderBase) SetPOSIXProperties() error {
var HNSSetAccessControlFailedOnce = &sync.Once{}

func (u *blobFSSenderBase) SetPOSIXProperties(hnsOnly bool) error {
adapter, err := u.GetSourcePOSIXProperties()
if err != nil {
return fmt.Errorf("failed to get POSIX properties")
Expand All @@ -249,12 +252,57 @@ func (u *blobFSSenderBase) SetPOSIXProperties() error {
common.AddStatToBlobMetadata(adapter, meta)
delete(meta, common.POSIXFolderMeta) // Can't be set on HNS accounts.

_, err = u.GetBlobURL().SetMetadata(u.jptm.Context(), meta, azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
return err
var AccessControlURL interface {SetAccessControl(ctx context.Context, permissions azbfs.BlobFSAccessControl) (*azbfs.PathUpdateResponse, error)}
switch u.SendableEntityType() {
case common.EEntityType.File(), common.EEntityType.Symlink():
AccessControlURL = u.fileURL()
case common.EEntityType.Folder():
AccessControlURL = u.dirURL()
}

isRoot := false
if dURL, ok := AccessControlURL.(azbfs.DirectoryURL); ok {
if dURL.IsFileSystemRoot() {
isRoot = true
}
}

if !hnsOnly && !isRoot { // don't try to set metadata on the container
_, err = u.GetBlobURL().SetMetadata(u.jptm.Context(), meta, azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
if err != nil {
return err
}
}

mode := adapter.FileMode()
fields := []uint32{common.S_IRUSR, common.S_IWUSR, common.S_IXUSR, common.S_IRGRP, common.S_IWGRP, common.S_IXGRP, common.S_IROTH, common.S_IWOTH, common.S_IXOTH }
chars := "rwx"
out := ""
for _, field := range fields {
if mode & field == field {
out += string(chars[len(out) % 3])
} else {
out += "-"
}
}

_, err = AccessControlURL.SetAccessControl(u.jptm.Context(), azbfs.BlobFSAccessControl{
Owner: fmt.Sprint(adapter.Owner()),
Group: fmt.Sprint(adapter.Group()),
Permissions: out,
})
if err != nil { // A user could be targeting a non-HNS account with the dfs endpoint; it's best to warn rather than fail.
u.jptm.LogAtLevelForCurrentTransfer(pipeline.LogError, fmt.Sprintf("Failed to set dfs owner/group: %s", err.Error()))
HNSSetAccessControlFailedOnce.Do(func() {
common.GetLifecycleMgr().Info("One or more files or directories have failed to set access control; check the logs for details. (are you targeting a non-HNS account?)")
})
}

return nil
}

func (u *blobFSSenderBase) SetFolderProperties() error {
return u.SetPOSIXProperties()
return u.SetPOSIXProperties(false)
}

func (u *blobFSSenderBase) DirUrlToString() string {
Expand Down Expand Up @@ -295,6 +343,9 @@ func (u *blobFSSenderBase) SendSymlink(linkData string) error {
nil, // dfs doesn't support tags
azblob.ClientProvidedKeyOptions{}, // cpk isn't used for dfs
azblob.ImmutabilityPolicyOptions{}) // dfs doesn't support immutability policy
if err != nil {
return err
}

return err
return u.SetPOSIXProperties(true) // set only the HNS props
}
2 changes: 1 addition & 1 deletion ste/sender-blobFSFromLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (u *blobFSUploader) Epilogue() {
// Write POSIX data
if jptm.IsLive() {
if jptm.Info().PreservePOSIXProperties {
err := u.SetPOSIXProperties()
err := u.SetPOSIXProperties(false) // set all posix properties
if err != nil {
jptm.FailActiveUpload("Setting POSIX Properties", err)
}
Expand Down

0 comments on commit 2be0ac7

Please sign in to comment.