-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: changing owner while creating container for download support (#…
…2056) Signed-off-by: Viet Nguyen Duc <[email protected]>
- Loading branch information
Showing
17 changed files
with
213 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
FROM ubuntu:jammy-20231004 | ||
LABEL authors="Selenium <[email protected]>" | ||
|
||
# Arguments to define the version of dependencies to download | ||
ARG VERSION | ||
ARG RELEASE=selenium-${VERSION} | ||
ARG OPENTELEMETRY_VERSION=1.31.0 | ||
ARG GRPC_VERSION=1.59.0 | ||
|
||
#Arguments to define the user running Selenium | ||
ARG SEL_USER=seluser | ||
ARG SEL_PASSWD=secret | ||
ARG SEL_UID=1200 | ||
ARG SEL_GID=1201 | ||
|
||
USER root | ||
#================================================ | ||
# Customize sources for apt-get | ||
#================================================ | ||
|
@@ -33,6 +44,7 @@ RUN apt-get -qqy update \ | |
curl \ | ||
supervisor \ | ||
gnupg2 \ | ||
libnss3-tools \ | ||
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \ | ||
&& sed -i 's/securerandom\.source=file:\/dev\/random/securerandom\.source=file:\/dev\/urandom/' ./usr/lib/jvm/java-11-openjdk-amd64/conf/security/java.security | ||
|
||
|
@@ -45,64 +57,92 @@ RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime && \ | |
dpkg-reconfigure -f noninteractive tzdata && \ | ||
cat /etc/timezone | ||
|
||
#====================================== | ||
# Configure environement | ||
#====================================== | ||
ENV SEL_USER=${SEL_USER} | ||
ENV SEL_UID=${SEL_UID} | ||
ENV SEL_GID=${SEL_GID} | ||
ENV HOME=/home/${SEL_USER} | ||
ENV SEL_DIR=/opt/selenium | ||
ENV EXTERNAL_JARS=/external_jars | ||
ENV SE_DOWNLOAD_DIR=${HOME}/Downloads | ||
|
||
# Copy a script that we will use to correct permissions after running certain commands | ||
COPY fix-permissions /usr/local/bin/fix-permissions | ||
RUN chmod a+rx /usr/local/bin/fix-permissions | ||
|
||
#======================================== | ||
# Add normal user and group with passwordless sudo | ||
#======================================== | ||
RUN groupadd seluser \ | ||
--gid 1201 \ | ||
&& useradd seluser \ | ||
--create-home \ | ||
--gid 1201 \ | ||
--shell /bin/bash \ | ||
--uid 1200 \ | ||
&& usermod -a -G sudo seluser \ | ||
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \ | ||
&& echo 'seluser:secret' | chpasswd | ||
ENV HOME=/home/seluser | ||
RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su \ | ||
&& sed -i.bak -e 's/^%admin/#%admin/' /etc/sudoers \ | ||
&& sed -i.bak -e 's/^%sudo/#%sudo/' /etc/sudoers \ | ||
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers | ||
|
||
RUN groupadd ${SEL_USER} \ | ||
--gid ${SEL_GID} \ | ||
&& useradd ${SEL_USER} \ | ||
--no-log-init \ | ||
--create-home \ | ||
--gid ${SEL_GID} \ | ||
--shell /bin/bash \ | ||
--uid ${SEL_UID} \ | ||
&& chmod g+w /etc/passwd \ | ||
&& echo "${SEL_USER}:${SEL_PASSWD}" | chpasswd | ||
|
||
#====================================== | ||
# Create directories needed | ||
#====================================== | ||
RUN mkdir -p ${HOME}/.mozilla ${HOME}/.cache \ | ||
${SEL_DIR} ${SEL_DIR}/assets \ | ||
/var/run/supervisor /var/log/supervisor \ | ||
${EXTERNAL_JARS} \ | ||
${SE_DOWNLOAD_DIR} | ||
|
||
#====================================== | ||
# Add Grid check script | ||
#====================================== | ||
COPY check-grid.sh entry_point.sh /opt/bin/ | ||
COPY --chown="${SEL_UID}:${SEL_GID}" check-grid.sh entry_point.sh /opt/bin/ | ||
|
||
#====================================== | ||
# Add Supervisor configuration file | ||
#====================================== | ||
COPY supervisord.conf /etc | ||
|
||
#========== | ||
# Selenium & relaxing permissions for OpenShift and other non-sudo environments | ||
# Selenium | ||
#========== | ||
RUN mkdir -p /opt/selenium /opt/selenium/assets /var/run/supervisor /var/log/supervisor \ | ||
&& touch /opt/selenium/config.toml \ | ||
&& chmod -R 777 /opt/selenium /opt/selenium/assets /var/run/supervisor /var/log/supervisor /etc/passwd \ | ||
RUN touch ${SEL_DIR}/config.toml \ | ||
&& wget --no-verbose https://github.com/SeleniumHQ/selenium/releases/download/${RELEASE}/selenium-server-${VERSION}.jar \ | ||
-O /opt/selenium/selenium-server.jar \ | ||
&& chgrp -R 0 /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \ | ||
&& chmod -R g=u /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \ | ||
&& setfacl -Rm u:seluser:rwx /opt /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor | ||
-O ${SEL_DIR}/selenium-server.jar | ||
|
||
#===== | ||
# Download observability related jaegar jars and make them available in a separate directory | ||
# so that the container can skip downloading them everytime it comes up | ||
#===== | ||
RUN curl -fLo /tmp/cs https://github.com/coursier/launchers/raw/master/coursier \ | ||
&& chmod +x /tmp/cs \ | ||
&& mkdir -p /external_jars \ | ||
&& chmod -R 775 /external_jars | ||
&& chmod +x /tmp/cs | ||
|
||
RUN /tmp/cs fetch --classpath --cache /external_jars \ | ||
io.opentelemetry:opentelemetry-exporter-otlp:1.31.0 \ | ||
io.opentelemetry:opentelemetry-exporter-jaeger:1.31.0 \ | ||
io.grpc:grpc-netty:1.59.0 > /external_jars/.classpath.txt | ||
|
||
RUN chmod 664 /external_jars/.classpath.txt | ||
RUN /tmp/cs fetch --classpath --cache ${EXTERNAL_JARS} \ | ||
io.opentelemetry:opentelemetry-exporter-otlp:${OPENTELEMETRY_VERSION} \ | ||
io.opentelemetry:opentelemetry-exporter-jaeger:${OPENTELEMETRY_VERSION} \ | ||
io.grpc:grpc-netty:${GRPC_VERSION} > ${EXTERNAL_JARS}/.classpath.txt | ||
RUN rm -fr /root/.cache/* | ||
|
||
# Change ownership of directories | ||
RUN chown -R "${SEL_USER}:${SEL_GID}" ${HOME} ${SEL_DIR} ${SEL_DIR}/assets ${EXTERNAL_JARS} ${SE_DOWNLOAD_DIR} /var/run/supervisor /var/log/supervisor \ | ||
&& fix-permissions ${HOME} ${SEL_DIR} ${SEL_DIR}/assets ${EXTERNAL_JARS} ${SE_DOWNLOAD_DIR} /var/run/supervisor /var/log/supervisor | ||
|
||
#========== | ||
# Relaxing permissions for OpenShift and other non-sudo environments | ||
#========== | ||
RUN chmod g=u /etc/passwd | ||
|
||
#=================================================== | ||
# Run the following commands as non-privileged user | ||
#=================================================== | ||
USER 1200:1201 | ||
USER ${SEL_UID}:${SEL_GID} | ||
|
||
# Boolean value, maps "--bind-host" | ||
ENV SE_BIND_HOST false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
set -e | ||
# Run this with USER root only | ||
for d in "$@"; do | ||
find "${d}" \ | ||
! \( \ | ||
-group "${SEL_GID}" \ | ||
-a -perm -g+rwX \ | ||
\) \ | ||
-exec chgrp -R "${SEL_GID}" -- {} \+ \ | ||
-exec chmod -R g+rwX -- {} \+ | ||
# setuid, setgid *on directories only* | ||
find "${d}" \ | ||
\( \ | ||
-type d \ | ||
-a ! -perm -6000 \ | ||
\) \ | ||
-exec chmod -R +6000 -- {} \+ | ||
# Relaxing permissions for OpenShift and other non-sudo environments | ||
chmod -R u+x "${d}" | ||
chgrp -R 0 "${d}" | ||
chmod -R g=u "${d}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.