Skip to content

Run all processes with seluser instead of root #477

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 16 commits into from
Jun 6, 2017
Merged

Run all processes with seluser instead of root #477

merged 16 commits into from
Jun 6, 2017

Conversation

diemol
Copy link
Member

@diemol diemol commented May 2, 2017

While checking #474, I found that in some images the processes are run by seluser and in other ones they are run with seluser and root (specially in the debug ones). E.g.:

docker run --rm -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm --shm-size=1g selenium/standalone-chrome-debug:3.4.0-chromium

docker exec -ti objective_stonebraker bash

root@be3eb04ea476:/# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  20996  3280 ?        Ss+  14:44   0:00 /bin/bash /opt/bin/entry_point.sh
root        21  0.0  0.0  20992  1616 ?        S+   14:44   0:00 /bin/bash /opt/bin/entry_point.sh
root        26  0.0  0.0   4508  1632 ?        S+   14:44   0:00 /bin/sh /usr/bin/xvfb-run -n 99 --server-args=-screen 0 1360x1020x24 -ac +extension RANDR java -jar /opt/selenium/se
root        38  0.8  2.6 217096 54464 ?        Sl+  14:44   0:00 Xvfb :99 -screen 0 1360x1020x24 -ac +extension RANDR -nolisten tcp -auth /tmp/xvfb-run.l7EYS6/Xauthority
root        43  3.0  2.3 2966204 48284 ?       Sl+  14:44   0:01 java -jar /opt/selenium/selenium-server-standalone.jar
root        56  1.8  0.5 114212 10972 ?        S+   14:44   0:00 fluxbox -display :99.0
root        57  0.2  0.6 113380 13536 ?        S+   14:44   0:00 x11vnc -forever -usepw -shared -rfbport 5900 -display :99.0
root        78  1.0  0.1  21196  3672 ?        Ss   14:45   0:00 bash
root        87  0.0  0.1  37364  3276 ?        R+   14:45   0:00 ps -aux

I went through all the Dockerfiles and entry_point.sh and improved them so all the processes run now with seluser.

I executed the tests and they passed, I also tested it so the fix done in #459 and #469 don't get lost.

@ddavison
I will add some comments next to the commits to make this PR easier to review.

@elgalu, can you please also help to review this PR?

Base/Dockerfile Outdated
#==========
RUN mkdir -p /home/seluser/selenium \
&& wget --no-verbose https://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar \
-O /home/seluser/selenium/selenium-server-standalone.jar
Copy link
Member Author

@diemol diemol May 2, 2017

Choose a reason for hiding this comment

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

The Selenium related files are placed in a seluser home subfolder, called /home/seluser/selenium/, so the seluser is owner by default.

@@ -1,3 +1,5 @@
USER seluser

Copy link
Member Author

Choose a reason for hiding this comment

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

Running all commands as seluser, so the ENV vars a present for this user always.

@@ -61,7 +61,7 @@ standalone_firefox: generate_standalone_firefox firefox
cd ./StandaloneFirefox && docker build $(BUILD_ARGS) -t $(NAME)/standalone-firefox:$(VERSION) .

generate_standalone_firefox_debug:
cd ./StandaloneDebug && ./generate.sh StandaloneFirefoxDebug standalone-firefox Firefox $(VERSION) $(NAMESPACE) $(AUTHORS)
cd ./StandaloneDebug && ./generate.sh StandaloneFirefoxDebug node-firefox-debug Firefox $(VERSION) $(NAMESPACE) $(AUTHORS)
Copy link
Member Author

Choose a reason for hiding this comment

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

Building the StandaloneDebug images based on the NodeDebug images, makes the build faster.

ENV NODE_APPLICATION_NAME ""

# Following line fixes https://github.com/SeleniumHQ/docker-selenium/issues/87
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
Copy link
Member Author

@diemol diemol May 2, 2017

Choose a reason for hiding this comment

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

Leaving these ENV vars in the NodeBase image, they were duplicated in other docker files.
Exporting them with seluser, so they are present by default in the entry points.

env | cut -f 1 -d "=" | sort > asroot
sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
sudo -E -i -u seluser \
"$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done)" \
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a workaround to export the ENV vars present in the root user and not present in the seluser. Since all ENV vars are now exported with the seluser, this is not needed anymore.

#!/bin/bash
#
# IMPORTANT: Change this file only in directory NodeDebug!

Copy link
Member Author

Choose a reason for hiding this comment

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

File added to handle the entry_point.sh in the same way it is done for the StandaloneDebug images. Things get changed here and the file is copied to the appropriate folders.

@@ -27,31 +27,11 @@ RUN wget --no-verbose -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geck
&& chmod 755 /opt/geckodriver-$GECKODRIVER_VERSION \
&& ln -fs /opt/geckodriver-$GECKODRIVER_VERSION /usr/bin/geckodriver

#========================
Copy link
Member Author

Choose a reason for hiding this comment

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

All these ENV vars are now exported in the NodeBase image.

@@ -1,55 +0,0 @@
FROM selenium/node-firefox:3.4.0-chromium
Copy link
Member Author

Choose a reason for hiding this comment

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

This file was in the repo, but not used anywhere. The Dockerfile comes from the NodeDebug folder.

sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
sudo -E -i -u seluser \
"$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done)" \
DISPLAY=$DISPLAY \
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a workaround to export the ENV vars present in the root user and not present in the seluser. Since all ENV vars are now exported with the seluser, this is not needed anymore.

@@ -29,19 +29,17 @@ if [ ! -z "$SE_OPTS" ]; then
echo "appending selenium options: ${SE_OPTS}"
fi

# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing this TODO since the browserSideLog (which the URL refers to), should not be used anymore according to the Selenium Grid code

@elgalu
Copy link
Member

elgalu commented May 4, 2017

👍 on my side, I run a couple of tests in my OSX host and also in my Linux host, using chrome and firefox standalone images built from Diego's fork.

@ddavison
Copy link
Member

ddavison commented May 4, 2017

i'd like to merge this in at the same time as i get the new testing in place. working on it as we speak, so hopefully soon we'll get this in :)

@ddavison
Copy link
Member

ddavison commented Jun 6, 2017

the only thing that concerns me with these changes, are programs that have their own arbitrary user for security purposes, e.g.: OpenShift. We can fix these on an adhoc basis, but we can probably expect to see some issues being created regarding this.

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