Change:
If I look at the code of azureFile plugin, it has fsGroup as an argument, but don't see its usage anywhere I also don't see anywhere explicitely stated that azureFile volume supports fsGroup.
/sig storage
For those landing here, a separate path to get the mount point to have the right permissions is to add this annotation to the PV metadata: This makes the plugin mount the volume in the Pod under those UID,GID. Obviously, this implies that one knows what those are for their workload in the container ...
If i create a PV like this, still mounted with the default root used into POD. StorageClass PV
Issues go stale after 90d of inactivity. Mark the issue as fresh with . Stale issues rot after an additional 30d of inactivity and eventually close. Prevent issues from auto-closing with an comment. If this issue is safe to close now please do so with . Send feedback to sig-testing, kubernetes/test-infra and/or . /lifecycle stale
/remove-lifecycle stale cc Let's check whether works for azure file.
/sig azure
is another way to set groupid(gid) While according to this , we also need to support Here is the code about setting fsgroup from securityContext. I will enable this feature and do a test, it should be 3 lines of code. /assign
BTW, this is all for Linux(UserID, GroupID), is there an identical setting for Windows container?
No, setting user for volumes doesn't work on Windows. Only the rw/ro options are implemented.
According to my investigation, though I put the following code in azure file , it does not take effect. The reason is azure file(cifs) mount does not support gid setting after file system mount, by default would be 0(root) So in summary, set fsGroup code in azure file is useless, user could set gid by mountOptions in storage class, here is an Let me know if you hav any concern about this issue Update: Root cause is azure file(cifs) mount does not support gid setting after file system mount, while azure disk supports.
is this true, that cifs does not support guid setting?
Of course cifs support gid setting, see example: I mean cifs does not support second time gid setting, kind of differnet than azure disk. Anyway, I am working on a PR to support if no gid setting in azure file storage class, while if both sets, only gid from storage class would be used.
while the code is quite different than just add below 3 lines of code, actually below does not work: I will show you the PR tomorrow.

Discussion:
"//pkg/util/mount:go_default_library", "//pkg/volume:go_default_library", "//pkg/volume/testing:go_default_library", <ins> "//vendor/github.com/Azure/go-autorest/autorest/to:go_default_library", </ins> "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",

options = append(options, "ro") } mountOptions = volume.JoinMountOptions(b.mountOptions, options) <del> mountOptions = appendDefaultMountOptions(mountOptions) </del> <ins> mountOptions = appendDefaultMountOptions(mountOptions, fsGroup) </ins> } err = b.mounter.Mount(source, dir, "cifs", mountOptions)

"strings" "testing" <ins> "github.com/Azure/go-autorest/autorest/to" </ins> "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types"

func TestAppendDefaultMountOptions(t *testing.T) { tests := []struct { options  []string <ins> fsGroup  *int64 </ins> expected []string }{ { <del> options:  []string{"dir_mode=0777"}, expected: []string{"dir_mode=0777", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", vers, defaultVers)}, </del> <ins> options: []string{"dir_mode=0777"}, fsGroup: nil, expected: []string{"dir_mode=0777", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", vers, defaultVers)}, </ins> }, { <del> options:  []string{"file_mode=0777"}, expected: []string{"file_mode=0777", fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=%s", vers, defaultVers)}, </del> <ins> options: []string{"file_mode=0777"}, fsGroup: to.Int64Ptr(0), expected: []string{"file_mode=0777", fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=%s", vers, defaultVers), fmt.Sprintf("%s=0", gid)}, </ins> }, { <del> options:  []string{"vers=2.1"}, expected: []string{"vers=2.1", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode)}, </del> <ins> options: []string{"vers=2.1"}, fsGroup: to.Int64Ptr(1000), expected: []string{"vers=2.1", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=1000", gid)}, </ins> }, { <del> options:  []string{""}, expected: []string{"", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=%s", vers, defaultVers)}, </del> <ins> options: []string{""}, expected: []string{"", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode), fmt.Sprintf("%s=%s", vers, defaultVers)}, </ins> }, { options:  []string{"file_mode=0777", "dir_mode=0777"}, expected: []string{"file_mode=0777", "dir_mode=0777", fmt.Sprintf("%s=%s", vers, defaultVers)}, }, <ins> { options: []string{"gid=2000"}, fsGroup: to.Int64Ptr(1000), expected: []string{"gid=2000", fmt.Sprintf("%s=%s", fileMode, defaultFileMode), fmt.Sprintf("%s=%s", dirMode, defaultDirMode), "vers=3.0"}, }, </ins> } for _, test := range tests { <del> result := appendDefaultMountOptions(test.options) </del> <ins> result := appendDefaultMountOptions(test.options, test.fsGroup) </ins> if !reflect.DeepEqual(result, test.expected) { t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected) }

const ( fileMode        = "file_mode" dirMode         = "dir_mode" <ins> gid             = "gid" </ins> vers            = "vers" defaultFileMode = "0755" defaultDirMode  = "0755"

return secretName, err } <del> // check whether mountOptions contain file_mode and dir_mode, if not, append default mode func appendDefaultMountOptions(mountOptions []string) []string { </del> <ins> // check whether mountOptions contain file_mode, dir_mode, vers, gid, if not, append default mode func appendDefaultMountOptions(mountOptions []string, fsGroup *int64) []string { </ins> fileModeFlag := false dirModeFlag := false versFlag := false <ins> gidFlag := false </ins> for _, mountOption := range mountOptions { if strings.HasPrefix(mountOption, fileMode) {

if strings.HasPrefix(mountOption, vers) { versFlag = true } <ins> if strings.HasPrefix(mountOption, gid) { gidFlag = true } </ins> } allMountOptions := mountOptions

if !versFlag { allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", vers, defaultVers)) } <ins> if !gidFlag && fsGroup != nil { allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%d", gid, *fsGroup)) } </ins> return allMountOptions }