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

Preserve file mode when copying files out of a pod #73053

Closed
wants to merge 2 commits into from

Conversation

evanphx
Copy link

@evanphx evanphx commented Jan 17, 2019

What type of PR is this?
/kind bug

What this PR does / why we need it:
This fixes the ability to inherit the file modes from the files within the pod that are copied. Most importantly, it makes sure that the execute bits are set properly and generally makes this code match what tar would do (namely, using a readonly mode if the source was readonly)

Which issue(s) this PR fixes:
Didn't open an issue, just fixed the problem directly.

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

File modes are properly maintained when copying data out of pods with `kubectl cp`

This fixes the ability to inherit the file modes from the files within the pod that are copied. Most importantly, it makes sure that the execute bits are set properly and generally makes this code match what tar would do (namely, using a readonly mode if the source was readonly)
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Jan 17, 2019
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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 cncf-cla: no Indicates the PR's author has not 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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 17, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @evanphx. 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 /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.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: evanphx
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: adohe

If they are not already assigned, you can assign the PR to them by writing /assign @adohe in a comment when ready.

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 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 Jan 17, 2019
@evanphx
Copy link
Author

evanphx commented Jan 17, 2019

signed the CLA

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 17, 2019
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

thank you for the PR @evanphx
this change needs approval by SIG CLI.

/ok-to-test
/priority backlog

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 27, 2019
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 29, 2019
@evanphx
Copy link
Author

evanphx commented May 13, 2019

/remove-lifecycle stable

@evanphx
Copy link
Author

evanphx commented May 14, 2019

@neolit123 Any thoughts on this?

@neolit123
Copy link
Member

@neolit123 Any thoughts on this?

try mentioning this PR in the slack channels #sig-cli or #pr-reviews

@liggitt
Copy link
Member

liggitt commented May 15, 2019

@soltysh @tallclair note that this will allow creating executable files via kubectl cp. What kubectl cp currently does is not correct, but we've had enough issues with cp that I'm really wary of expanding its potential as an attack vector

@evanphx
Copy link
Author

evanphx commented May 15, 2019

I added this actually because I wanted to preserve the executable bits.

@evanphx
Copy link
Author

evanphx commented May 15, 2019

What should kubectl cp do? I can add a flag, ala tar, to preserve executable bits.

@evanphx
Copy link
Author

evanphx commented May 23, 2019

I'm happy to change this however y'all think is best, please let me know.

@soggiest
Copy link

Hello! Code Freeze is just about on us. We'll be entering into Freeze tomorrow, May 31st. Is this still planned to land in 1.15?

@apelisse
Copy link
Member

What should kubectl cp do? I can add a flag, ala tar, to preserve executable bits.

I think I'm fine with that, what do you think @liggitt @soltysh

@soggiest
Copy link

soggiest commented Jun 3, 2019

/milestone v1.16

@k8s-ci-robot k8s-ci-robot modified the milestones: v1.15, v1.16 Jun 3, 2019
@liggitt
Copy link
Member

liggitt commented Jul 9, 2019

given the repeated past vulnerabilities in kubectl cp where files from malicious tar files sent by containers could escape the target directory, I don't think making files executable is a good idea.

@kubernetes/sig-cli-maintainers should consider one or more of the following options:

  • moving kubectl cp to an optional plugin (reduces attack surface for users that don't care about it, allows independent release of the command)
  • rewriting kubectl cp to use tar directly instead of a custom tar file extractor. most tar implementations are hardened to avoid extracting files outside the target directory (via absolute paths, or relative backsteps, or symlinks)
  • deprecating/removing kubectl cp in favor of direct use of kubectl exec and tar

@xmudrii
Copy link
Member

xmudrii commented Aug 12, 2019

@evanphx @liggitt Hello! I'm bug triage lead for the 1.16 release cycle and considering this PR has not been updated for a long time, I'd like to check what's the status of this PR. The code freeze is starting 29th August (about 2.5 weeks from now) and while there is plenty of time, we want to ensure that each PR has a chance to be merged on time.

As the PR is tagged for 1.16, is it still planned for this release?

@evanphx
Copy link
Author

evanphx commented Aug 12, 2019

@liggitt Perhaps since you're concerned about setting executable, exposing it as a configuration option to honor the executable bit? Happy to add that to this PR.

@liggitt
Copy link
Member

liggitt commented Aug 13, 2019

the history of kubectl cp with respect to secure extraction of files is not good (c.f. CVE-2018-1002100, CVE-2019-1002101, CVE-2019-11246, CVE-2019-11249)

even if the option is flag-gated, the capability would still have escalated the severity of those issues significantly if the placed files could be made executable.

I'd prefer we document how to use kubectl exec in combination with tar to accomplish advanced use cases like this. @tallclair looked into that, I believe, and might be able to shepherd some docs changes to that effect.

@tallclair
Copy link
Member

The basic command to copy from a pod using exec & tar is:

kubectl exec ${POD} -- tar cf - ${FILE} | tar xf -

Of course you can use any typical arguments to tar, in this case you might be interested in --preserve --same-owner.

More examples here: https://gist.github.com/tallclair/9217e2694b5fdf27b55d6bd1fda01b53

@soltysh
Copy link
Contributor

soltysh commented Aug 22, 2019

I agree with @liggitt here, we (as in sig-cli) need to reconsider kubectl cp implementation. The current causes more harm than good to both users and maintainers. I don't think that moving this to an optional plugin is a good approach, I'd prefer the rewrite option. I'll rise this problem during next sig-cli call (Wed, Aug 28th).

@liggitt liggitt removed this from the v1.16 milestone Aug 30, 2019
@liggitt
Copy link
Member

liggitt commented Aug 30, 2019

Discussed in sig-cli this week. The immediate priority is to resolve symlink handling issues in #82143 before considering expanding the surface area to include things like wildcard support and executable-permission preservation.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 28, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 28, 2019
@k8s-ci-robot
Copy link
Contributor

@evanphx: PR needs rebase.

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.

@evanphx
Copy link
Author

evanphx commented Dec 28, 2019 via email

@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

@atomd
Copy link

atomd commented May 26, 2020

tx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet