che: Most public images used in devfile registry do not work as the base for Che 7 workspaces on OpenShift

Description

OpenShift by default starts containers using a random UID for security purposes [1]. Since the UID to be used is not known at container creation time, there is no entry for the running user in /etc/passwd.

This can cause a multitude of problems:

  • The terminal is buggy: tab completion does not work, pressing up arrow does not work
    • Default terminal is always /bin/sh; starting bash results in the prompt I have no name!@workspaceid $
    • User does not have a home directory, and terminal does not open to /projects
  • Any program that depends on user id or home directory can have issues
  • Some configuration that relies on having a home directory is impossible, and behaviour in these cases is generally unpredictable.

The suggestions in [1] are

  • Any directory that needs to be accessed must have read/write permissions for the root group. This is not a problem for directories mounted as volumes
  • The /etc/passwd file should be writable by the root group. Then, an entrypoint script can execute something like
    if ! whoami &> /dev/null; then
      if [ -w /etc/passwd ]; then
        echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
      fi
    fi
    
    to set the current user correctly.

The second point above is the issue – images not created to run on OpenShift do not have a writeable /etc/passwd; further, since we normally overwrite container commands with sleep infinity or tail -f /dev/null, even images with an entrypoint that does what we need won’t execute the script by default. Note that this is what’s done when starting the default “Che 7” stack, which explains why it works.

At this time, I don’t see many good potential solutions; when running on OpenShift, the Che server could attempt to rewrite the recipe’s container commands with the script above followed by whichever non-terminating command we like, but this would still require using compatible images in the devfile registry. It could also result in confusing errors if we’re automatically rewriting entrypoints, and it’s difficult to specify a script like above in the yaml list format used for container commands.

I’m currently working with trying to implement the above, but if anyone has better ideas, it’d be great to hear them.

[1]- https://docs.okd.io/3.11/creating_images/guidelines.html#openshift-specific-guidelines

Reproduction Steps

Start a Che 7 workspace other than the default dev image (e.g. java-maven), open a terminal, and type whoami

OS and version:
Che 7 on any OpenShift

Diagnostics: In most images, we have e.g.:

$ id
uid=1075080000 gid=0(root) groups=0(root),1075080000

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

@amisevsk I reworded this issue a bit to make it Che 7 specific. WDYT about closing this one and creating a separate one for the general use-case of public images as a language runtime on OpenShift? I believe we need to cross-link this new general issue with https://github.com/openshift/origin/issues/23369

@ibuziuk, speaking of split discussion: https://github.com/eclipse/che-devfile-registry/pull/38#issuecomment-513729389

I’ll open a PR to use a more convenient base image.

@ibuziuk There is, but sadly the discussion is split over 4-5 PRs/issues.

The alpine image does not ship with bash installed, so the current patch breaks the image (sets default login shell for user to /bin/bash. The three options for fixing this are

  • Treat the angular devfile as a special case in patching (use /bin/sh instead of bash)
  • Switch the angular devfile to use the debian-based variant instead of alpine. Works but the image ends up significantly larger
    • This may not actually be an issue since most debian layers should be cached from other images
  • Create a new base image that installs bash on top of the default alpine-based image and use that as our base image in patching.

I think the second option (move to debian) is cleanest, but I haven’t tested or checked if there are further issues. It shouldn’t cause problems since we already use debian-based devfiles elsewhere.

PR patching all currently used images (except for one based off alpine): https://github.com/eclipse/che-devfile-registry/pull/38