Skip to content

CVE-2019-11251: Remove symlink support from kubectl cp#82143

Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
soltysh:cp_no_links
Sep 3, 2019
Merged

CVE-2019-11251: Remove symlink support from kubectl cp#82143
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
soltysh:cp_no_links

Conversation

@soltysh
Copy link
Copy Markdown
Contributor

@soltysh soltysh commented Aug 29, 2019

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
Based on the recent discussion in SIG-CLI we've decided to drop support when copying data from pods.

Special notes for your reviewer:
/assign @liggitt @tallclair
Only the second commit matters, the first is coming from #82087

Fixes #87773

Does this PR introduce a user-facing change?:

`kubectl cp` no longer supports copying symbolic links from containers; to support this use case, see `kubectl exec --help` for examples using `tar` directly

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Aug 29, 2019
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 29, 2019
@soltysh
Copy link
Copy Markdown
Contributor Author

soltysh commented Aug 29, 2019

/sig cli
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 29, 2019
@k8s-ci-robot k8s-ci-robot requested review from dims and lavalamp August 29, 2019 19:42
@liggitt
Copy link
Copy Markdown
Member

liggitt commented Aug 29, 2019

Some packages in hack/.staticcheck_failures are passing staticcheck. Please remove them.

  pkg/kubectl/cmd/cp
Executing tests from //pkg/kubectl/cmd/cp:go_default_test
-----------------------------------------------------------------------------
--- FAIL: TestTarUntar (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rather than holding a pointer to the command, consider storing the name of the parent command here (e.g. o.ExecParentCmdName = cmd.Parent().Name()

then, make the hint about using exec condition on ExecParentCmdName being non-empty. that way, CopyOptions stays reusable

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should refer users to help describing how to use exec for symlink support... it is not immediately obvious how you would do that (even just see cp command help for details)

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this is verbose for an error that might be printed a bunch of times. Maybe simplify it to something like:

Suggested change
fmt.Fprintf(o.IOStreams.ErrOut, "warning: file %q is a symlink, skipping (consider using %s exec for symlink support)\n", destFileName, o.cmd.Parent().Name())
fmt.Fprintf(o.IOStreams.ErrOut, "skipping symlink: %q -> %q\n", destFileName, linkTarget)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd tend to agree. the pointer to exec can be printed just once

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This continue makes no difference, so I think it should be omitted.

Another alternative (my personal favorite) would be to remove the else and keep the continue to make the code path even cleaner and easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point, I prefer the no else approach too.

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think o.cmd can be nil in some of the tests, as the o.Complete func that sets cmd isn't executed in all of them. The applies to at least TestTarUntar.

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Aug 31, 2019

/milestone v1.16
/area security

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 2, 2019
@soltysh
Copy link
Copy Markdown
Contributor Author

soltysh commented Sep 2, 2019

@liggitt @tallclair @odinuge updated, sample output:

$ kubectl cp hello-1-b5fwp:/tmp/test ./
tar: Removing leading `/' from member names
warning: file "link" is a symlink, skipping (consider using "kubectl exec -n "" "hello-1-b5fwp" -- tar cf - "/tmp/test" | tar xf -")
warning: skipping symlink: "link2" -> "file2"

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 2, 2019
@soltysh
Copy link
Copy Markdown
Contributor Author

soltysh commented Sep 2, 2019

/retest

1 similar comment
@soltysh
Copy link
Copy Markdown
Contributor Author

soltysh commented Sep 2, 2019

/retest

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: does this copy to /tmp/bar like the description says?

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: does this copy to /tmp/bar like the description says?

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

&& len(o.ExecParentCmdName) > 0

Comment thread pkg/kubectl/cmd/cp/cp.go Outdated
@soltysh
Copy link
Copy Markdown
Contributor Author

soltysh commented Sep 3, 2019

@liggitt nits addressed, comments answered, ptal

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Sep 3, 2019

/lgtm
/approve
/retest

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 3, 2019
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, soltysh

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

The pull request process is described here

Details 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

Copy link
Copy Markdown
Member

@odinuge odinuge left a comment

Choose a reason for hiding this comment

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

/lgtm

@odinuge
Copy link
Copy Markdown
Member

odinuge commented Sep 3, 2019

/retest

Comment thread pkg/kubectl/cmd/cp/cp.go
evaledPath, err := filepath.EvalSymlinks(baseName)
if mode&os.ModeSymlink != 0 {
if !symlinkWarningPrinted && len(o.ExecParentCmdName) > 0 {
fmt.Fprintf(o.IOStreams.ErrOut, "warning: file %q is a symlink, skipping (consider using \"%s exec -n %q %q -- tar cf - %q | tar xf -\")\n", destFileName, o.ExecParentCmdName, src.PodNamespace, src.PodName, src.File)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I would make this error message more consistent with the other one, so they can be visually scanned together

Suggested change
fmt.Fprintf(o.IOStreams.ErrOut, "warning: file %q is a symlink, skipping (consider using \"%s exec -n %q %q -- tar cf - %q | tar xf -\")\n", destFileName, o.ExecParentCmdName, src.PodNamespace, src.PodName, src.File)
fmt.Fprintf(o.IOStreams.ErrOut, "warning: skipping symlink: %q -> %q (consider using \"%s exec -n %q %q -- tar cf - %q | tar xf -\")\n", destFileName, o.ExecParentCmdName, src.PodNamespace, src.PodName, src.File)

@fejta-bot
Copy link
Copy Markdown

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 35e0f17 into kubernetes:master Sep 3, 2019
@soltysh soltysh deleted the cp_no_links branch September 4, 2019 11:36
@soltysh soltysh mentioned this pull request Oct 1, 2019
@liggitt liggitt changed the title Remove symlink support from kubectl cp CVE-2019-11240: Remove symlink support from kubectl cp Feb 3, 2020
@liggitt liggitt changed the title CVE-2019-11240: Remove symlink support from kubectl cp CVE-2019-11251: Remove symlink support from kubectl cp Feb 3, 2020
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. area/kubectl area/security cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

CVE-2019-11251: kubectl cp symlink vulnerability

6 participants