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

not allow backsteps in local volume plugin #47236

Merged

Conversation

dixudx
Copy link
Member

@dixudx dixudx commented Jun 9, 2017

Which issue this PR fixes : fixes #47207

Special notes for your reviewer:
cc @msau42 @ddysher
Just follow @liggitt commented.

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 9, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @dixudx. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 9, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Jun 9, 2017
@dixudx dixudx force-pushed the not_allow_backsteps_in_local_volume branch from 6937333 to c339a06 Compare June 9, 2017 10:38
// 3. start with '..'
// 4. contain filename larger than 255 characters
// 5. be longer than 4096 characters
func ValidateLocalPath(targetPath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also probably be used for the host volume plugin, so perhaps a different name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this check different from

https://github.com/kubernetes/kubernetes/blob/master/pkg/api/validation/validation.go#L947

It seems weird to me to have different validation here than every where else.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jhorwit2 Yeah, you're right. Thanks for pointing out.

These two functions are nearly the same. But https://github.com/kubernetes/kubernetes/blob/master/pkg/api/validation/validation.go#L947 may not be suitable to be called in pkg/volume/local/local.go.

@@ -51,6 +51,7 @@ import (
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/security/apparmor"
"k8s.io/kubernetes/pkg/volume/util"
Copy link
Member

Choose a reason for hiding this comment

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

I don't really think the api package should be importing the volume package... I'd rather see the validation function stay in the validation package

if item == ".." {
return fmt.Errorf("invalid path: must not contain '..': %s", targetPath)
}
if len(item) > maxFileNameLength {
Copy link
Member

Choose a reason for hiding this comment

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

is maxFileNameLength the max of all platforms' max, or the min of all platforms' max?

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this already covered on each node when the mounts are provisioned, which would be platform specific?

Copy link
Member Author

Choose a reason for hiding this comment

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

@liggitt Linux has a maximum filename length of 255 characters for most filesystems (including EXT4), and a maximum path of 4096 characters. On windows, the maximum length for a path is defined as 260 characters and a maximum total path length is 32,767 characters. Here maxFileNameLength is the min value. Also for maxPathLength.

Copy link
Member

Choose a reason for hiding this comment

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

Since there are differences between platforms, I don't think we should be enforcing this this way. Let's limit this to the backstep path segment prevention for now

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good advice. Function validateLocalNonReservedPath is quite similar with this function. Shall we abstract the core part to a common function?

@jhorwit2
Copy link
Contributor

jhorwit2 commented Jun 9, 2017

Local volumes would still allow backsteps in the VolumeMount.SubPath, correct? Do we want to also address that here? If I'm not mistaken that's taken care of outside the local volume mounter just like with the host volume mounter.

// 5. be longer than 4096 characters
func ValidateLocalPath(targetPath string) error {
if targetPath == "" {
return fmt.Errorf("invalid path: must not be empty: %q", targetPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. if it's empty then I don't see a reason of showing it in quotes
  2. I don't think that we should add "invalid path:" prefix to each error message. We're using field.Invalid() and it also adds similar prefix to the error AFAIR.

Copy link
Member Author

Choose a reason for hiding this comment

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

@php-coder Actually function validateLocalNonReservedPath is exactly like what you said. But I think it is not quite suitable to be called by other functions.

}

if !tc.valid && err == nil {
t.Errorf("%v: unexpected success", tc.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

"%v: unexpected success for the path %q" ?

for _, tc := range cases {
err := ValidateLocalPath(tc.path)
if tc.valid && err != nil {
t.Errorf("%v: unexpected failure: %v", tc.name, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to include path in the error msg, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, will update it.

}
}
if strings.HasPrefix(items[0], "..") && len(items[0]) > 2 {
return fmt.Errorf("invalid path: must not start with '..': %s", targetPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is reserved paths and why we don't allow them? How they're dangerous? Is it something Windows-specific?

@msau42
Copy link
Member

msau42 commented Jun 9, 2017

Do we want local and hostpath path validations to use the same function?

@dixudx
Copy link
Member Author

dixudx commented Jun 11, 2017

@jhorwit2 Local volumes does not allow backsteps in the VolumeMount.SubPath, which has already been validated in ValidateVolumeMounts.

@dixudx dixudx force-pushed the not_allow_backsteps_in_local_volume branch 2 times, most recently from 03dd60c to 50b233d Compare June 11, 2017 06:05
@jhorwit2
Copy link
Contributor

@dixudx that check assumes the apiserver & the node are the same OS. I opened a PR that hopes to address that issue. #47290

@dixudx dixudx closed this Jun 17, 2017
@dixudx dixudx force-pushed the not_allow_backsteps_in_local_volume branch from 50b233d to 5262a37 Compare June 17, 2017 04:56
@dixudx dixudx reopened this Jun 17, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2017
@dixudx
Copy link
Member Author

dixudx commented Jun 17, 2017

@liggitt PTAL. Revised based on #47290.

@@ -1134,6 +1134,8 @@ func validateLocalVolumeSource(ls *api.LocalVolumeSource, fldPath *field.Path) f
if ls.Path == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("path"), ""))
Copy link
Member

Choose a reason for hiding this comment

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

return early

@@ -192,6 +193,11 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *types.UnixGroupID) err
return err
}

err := validation.ValidatePathNoBacksteps(m.globalPath)
Copy link
Member

Choose a reason for hiding this comment

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

should this be validating m.globalPath or dir?

Copy link
Member Author

Choose a reason for hiding this comment

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

validating m.globalPath.

@dixudx dixudx force-pushed the not_allow_backsteps_in_local_volume branch from e56d032 to aa23ed5 Compare June 17, 2017 06:37
@msau42
Copy link
Member

msau42 commented Jun 19, 2017

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 19, 2017
@msau42
Copy link
Member

msau42 commented Jun 19, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2017
@k8s-github-robot k8s-github-robot added the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Jun 19, 2017
@dixudx
Copy link
Member Author

dixudx commented Jun 20, 2017

@msau42 @liggitt need your approval. Thx.

@supereagle
Copy link
Contributor

@dixudx Need to add release note to remove the label release-note-label-needed. Please refer to Write Release Notes if Needed.

@k8s-github-robot k8s-github-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jun 20, 2017
@liggitt
Copy link
Member

liggitt commented Jun 21, 2017

/lgtm

@dixudx
Copy link
Member Author

dixudx commented Jun 21, 2017

/assign @thockin

Needs your approval @thockin . Thx.

@dchen1107 dchen1107 removed the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Jun 21, 2017
@dchen1107 dchen1107 added this to the v1.7 milestone Jun 21, 2017
@dchen1107
Copy link
Member

/approve

Thanks!

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dchen1107, dixudx, liggitt, msau42

Associated issue: 47207

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 k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 34515, 47236, 46694, 47819, 47792)

@k8s-github-robot k8s-github-robot merged commit 1184ce8 into kubernetes:master Jun 21, 2017
@dixudx dixudx deleted the not_allow_backsteps_in_local_volume branch September 9, 2017 14:10
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-none Denotes a PR that doesn't merit a release note. 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.

Don't allow backsteps in local volume plugin