diff --git a/SSH/Dockerfile b/SSH/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..a231169548fb5fafcc7fb6aa4c0513dc6543b543 --- /dev/null +++ b/SSH/Dockerfile @@ -0,0 +1,28 @@ +FROM base +MAINTAINER Stefano Alberto Russo <stefano.russo@inaf.it> + +# Switch to root +USER root + +# Install OpenSSH +RUN apt-get install openssh-server -y + +# Set a fixed password for metauser (will be changed in the entypoint) +RUN echo "metauser:metapass" | chpasswd + +# Set entrypoint command +COPY files/entrypoint.sh /entrypoint.sh +RUN chmod 755 /entrypoint.sh +ENV DEFAULT_ENTRYPOINT_COMMAND="/entrypoint.sh" + +# Fix home permissions +RUN chmod 777 /home + +# Set user (mainly for Singularity) +USER metauser + +# Set container name +ENV CONTAINER_NAME='SSH' + + + diff --git a/SSH/build.sh b/SSH/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..12c8b48ae0d8b2e04f5af47900c892ea84671a1f --- /dev/null +++ b/SSH/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build . -t ssh diff --git a/SSH/files/entrypoint.sh b/SSH/files/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..02db98c1295b8ae0aaf5d9d785e9f02f75bb5a0e --- /dev/null +++ b/SSH/files/entrypoint.sh @@ -0,0 +1,39 @@ +#/bin/bash + +# Set port +if [ "x$BASE_PORT" == "x" ]; then + BASE_PORT=22 +fi + +# Set password +if [ "x$AUTH_PASS" != "x" ]; then + echo "[INFO] Setting linux password" # In the Dockerflie remove the -e + echo -e "metapass\n$AUTH_PASS\n$AUTH_PASS" | passwd +fi + +# Prepare conf +mkdir ${HOME}/custom_ssh +ssh-keygen -f ${HOME}/custom_ssh/ssh_host_rsa_key -N '' -t rsa +ssh-keygen -f ${HOME}/custom_ssh/ssh_host_dsa_key -N '' -t dsa + +cat << EOF > ${HOME}/custom_ssh/sshd_config +Port $BASE_PORT +HostKey ${HOME}/custom_ssh/ssh_host_rsa_key +HostKey ${HOME}/custom_ssh/ssh_host_dsa_key +AuthorizedKeysFile .ssh/authorized_keys +ChallengeResponseAuthentication no +UsePAM yes +Subsystem sftp /usr/lib/ssh/sftp-server +PidFile ${HOME}/custom_ssh/sshd.pid +EOF + +# Run +echo "[INFO] Now running SSH server on port $BASE_PORT and listening." +/usr/sbin/sshd -D -f ${HOME}/custom_ssh/sshd_config +EXIT_CODE=$? +echo "Exit code: $EXIT_CODE" +if [[ "x$EXIT_CODE" != "x0" ]] && [[ "x$EXIT_CODE" != "x130" ]] ; then + echo "This exit code is an error, exiting." + exit $? +fi +echo "" \ No newline at end of file diff --git a/SSH/run.sh b/SSH/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..cf330614ca2392494230aecf825c7527d34a2f47 --- /dev/null +++ b/SSH/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker run -v$PWD/:/data -p2222:2222 -eAUTH_PASS='testpass' -eBASE_PORT=2222 -it ssh diff --git a/base/Dockerfile b/base/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b0612b6d555af416f4e4b2ccb9731e9da9c0c353 --- /dev/null +++ b/base/Dockerfile @@ -0,0 +1,57 @@ +FROM ubuntu:18.04 +MAINTAINER Stefano Alberto Russo <stefano.russo@inaf.it> + +#---------------------- +# Basics +#---------------------- + +# Set non-interactive +ENV DEBIAN_FRONTEND noninteractive + +# Update first of all +RUN apt-get update + +# Utilities +RUN apt-get install -y nano telnet unzip wget supervisor build-essential python-dev git-core openjdk-8-jre + + +#------------------------ +# "Meta" user +#------------------------ + +# Add group. We chose GID 65527 to try avoiding conflicts. +RUN groupadd -g 65527 metauser + +# Add user. We chose UID 65527 to try avoiding conflicts. +RUN useradd metauser -d /home/metauser -u 65527 -g 65527 -m -s /bin/bash + +# Add metuaser user to sudoers +RUN adduser metauser sudo + +# Install suodo +RUN apt-get install sudo -y + +# No pass sudo (for everyone, actually) +COPY files/sudoers /etc/sudoers + +# Prepare for user-space logs +RUN mkdir /home/metauser/.logs && chown metauser:metauser /home/metauser/.logs + +# Rename metauser home folder as a "vanilla" home folder +RUN mv /home/metauser /metauser_home_vanilla + +# Set container name +ENV CONTAINER_NAME='base' + +# Entrypoint +COPY files/base_entrypoint.sh / +RUN chmod 755 /base_entrypoint.sh +ENTRYPOINT ["/base_entrypoint.sh"] +ENV DEFAULT_ENTRYPOINT_COMMAND="/bin/bash" + +# Allow to move the /home_vanilla folder in /home +RUN chmod 777 /home + +# Set user +USER metauser + diff --git a/base/build.sh b/base/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..d4f5524609296c5fb3f1fd66887a5a32a57bc0f8 --- /dev/null +++ b/base/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build . -t base diff --git a/base/files/base_entrypoint.sh b/base/files/base_entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..daaa28305a13fb70ec4b5f1e36919daa785abfc2 --- /dev/null +++ b/base/files/base_entrypoint.sh @@ -0,0 +1,82 @@ +#!/bin/bash + + # Exit on any error. More complex thing could be done in future +# (see https://stackoverflow.com/questions/4381618/exit-a-script-on-error) +set -e + + +if [ "x$SAFE_MODE" == "xTrue" ]; then + echo "" + echo "[INFO] Not executing entrypoint as we are in safe mode, just opening a Bash shell." + exec /bin/bash +else + echo "" + echo "[INFO] Executing entrypoint..." + + + #--------------------- + # Setup home + #--------------------- + + if [ -f "/home/metauser/.initialized" ]; then + : + else + echo "[INFO] Setting up home" + mkdir -p /home/metauser + + # Copy over vanilla home contents + for x in /metauser_home_vanilla/* /metauser_home_vanilla/.[!.]* /metauser_home_vanilla/..?*; do + if [ -e "$x" ]; then cp -a "$x" /home/metauser/; fi + done + + # Mark as initialized + touch /home/metauser/.initialized + fi + + # Manually set home (mainly for Singularity) + echo "[INFO] Setting up HOME env var" + export HOME=/home/metauser + cd /home/metauser + + #--------------------- + # Save env + #--------------------- + echo "[INFO] Dumping env" + + # Save env vars for later usage (e.g. ssh) + + env | \ + while read env_var; do + if [[ $env_var == HOME\=* ]]; then + : # Skip HOME var + elif [[ $env_var == PWD\=* ]]; then + : # Skip PWD var + else + echo "export $env_var" >> /tmp/env.sh + fi + done + + #--------------------- + # Prompt + #--------------------- + + echo "[INFO] Setting new prompt @$CONTAINER_NAME container" + echo 'export PS1="${debian_chroot:+($debian_chroot)}\u@$CONTAINER_NAME@\h:\w\$ "' >> /home/metauser/.bashrc + + + #--------------------- + # Entrypoint command + #--------------------- + + if [ "$@x" == "x" ]; then + echo -n "[INFO] Executing default entrypoint command: " + echo $DEFAULT_ENTRYPOINT_COMMAND + exec $DEFAULT_ENTRYPOINT_COMMAND + else + echo -n "[INFO] Executing entrypoint command: " + echo $@ + exec $@ + fi + +fi + diff --git a/base/files/sudoers b/base/files/sudoers new file mode 100644 index 0000000000000000000000000000000000000000..47ab37c90fdec1df833409f825d2665fe7d1f899 --- /dev/null +++ b/base/files/sudoers @@ -0,0 +1,30 @@ +# +# This file MUST be edited with the 'visudo' command as root. +# +# Please consider adding local content in /etc/sudoers.d/ instead of +# directly modifying this file. +# +# See the man page for details on how to write a sudoers file. +# +Defaults env_reset +Defaults mail_badpass +Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + +# Host alias specification + +# User alias specification + +# Cmnd alias specification + +# User privilege specification +root ALL=(ALL:ALL) ALL + +# Members of the admin group may gain root privileges +%admin ALL=(ALL) ALL + +# Allow members of group sudo to execute any command +%sudo ALL=(ALL:ALL) NOPASSWD:ALL + +# See sudoers(5) for more information on "#include" directives: + +#includedir /etc/sudoers.d diff --git a/base/run.sh b/base/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..a7f1984308fd8a1d4ebcc8d7f6e8b6b1c45ce38f --- /dev/null +++ b/base/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker run -v$PWD/:/data -it base