-
Notifications
You must be signed in to change notification settings - Fork 145
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
feat: use cluster identity for using azcopy in volume cloning #1654
feat: use cluster identity for using azcopy in volume cloning #1654
Conversation
Hi @umagnus. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
@@ -2904,3 +2936,256 @@ func TestGenerateSASToken(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func Test_authorizeAzcopyWithIdentity(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestAuthorizeAzcopyWithIdentity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/azurefile/azurefile.go
Outdated
klog.Warningf("azcopy list failed with AuthorizationPermissionMismatch error, should assign \"Storage File Data SMB Share Elevated Contributor\" role to controller identity, fall back to use sas token, original output: %v", string(out)) | ||
d.azcopySasTokenCache.Set(accountName, "") | ||
var accountKey, sasToken string | ||
if accountKey, err = d.GetStorageAccesskey(ctx, accountOptions, secrets, secretName, secretNamespace); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could leverage getSASToken
func to get sas token? thus don't need to duplicate code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, give a useSasToken parameter to get sas token
pkg/azurefile/azurefile.go
Outdated
srcPath := srcPath + sasToken | ||
dstPath := dstPath + sasToken | ||
cmd := exec.Command("azcopy", "copy", srcPath, dstPath, "--recursive", "--check-length=false") | ||
if len(authAzcopyEnv) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this since it's already using sastoken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/azurefile/azurefile.go
Outdated
if copyErr != nil { | ||
if strings.Contains(string(out), authorizationPermissionMismatch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(accountSASToken) > 0 && strings.Contains(string(out), authorizationPermissionMismatch) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be accountSASToken ==""
which means we use identity and get permission mismatch
pkg/azurefile/azurefile.go
Outdated
if sasToken, err = generateSASToken(accountName, accountKey, storageEndpointSuffix, d.sasTokenExpirationMinutes); err != nil { | ||
return err | ||
} | ||
srcPath := srcPath + sasToken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a loop, don't change srcPath
, dstPath
, otherwise this append may happen multiple times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls also follow this PR to refine getSASToken func:
/retest |
2 similar comments
/retest |
/retest |
pkg/azurefile/controllerserver.go
Outdated
|
||
return authAzcopyEnv, nil | ||
} | ||
return []string{}, fmt.Errorf("service principle or managed identity are both not set") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neither the service principal nor the managed identity has been set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/azurefile/controllerserver.go
Outdated
// 4. parameter useSasToken is true | ||
func (d *Driver) getAzcopyAuth(ctx context.Context, accountName, accountKey, storageEndpointSuffix string, accountOptions *azure.AccountOptions, secrets map[string]string, secretName, secretNamespace string, useSasToken bool) (string, []string, error) { | ||
var authAzcopyEnv []string | ||
if len(secrets) == 0 && len(secretName) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !useSasToken && len(secrets) == 0 && len(secretName) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/azurefile/azurefile.go
Outdated
klog.V(2).Infof("azcopy job status: %s, copy percent: %s%%, error: %v", jobState, percent, err) | ||
switch jobState { | ||
case fileutil.AzcopyJobError, fileutil.AzcopyJobCompleted: | ||
return err | ||
case fileutil.AzcopyJobNotFound: | ||
klog.V(2).Infof("copy fileshare %s to %s", srcFileShareName, dstFileShareName) | ||
out, copyErr := exec.Command("azcopy", "copy", srcPath, dstPath, "--recursive", "--check-length=false").CombinedOutput() | ||
cmd := exec.Command("azcopy", "copy", srcPath, dstPath, "--recursive", "--check-length=false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better set a defaultAzcopyMountOption var to replace "--recursive", "--check-length=false"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/azurefile/azurefile.go
Outdated
if sasToken, _, err = d.getAzcopyAuth(ctx, accountName, "", storageEndpointSuffix, accountOptions, secrets, secretName, secretNamespace, true); err != nil { | ||
return err | ||
} | ||
out, copyErr = exec.Command("azcopy", "copy", srcPath+sasToken, dstPath+sasToken, "--recursive", "--check-length=false").CombinedOutput() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better set a defaultAzcopyMountOption var to replace "--recursive", "--check-length=false"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/retest |
can you squash all commits? thanks. |
0785325
to
b4926fc
Compare
/retest |
2 similar comments
/retest |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andyzhangx, umagnus The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/cherrypick release-1.29 |
@andyzhangx: new pull request created: #1657 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/cherrypick release-1.28 |
@andyzhangx: #1654 failed to apply on top of branch "release-1.28":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/cherrypick release-1.29 |
@andyzhangx: #1654 failed to apply on top of branch "release-1.29":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
azcopy already supports managed identity in a different way: Authorize access to blobs with AzCopy & Microsoft Entra ID | Microsoft Learn, and it supports file in the latest version.
if user only provides storage account key, then we should use sas token; otherwise we should leverage aks cluster identity(managed identity or spn) for volume cloning which is better way.
Which issue(s) this PR fixes:
Fixes #
Requirements:
Special notes for your reviewer:
Release note: