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

Cleanup PATH variable mangling #1026

Closed
wants to merge 9 commits into from
Closed

Conversation

jerome-benoit
Copy link
Collaborator

@jerome-benoit jerome-benoit commented Jan 18, 2023

Description

Checklist

  • Code compiles correctly
  • Relevant tests were added (unit / contract / integration)
  • Relevant logs were added
  • Formatting and linting run locally successfully
  • All tests pass
  • UA review
  • Design is documented
  • Extended the README / documentation, if necessary
  • Open source is approved

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
@jerome-benoit jerome-benoit changed the title Fix npm link usage at build Fix npm packages global installation Jan 23, 2023
@@ -212,6 +212,12 @@ RUN set -ex \
&& python2.7 --version \
&& python3 --version

# Allow global npm packages install without sudo
RUN set -ex \
&& mkdir ${USER_HOME_DIR}/.npm-global \
Copy link
Member

Choose a reason for hiding this comment

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

wonder why USER/USER_HOME_DIR instead of MTA_USER/MTA_USER_HOME is used!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cut&paste typo ...

Thanks.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
RUN set -ex \
&& mkdir ${MTA_USER_HOME}/.npm-global \
&& chown -R ${MTA_USER}:${MTA_USER} ${MTA_USER_HOME}
ENV NPM_CONFIG_PREFIX ${MTA_USER_HOME}/.npm-global
Copy link
Member

Choose a reason for hiding this comment

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

according to the spec it's
ENV <key>=<value>
does it work without the equal too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Both are working. The current Dockerfile use space, so let's keep it consistent with the style already used.

&& mkdir ${MTA_USER_HOME}/.npm-global \
&& chown -R ${MTA_USER}:${MTA_USER} ${MTA_USER_HOME}
ENV NPM_CONFIG_PREFIX ${MTA_USER_HOME}/.npm-global

ENV PATH=$PATH:./node_modules/.bin HOME=${MTA_USER_HOME}
Copy link
Member

Choose a reason for hiding this comment

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

on the image i used i do not have this path entry:

mta@63fceb6d640d:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

is it intended that the root user has the home of mta?

root@b40df04c7063:/project# id
uid=0(root) gid=0(root) groups=0(root)
root@b40df04c7063:/project# echo $HOME
/home/mta

Copy link
Collaborator Author

@jerome-benoit jerome-benoit Jan 23, 2023

Choose a reason for hiding this comment

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

It's not intended and a genuine security bug, and as well as the HOME env variable redefinition.
The PATH env variable mangling is buggy as hell in that Dockerfile. I plan to fix it but in another PR.

Thanks.

@rodibrin
Copy link
Member

Does this PR solve #1018 ?

How does this PR relate to #1023 ?

@jerome-benoit
Copy link
Collaborator Author

jerome-benoit commented Jan 23, 2023

Does this PR solve #1018 ?

As stated in the PR description, yes, but for currently supported node.js/java versions combination. It does not include node 14 and java 8.

How does this PR relate to #1023 ?

That PR is a duplicate of #1013 unrelated to the issue fixed here.
It's relevant for you as it reintroduces the support for the version combination you are using.
The original image with the issue have been built with the previous Dockerfile before its rewrite and has serious security issues. In the meantime, you can use the one you've successfully tested to work that introduce the fix in that PR until the java 8 support is re-added and that fix goes in. It does not contain the insecure chmod -R 777 usage in #1023.

@rodibrin
Copy link
Member

rodibrin commented Jan 24, 2023

As stated in the PR description, yes, but for currently supported node.js/java versions combination. It does not include node 14 and java 8.

Which node/java versions does it cover. we offer the following to the customer:

  • devxci/mbtci-java11-node14:
  • devxci/mbtci-java11-node16:
  • devxci/mbtci-java11-node18:
  • devxci/mbtci-java8-node16:
  • devxci/mbtci-java8-node18:
  • devxci/mbtci-java8-node14:

In the meantime, you can use the one you've successfully tested to ...

Unfortunately, the CICD service doesn't allow to easily switch to an arbitrary image. So we have to wait for the release of #1023, right?

@jerome-benoit
Copy link
Collaborator Author

jerome-benoit commented Jan 24, 2023 via email

Copy link
Member

@rodibrin rodibrin left a comment

Choose a reason for hiding this comment

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

LGTM

@jerome-benoit
Copy link
Collaborator Author

jerome-benoit commented Jan 31, 2023

LGTM

@young-yang03: I think the HOME variable override is causing issues at creating the directory structure under NPM_CONFIG_PREFIX path. I will remove it in that PR.

Since that PR can't cause any regressions as as long as npm -g is used, it's fine to merge it, ship the images and let @rodibrin confirm it works.

@jerome-benoit
Copy link
Collaborator Author

jerome-benoit commented Jan 31, 2023

LGTM

@rodibrin: Have you also tested the node 16 java variant: https://hub.docker.com/repository/docker/fraggle0/mbt-node16-java8-docker/general?
If not, could you please confirm (or infirm) it works?

@young-yang03 young-yang03 mentioned this pull request Feb 1, 2023
9 tasks
@rodibrin
Copy link
Member

rodibrin commented Feb 2, 2023

Test of
fraggle0/mbt-node16-java8-docker:latest 0f64f79118ce 9 days ago 665MB
failed:

npm ERR! code 254
npm ERR! path /project/node_modules/hana-cli
npm ERR! command failed
npm ERR! command sh -c -- npm link @sap/cds-dk --local
npm ERR! npm ERR! code ENOENT
npm ERR! npm ERR! syscall lstat
npm ERR! npm ERR! path /home/mta/.npm-global/lib
npm ERR! npm ERR! errno -2
npm ERR! npm ERR! enoent ENOENT: no such file or directory, lstat '/home/mta/.npm-global/lib'
npm ERR! npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! npm ERR! enoent
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/mta/.npm/_logs/2023-02-02T09_12_44_959Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/mta/.npm/_logs/2023-02-02T08_55_30_802Z-debug-0.log
mta@ba01bd395d75:/project$ ls -ali /home/mta/
total 48
1926508 drwxrwxrwx 1 mta  mta  4096 Feb  2 09:12 .
1926507 drwxr-xr-x 1 root root 4096 Jan 16 22:47 ..
1926509 -rw-r--r-- 1 mta  mta   220 Mar 27  2022 .bash_logout
1926510 -rw-r--r-- 1 mta  mta  3526 Mar 27  2022 .bashrc
1934075 drwxr-xr-x 3 mta  mta  4096 Feb  2 09:12 .cache
1934070 drwx------ 3 mta  mta  4096 Feb  2 09:12 .hdb
1926511 drwxr-xr-x 1 mta  mta  4096 Feb  2 08:55 .npm
1926517 drwxr-xr-x 2 mta  mta  4096 Jan 23 10:52 .npm-global
1926518 -rw-r--r-- 1 mta  mta   807 Mar 27  2022 .profile
mta@ba01bd395d75:/project$ ls -ali /home/mta/.npm-global/
total 12
1926517 drwxr-xr-x 2 mta mta 4096 Jan 23 10:52 .
1926508 drwxrwxrwx 1 mta mta 4096 Feb  2 09:12 ..

@jerome-benoit
Copy link
Collaborator Author

jerome-benoit commented Feb 2, 2023

Test of fraggle0/mbt-node16-java8-docker:latest 0f64f79118ce 9 days ago 665MB failed:

Ok, thanks. I'm pushing the test images with the directory pre-creation. Dunno why npm does not properly populate it with latest version.

Could you please re-test?

@rodibrin
Copy link
Member

rodibrin commented Feb 2, 2023

test succeeded:

fraggle0/mbt-node16-java8-docker latest bcc6a780a618 3 hours ago 665MB

@jerome-benoit jerome-benoit changed the title Fix npm packages global installation Cleanup PATH variable mangling Feb 7, 2023
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
@young-yang03 young-yang03 deleted the jerome-benoit-patch-1 branch September 22, 2023 07:01
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.

3 participants