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

Detect backsteps correctly in base path detection #61080

Merged
merged 2 commits into from
Mar 13, 2018

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Mar 13, 2018

Avoids false positives with atomic writer ..<timestamp> directories

Fixes #61076

/assign @msau42 @jsafrane

Fix a regression that prevented using `subPath` volume mounts with secret, configMap, projected, and downwardAPI volumes

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 13, 2018
@liggitt
Copy link
Member Author

liggitt commented Mar 13, 2018

@kubernetes/sig-storage-pr-reviews @kubernetes/sig-storage-bugs

@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 13, 2018
@liggitt liggitt added this to the v1.10 milestone Mar 13, 2018
@liggitt liggitt added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Mar 13, 2018
@liggitt
Copy link
Member Author

liggitt commented Mar 13, 2018

cc @tallclair

Copy link
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

@msau42 is OOO. I can find someone else tomorrow if @jsafrane doesn't beat me to it.

@@ -325,7 +325,7 @@ func pathWithinBase(fullPath, basePath string) bool {
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This function is also implemented in Kubelet, although I'm not sure it's used anywhere? https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/util/util.go#L51

Copy link
Contributor

@ericchiang ericchiang Mar 13, 2018

Choose a reason for hiding this comment

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

I don't see any uses of that method on master, v1.9.4, v1.8.9, or v1.7.9

$ ag 'pathWithinBase'
pkg/util/mount/mount_windows_test.go
544:            result := pathWithinBase(test.fullPath, test.basePath)
545:            assert.Equal(t, result, test.expectedResult, "Expect result not equal with pathWithinBase(%s, %s) return: %q, expected: %q",

pkg/util/mount/mount_linux_test.go
407:            if pathWithinBase(test.fullPath, test.basePath) != test.expected {

pkg/util/mount/mount_linux.go
732:    if !pathWithinBase(evalSubPath, subpath.VolumePath) {
912:    if !pathWithinBase(endDir, baseDir) {
949:    if !pathWithinBase(pathname, base) {
976:    if !pathWithinBase(fullExistingPath, base) {
1121:           if !pathWithinBase(currentPath, base) {

pkg/util/mount/mount_windows.go
329:            if !pathWithinBase(currentFullPath, volumePath) {
473:    if !pathWithinBase(pathname, base) {
508:    if !pathWithinBase(fullExistingPath, fullBasePath) {

pkg/util/mount/mount.go
322:// pathWithinBase checks if give path is within given base directory.
323:func pathWithinBase(fullPath, basePath string) bool {

pkg/kubelet/util/util.go
51:func pathWithinBase(fullPath, basePath string) bool {

Copy link
Member Author

Choose a reason for hiding this comment

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

removed the unused function. similar faulty logic exists in pkg/util/mount/mount_windows.go lockAndCheckSubPathWithoutSymlink and findExistingPrefix

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 13, 2018
@@ -291,7 +291,7 @@ func lockAndCheckSubPathWithoutSymlink(volumePath, subPath string) ([]uintptr, e
if err != nil {
return []uintptr{}, fmt.Errorf("Rel(%s, %s) error: %v", volumePath, subPath, err)
}
if strings.HasPrefix(relSubPath, "..") {
if relSubPath == ".." || strings.HasPrefix(relSubPath, ".."+string(filepath.Separator)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@andyzhangx, can you verify this is correct? (does filepath.Rel always produce ..\ backstep paths on windows or would a subPath of ../... get preserved and fail this check?

@@ -552,7 +552,7 @@ func findExistingPrefix(base, pathname string) (string, []string, error) {
return base, nil, err
}

if strings.HasPrefix(rel, "..") {
if rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@andyzhangx same here

Avoid false positives with atomic writer ..<timestamp> directories
@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 13, 2018
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2018
@lorenz
Copy link
Contributor

lorenz commented Mar 13, 2018

Will this be released as 1.9.5 (for the 1.9 series)? Or is it better to downgrade for the time being?

@liggitt
Copy link
Member Author

liggitt commented Mar 13, 2018

Will this be released as 1.9.5 (for the 1.9 series)?

yes, this will be cherry-picked to 1.7.x, 1.8.x, and 1.9.x

@jsafrane
Copy link
Member

/lgtm

@liggitt
Copy link
Member Author

liggitt commented Mar 13, 2018

fyi @kubernetes/sig-release-misc

@k8s-ci-robot k8s-ci-robot added the sig/release Categorizes an issue or PR as relevant to SIG Release. label Mar 13, 2018
@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@andyzhangx @jsafrane @liggitt @tallclair

Pull Request Labels
  • sig/release sig/storage: Pull Request will be escalated to these SIGs if needed.
  • priority/critical-urgent: Never automatically move pull request out of a release milestone; continually escalate to contributor and SIG through all available channels.
  • kind/bug: Fixes a bug discovered during the current release.
Help

Context("Atomic writer volumes", func() {
var err error

BeforeEach(func() {
Copy link
Member

Choose a reason for hiding this comment

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

nit - Do we need an AfterEach to cleanup the secret and configmap? How about the pods? (where do they get cleaned up?)

Copy link
Member Author

@liggitt liggitt Mar 13, 2018

Choose a reason for hiding this comment

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

Do we need an AfterEach to cleanup the secret and configmap?

not really... these just hang around for the duration of the test (and if they already exist, the setup tolerates it)

where do they get cleaned up?

the entire namespace gets deleted at the end of each test, which cleans everything up

Copy link
Member

Choose a reason for hiding this comment

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

thanks @liggitt !

@ericchiang
Copy link
Contributor

/assign @tallclair

For pkg/kubelet/OWNERS approval.

@tallclair
Copy link
Member

/lgtm
Thanks!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, jsafrane, liggitt, tallclair

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 60737, 60739, 61080, 60968, 60951). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 8313fc0 into kubernetes:master Mar 13, 2018
k8s-github-robot pushed a commit that referenced this pull request Mar 13, 2018
…0-upstream-release-1.9

Automatic merge from submit-queue.

Automated cherry pick of #61080: Detect backsteps correctly in base path detection

Cherry pick of #61080 on release-1.9.

#61080: Detect backsteps correctly in base path detection
@liggitt liggitt deleted the subpath-test branch March 14, 2018 01:04
@jpbetz jpbetz added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Mar 14, 2018
k8s-github-robot pushed a commit that referenced this pull request Mar 14, 2018
…0-upstream-release-1.7

Automatic merge from submit-queue.

Automated cherry pick of #61080: Detect backsteps correctly in base path detection

Cherry pick of #61080 on release-1.7.

#61080: Detect backsteps correctly in base path detection
k8s-github-robot pushed a commit that referenced this pull request Mar 14, 2018
…0-upstream-release-1.8

Automatic merge from submit-queue.

Automated cherry pick of #61080: Detect backsteps correctly in base path detection

Cherry pick of #61080 on release-1.8.

#61080: Detect backsteps correctly in base path detection
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. cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.