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

set fsGroup by securityContext.fsGroup in azure file #58316

Merged
merged 1 commit into from
Jan 17, 2018

Conversation

andyzhangx
Copy link
Member

What this PR does / why we need it:
set fsGroup by securityContext.fsGroup in azure file
This PR respects securityContext.fsGroup, while if user both sets gid=xxx in mountOptions in azure storage class and securityContext.fsGroup, gid=xxx setting in mountOptions will win.

apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo
spec:
  securityContext:
    fsGroup: 2000
  volumes:
  - name: sec-ctx-vol
    emptyDir: {}
  containers:
  - name: sec-ctx-demo
    image: gcr.io/google-samples/node-hello:1.0
    volumeMounts:
    - name: sec-ctx-vol
      mountPath: /data/demo
    securityContext:
      allowPrivilegeEscalation: false

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #44085

Special notes for your reviewer:

Release note:

set fsGroup by securityContext.fsGroup in azure file

/assign @karataliu
cc @rootfs @avaranovich

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 16, 2018
@andyzhangx
Copy link
Member Author

/sig azure

@@ -225,9 +225,11 @@ func (b *azureFileMounter) SetUpAt(dir string, fsGroup *int64) error {
options := []string{fmt.Sprintf("username=%s,password=%s", accountName, accountKey)}
if b.readOnly {
options = append(options, "ro")
// we don't respect fsGroup value if b.readOnly = true
fsGroup = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can make use of fsGroup here. Some implementations do mount with ro first, so that gid could not be changed later.
Here it should be fine as it is passed via mount option,

Copy link
Member Author

Choose a reason for hiding this comment

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

according to https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/aws_ebs/aws_ebs.go#L379-L381
no fsGroup value will be set if readOnly = true

	if !b.readOnly {
		volume.SetVolumeOwnership(b, fsGroup)
	}

Anyway I reserved fsGroup value and use groupID var instead, not change the passing parameter value.

@@ -96,10 +97,11 @@ func (s *azureSvc) SetAzureCredentials(host volume.VolumeHost, nameSpace, accoun
}

// check whether mountOptions contain file_mode and dir_mode, if not, append default mode
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider updating comment since add gid logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member Author

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

@karataliu PTAL

@@ -225,9 +225,11 @@ func (b *azureFileMounter) SetUpAt(dir string, fsGroup *int64) error {
options := []string{fmt.Sprintf("username=%s,password=%s", accountName, accountKey)}
if b.readOnly {
options = append(options, "ro")
// we don't respect fsGroup value if b.readOnly = true
fsGroup = nil
Copy link
Member Author

Choose a reason for hiding this comment

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

according to https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/aws_ebs/aws_ebs.go#L379-L381
no fsGroup value will be set if readOnly = true

	if !b.readOnly {
		volume.SetVolumeOwnership(b, fsGroup)
	}

Anyway I reserved fsGroup value and use groupID var instead, not change the passing parameter value.

@@ -96,10 +97,11 @@ func (s *azureSvc) SetAzureCredentials(host volume.VolumeHost, nameSpace, accoun
}

// check whether mountOptions contain file_mode and dir_mode, if not, append default mode
Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@andyzhangx andyzhangx force-pushed the azurefile-setfsgroup branch from 6973118 to e94a988 Compare January 17, 2018 05:52
@andyzhangx
Copy link
Member Author

/test pull-kubernetes-kubemark-e2e-gce

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-e2e-kops-aws

expected: []string{"file_mode=0777",
fmt.Sprintf("%s=%s", dirMode, defaultDirMode),
fmt.Sprintf("%s=%s", vers, defaultVers),
fmt.Sprintf("%s=0", gid)},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a test where input string contains 'gid' and fsGroup is set, to verify gid takes precedence over fsGroup?

Others looks good. Please also do squash commits.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-e2e-kops-aws

fix comments

fix comments

fix comments
@andyzhangx andyzhangx force-pushed the azurefile-setfsgroup branch from e94a988 to c38e758 Compare January 17, 2018 09:25
Copy link
Member Author

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

@karataliu PTAL

expected: []string{"file_mode=0777",
fmt.Sprintf("%s=%s", dirMode, defaultDirMode),
fmt.Sprintf("%s=%s", vers, defaultVers),
fmt.Sprintf("%s=0", gid)},
Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@karataliu
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, karataliu

Associated issue: #44085

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 20f27a7 into kubernetes:master Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fsGroup in not used for azureFile
4 participants