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

Set SHELL env var in launcher if unset to avoid issues in Code's shell detection #284

Merged
merged 4 commits into from
Oct 17, 2023

Conversation

amisevsk
Copy link
Contributor

What does this PR do?

If the SHELL environment variable is unset when running the Code launcher, set it:

  • If we detect that bash is installed, to /bin/bash
  • Otherwise, fallback to setting it to /bin/sh

This is necessary due to shell-detection logic within Code itself, which will fallback to parsing /etc/passwd when SHELL is not set (see [1]). When running on e.g. OpenShift with a normal container, cri-o will add an /etc/passwd entry for the current user with /sbin/nologin, which results the terminal failing to launch.

What issues does this PR fix?

Closes eclipse-che/che#22524

How to test this PR?

Changes from this PR are built into quay.io/amisevsk/che-code:dev via the following Dockerfile:

FROM registry.access.redhat.com/ubi8/nodejs-18:1-71 as launcher-builder

USER root

COPY . /checode-launcher
WORKDIR /checode-launcher

RUN npm install -g yarn@1.22.17

RUN yarn \
    && mkdir /test-launcher \
    && cp -r out/src/*.js /test-launcher \
    && chgrp -R 0 /test-launcher && chmod -R g+rwX /test-launcher

FROM quay.io/che-incubator/che-code:next
COPY --from=launcher-builder --chown=0:0 /test-launcher /checode-linux-libc/launcher

To test the changes on an existing workspace, edit the DevWorkspace yaml on the cluster, updating the .spec.contributions field:

  spec:
    contributions:
      - name: editor
        kubernetes:
          name: che-code-java-maven
+       components:
+         - container:
+             image: 'quay.io/amisevsk/che-code:dev'
+           name: che-code-injector

(This will use quay.io/amisevsk/che-code:dev in place of the default injector image)

We should verify three cases before merging:

  1. Samples that do not set the SHELL environment variable have It is not possible to start a terminal when workspace started from a devfile from the registry.devfile.io eclipse-che/che#22524 resolved.
  2. It's still possible to override the shell by setting the SHELL env var in the devfile or container
  3. Default Che samples are unimpacted

Before launching Code, if the SHELL environment variable is unset, set
it to something before launching:

* If SHELL is unset and /bin/bash is installed, use that
* Otherwise, fall back to /bin/sh as a 'safe' option

This is necessary to avoid internal shell-detection logic in Code, which
reads /etc/passwd when SHELL is not set. This is an issue when running
in e.g. OpenShift, where cri-o will add a user entry to /etc/passwd
containing /sbin/nologin as the login shell.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
@github-actions
Copy link

github-actions bot commented Oct 11, 2023

Click here to review and test in web IDE: Contribute

@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

1 similar comment
@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

@@ -66,6 +66,17 @@ export class VSCodeLauncher {
env.NODE_EXTRA_CA_CERTS = NODE_EXTRA_CERTIFICATE;
}

if (!env.SHELL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about checking if the user shell (in /etc/passwd) is /sbin/nologin or not? If cri-o hasn't patched /etc/passwd (i.e. containerd is the container runtime) there may be a valid shell for current user anyway.

Beyond that I have tested the PR using image quay.io/che-incubator-pull-requests/che-code:pr-284-amd64 and the quarkus devfile from registry.devfile.io and the problem got solved 🎉 . I had an unrelated problem though and I have filed a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is probably a good idea -- I didn't initially do it since I was trying to keep it simple (since IIRC the default UDI image sets SHELL) but better safe than sorry :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR now. If /etc/passwd contains anything other than /sbin/nologin, we no longer override it by setting SHELL if it's not already set.

@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

2 similar comments
@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

@amisevsk
Copy link
Contributor Author

@vitaliy-guliy @l0rd Updated this PR after Mario's suggestion, please take a look before I merge.

When launching Code, add an additional check to read /etc/passwd and
check if the user has a (non-/sbin/nologin) shell defined there. If
/etc/passwd contains any other shell (e.g. /bin/zsh, /bin/bash, etc.),
then let Code read that shell from /etc/passwd instead of overriding it
by setting the SHELL environment variable.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

@amisevsk amisevsk merged commit b71a618 into che-incubator:main Oct 17, 2023
2 checks passed
@amisevsk amisevsk deleted the avoid-noshell branch October 17, 2023 16:18
@devstudio-release
Copy link

Build 3.10 :: code_3.x/959: Console, Changes, Git Data

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.10 :: get-sources-rhpkg-container-build_3.x/4794: FAILURE

code : 3.x ::
; copied to quay

@github-actions
Copy link

Pull Request images published ✨
image: quay.io/che-incubator-pull-requests/che-code:pr-284-amd64
Dev image: quay.io/che-incubator-pull-requests/che-code-dev:pr-284-dev-amd64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It is not possible to start a terminal when workspace started from a devfile from the registry.devfile.io
4 participants