Skip to content

Added --privileged flag to kubectl run #90569

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

Merged
merged 1 commit into from
Jun 10, 2020

Conversation

brianpursley
Copy link
Member

@brianpursley brianpursley commented Apr 28, 2020

What type of PR is this?
/kind feature

What this PR does / why we need it:
Adds --privileged flag to kubectl run

Which issue(s) this PR fixes:
Fixes kubernetes/kubectl#721

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Added --privileged flag to kubectl run

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:



EDIT: I'm adding this here because there were some questions/concerns about the security implications of this:

Just to be clear, this flag only enables, via a command-line flag, what you were already able to do using yaml, and it only does this for kubectl run which is for running one-off pods, not intended for deploying production workloads.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. 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. labels Apr 28, 2020
@brianpursley
Copy link
Member Author

/sig cli
/priority important-soon

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. area/kubectl and removed 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. labels Apr 28, 2020
@brianpursley
Copy link
Member Author

/retest

@zhouya0
Copy link
Contributor

zhouya0 commented Apr 29, 2020

/lgtm
But I have to say --privileged is a dangerous flag and has security risks, I would like to hear more from the community.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 29, 2020
@brianpursley
Copy link
Member Author

/lgtm
But I have to say --privileged is a dangerous flag and has security risks, I would like to hear more from the community.

Agreed it is not a production use thing, or should not be.

The functionally already exists if you create your pod using yaml. This just adds a way to use it from the command line.

I too am interested if others have opinions on if this is too dangerous to make convenient.

@brianpursley
Copy link
Member Author

/retest

2 similar comments
@brianpursley
Copy link
Member Author

/retest

@brianpursley
Copy link
Member Author

/retest

@brianpursley
Copy link
Member Author

/assign @mengqiy

@brianpursley
Copy link
Member Author

This doesn't really add or change any new security-related functionality, it just makes it more convenient to do what you can already do.

For example:

The existing way to do this is:

kubectl run wanmap-fake-wan --image=bradmwalker/wanmap -it --rm --overrides='{"spec": {"metadata": {"name": "wanmap-fake-wan"}, "template": {"spec": {"containers": [{"name": "wanmap-fake-wan", "image": "bradmwalker/wanmap", "command": ["/bin/sh"], "tty": true, "stdin": true, "securityContext": {"privileged": true} }]}}}}'

This PR lets you just do this instead:

kubectl run wanmap-fake-wan --image=bradmwalker/wanmap -it --rm --privileged

@zhouya0 do you have anyone else in mind who might have some thoughts on this? I can add them.

/cc @mengqiy

@k8s-ci-robot k8s-ci-robot requested a review from mengqiy May 14, 2020 13:00
@zhouya0
Copy link
Contributor

zhouya0 commented May 15, 2020

Looks great, but I believe @mengqiy is not available since he is not active for a long time. You may ask more approvers to review this.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 16, 2020
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 18, 2020
@brianpursley
Copy link
Member Author

Rebased

@brianpursley
Copy link
Member Author

/retest

@brianpursley
Copy link
Member Author

/assign @soltysh

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Jun 9, 2020
@brianpursley
Copy link
Member Author

/test pull-kubernetes-e2e-gce-ubuntu-containerd

@k8s-ci-robot k8s-ci-robot merged commit 5b76272 into kubernetes:master Jun 10, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Jun 10, 2020
@krmayankk
Copy link

is this adding privileged to the debug container or just the default deployment that gets created with run ?

@thomasfricke
Copy link
Contributor

Copying ideas from docker should always be questioned.

I spend a lot of time explaining to developers that there docker compose files are inherently insecure. Most of the time the host system is modified on their laptops. Most time the containers use privileges. Now you copied this mess into kubernetes.

Adding privileges with a simple flag will cause real damages in production.
This is the most stupid idea since allowing to run applications on windows as admin.

This will keep me busy for the next ten years.

What you really should do is add PSP as a default everywhere.

@sftim
Copy link
Contributor

sftim commented Jun 14, 2020

Worried about the impact? You can suggest a revision against the dev-1.19 branch in k/website with a cautionary note where it makes sense.

(BTW, if you want to update the generated reference docs, those are based on the upstream code).

@brianpursley
Copy link
Member Author

@krmayankk This flag just does the equivalent of setting privleged: true in your container's security context.

So for example, if I do this:

kubectl run test --image=nginx --privileged

And then look at the pod...

kubectl get pod test -o yaml

It shows:

...
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: test
    resources: {}
    securityContext:
      privileged: true
...

Starting in Kubernetes 1.19, run no longer will create a deployment (you would use kubectl create deployment for that now). So to your question about whether it affects deployments, no it would not.

@brianpursley
Copy link
Member Author

Just to be clear, this flag only enables, via a command-line flag, what you were already able to do using yaml, and it only does this for kubectl run which is for running one-off pods, not intended for deploying production workloads.

@zhouya0
Copy link
Contributor

zhouya0 commented Jun 15, 2020

@thomasfricke If you are worrying about windows privileged problems, it's not related to this PR because windows pods must have:

    securityContext:
        windowsOptions:

to enable admin.

@garloff
Copy link

garloff commented Jun 17, 2020

Shouldn't it at least spit out a big fat warning?
This option makes insecure deployments easier, so let's ensure as much as possible that this is not done unconsciously.

@soltysh
Copy link
Contributor

soltysh commented Jun 17, 2020

I wouldn't be worried about your concern @garloff, currently kubectl run can only create pods, not deployments nor higher level resources. This is more like an entry-level command to help come up to speed for users coming from docker/podman/other container engine where that options is available. We rarely if at all spit warnings and using this requires explicit --privileged flag usage. Also, I'd expect privileged is properly limited at the cluster level so that not everyone has access to it, by default. We are targeting local devs with this, rather than production clusters.

@erikbgithub
Copy link

Hackers will probably avoid this because the documentation clearly says it's for debugging purposes. We all know, hackers are the first to read the docs and will always abide by it.

@brianpursley brianpursley deleted the kubectl-721 branch June 21, 2020 22:59
@akin-ozer
Copy link

akin-ozer commented Jun 26, 2020

@erikbgithub It is mentioned in this issue that you can already do this with convoluted command. This change won't affect people with malicious intent but help people adopt Kubernetes faster. There are lots of workloads needs to be run on privileged mode, mostly legacy ones and I believe this will only increase adoption.

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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/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.

kubectl run supports --privileged