che icon indicating copy to clipboard operation
che copied to clipboard

Can't run as root

Open filips123 opened this issue 7 years ago • 12 comments

Describe the bug

I can't run commands as root or use su.

On default PHP simple stack, this happens:

bash-4.4 /projects $ sudo su
bash: sudo: command not found
bash-4.4 /projects $ su
su: must be run from a terminal

On default Python stack, I can run su, but I can't use it because I don't know the password:

bash-5.0 /projects $ sudo su
bash: sudo: command not found
bash-5.0 /projects $ su
Password: 
su: Authentication failure

Expected behavior

I should be able to run commands as root or use su.

Steps to reproduce

Runtime

  • Simple PHP stack
  • Python stack

Environment

Openshift Eclipse Che

Che version

Che-Theia@ad8e4f4 using Theia@f255f5a8

filips123 avatar Dec 01 '19 19:12 filips123

It isn't supposed to run anything in behalf of root user. If you need something you have to use a dockerimage with preinstalled software and add it to your workspace configuration (or replace).

components:
  - mountSources: true
    type: dockerimage
    alias: dev
    image: '<YOUR_IMAGE>'

tolusha avatar Dec 02 '19 08:12 tolusha

It isn't supposed to run anything in behalf of root user.

Why? It is useful if you want to quickly install some packages, change some configuration, run other commands...

In previous Che versions (actually Codenvy.io), root also worked.

filips123 avatar Dec 02 '19 08:12 filips123

Since containers are immutable, installing packages into a container is a strange use-case -- you would have to redo it on every startup. The recommended flow in docker is to configure your container to have all required packages installed in the image itself.

Further, containers as root is a significant security risk, so it is generally not supported by default in Che (it's not even possible to do on OpenShift, and advised against in Kubernetes).

amisevsk avatar Dec 03 '19 16:12 amisevsk

The recommended flow in docker is to configure your container to have all required packages installed in the image itself.

How can I configure a container to install packages in the image itself?

Is the only solution (that works on OpenShift) to create an image and publish it to Docker Hub? Or is there any other solution which doesn't require to publish images to Docker Hub?

Publically releasing new image version each time you want to change/add some system package isn't the best solution...

Since containers are immutable, installing packages into a container is a strange use-case -- you would have to redo it on every startup.

Actually, in Codenvy.io, there was some feature/bug that allowed you to save snapshot of container and restore it on next startup.

I agree that installing packages after container was built is not the best solution, but having to additionally publish images to Docker Hub is also quite complicating.

filips123 avatar Dec 03 '19 19:12 filips123

The typical way to include packages in an image is to install them at image build time, e.g. the plugin registry requires a few packages.

For running on a cluster (be it k8s or OpenShift), you'll in general need to make an image available somewhere -- it doesn't have to be dockerhub; you can always deploy your own container regiistry or use e.g. quay.io. In some cases, you can use the cluster's internal registry, but that is more error prone in general. If you are concerned about publicly sharing your images, dockerhub allows one private repository.

Publically releasing new image version each time you want to change/add some system package isn't the best solution...

You don't need to release a completely new image, tags on containers are mutable; for instance, image quay.io/eclipse/che-machine-exec:nightly is updated every day and devfiles in the nightly builds of the Che devfile registry also reference nightly builds of images. One of the main benefits of containers is that they can independently -- if you and I both pull the machine-exec image, we'll be running the same environment. For example, I use the amisevsk/che-server:dev for all of my development in Eclipse Che.

amisevsk avatar Dec 04 '19 14:12 amisevsk

we need to be able to run as root. Setting CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_RUN__AS__USER=0 works

mingfang avatar Dec 10 '19 16:12 mingfang

Issues go stale after 180 days of inactivity. lifecycle/stale issues rot after an additional 7 days of inactivity and eventually close.

Mark the issue as fresh with /remove-lifecycle stale in a new comment.

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

Moderators: Add lifecycle/frozen label to avoid stale mode.

che-bot avatar Jun 11 '20 14:06 che-bot

we need to be able to run as root. Setting CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_RUN__AS__USER=0 works

How did you implement it? Can you kindly let me know? I am using operator type installer.

sushant08 avatar Jun 11 '20 17:06 sushant08

we need to be able to run as root. Setting CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_RUN__AS__USER=0 works

@mingfang Can you please let me know how you achieved this?

sushant08 avatar Jun 15 '20 16:06 sushant08

@sushant08 Hope the following doc will help you https://www.eclipse.org/che/docs/che-7/advanced-configuration-options-for-the-che-server-component/

sleshchenko avatar Jun 16 '20 09:06 sleshchenko

@sushant08 I deploy Eclipse Che using my own Terraform plugin https://github.com/mingfang/terraform-provider-k8s and module https://github.com/mingfang/terraform-k8s-modules/tree/master/modules/eclipse-che.

Here is the specific lines that configures it to run workspaces as root. https://github.com/mingfang/terraform-k8s-modules/blob/master/examples/eclipse-che/main.tf#L51

mingfang avatar Jun 17 '20 01:06 mingfang

I think I'm confused, so eclipse-che is not useful for tinkering with systems before you make them docker images?

Kreijstal avatar Jun 24 '20 14:06 Kreijstal