From a6805fa7f35a4a6047eb5135d1357c9b197828d2 Mon Sep 17 00:00:00 2001 From: "Walter A. Alves" Date: Tue, 21 Feb 2017 23:54:22 -0300 Subject: [PATCH 1/6] Add an automation script to build images Added a script to automate the build images using all Dockerfiles inside of docker/ path. This Dockerfiles should respect the follow pattern: Dockerfile.$IMAGE_TAG. --- README.md | 12 ++++++++++++ build-images.sh | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100755 build-images.sh diff --git a/README.md b/README.md index 8316fdc..923080c 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,15 @@ SSH.pm manages machines that accept SSH connection, they may be physical machine Note that Linux is the priority here, as for now SSH.pm doesn't intend to support Windows, and does not guarantee compatibility with OS X, BSD, or another Unix-like opertating systems. **But as soon as we get to alpha phase we *will* add support to other Unix-like systems** + + +## Build automation + +Execute the build automation script: + +`./build-images` + +All Dockerfiles inside the `docker/` path will be built. + +Note that all Dockerfiles should respect the pattern `Dockerfile.$IMAGE_TAG`. + diff --git a/build-images.sh b/build-images.sh new file mode 100755 index 0000000..f90a455 --- /dev/null +++ b/build-images.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +DOCKER_ROOT=docker +DOCKER_FILES=$DOCKER_ROOT/* + +for docker_file in $DOCKER_FILES +do + IMAGE_TAG=$(echo $docker_file | sed -e "s/docker\/Dockerfile\.//" ) + + echo "Building sshpm-test-server$IMAGE_TAG..." + docker build -t sshpm-test-server:$IMAGE_TAG -f $docker_file $DOCKER_ROOT + + +done + From 5de39a6f5cba2d7ddffc930b7b44ecc0a2da564d Mon Sep 17 00:00:00 2001 From: "Walter A. Alves" Date: Wed, 22 Feb 2017 00:01:06 -0300 Subject: [PATCH 2/6] Fix README Fix the README text about Dockerfile pattern. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 923080c..e5b05b6 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Note that Linux is the priority here, as for now SSH.pm doesn't intend to suppor **But as soon as we get to alpha phase we *will* add support to other Unix-like systems** + ## Build automation Execute the build automation script: @@ -18,5 +19,5 @@ Execute the build automation script: All Dockerfiles inside the `docker/` path will be built. -Note that all Dockerfiles should respect the pattern `Dockerfile.$IMAGE_TAG`. +Note that all Dockerfiles should respect the follow pattern: `Dockerfile.$IMAGE_TAG`. From 04dd372316f0111d9e4dd03738dc9732c1a5d857 Mon Sep 17 00:00:00 2001 From: "Walter A. Alves" Date: Thu, 23 Feb 2017 02:09:21 -0300 Subject: [PATCH 3/6] Add a script to test if an user has sudo access This script verify if the user is sudo. The script will be "deployed" in the container in the path /var/scripts/ The script receives a parameter($1) which is the user password. --- docker/scripts/test_sudo.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docker/scripts/test_sudo.sh diff --git a/docker/scripts/test_sudo.sh b/docker/scripts/test_sudo.sh new file mode 100644 index 0000000..fad2420 --- /dev/null +++ b/docker/scripts/test_sudo.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +#This script is used to test if an user has sudo access + +echo $1 | sudo -S ls > /dev/null 2> /dev/null + +isSudo=$? +echo $isSudo From 6cbd3320006a08b52f567aa47d06795d70bd5cf2 Mon Sep 17 00:00:00 2001 From: "Walter A. Alves" Date: Thu, 23 Feb 2017 02:11:35 -0300 Subject: [PATCH 4/6] Make the script faster Now the docker build will run in paralel. --- build-images.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-images.sh b/build-images.sh index f90a455..f901f88 100755 --- a/build-images.sh +++ b/build-images.sh @@ -7,8 +7,8 @@ for docker_file in $DOCKER_FILES do IMAGE_TAG=$(echo $docker_file | sed -e "s/docker\/Dockerfile\.//" ) - echo "Building sshpm-test-server$IMAGE_TAG..." - docker build -t sshpm-test-server:$IMAGE_TAG -f $docker_file $DOCKER_ROOT + echo "Building sshpm-test-server images..." + docker build -t sshpm-test-server:$IMAGE_TAG -f $docker_file $DOCKER_ROOT & done From 09b2cfcc8c3a5f7b90405e829e9b104393e35409 Mon Sep 17 00:00:00 2001 From: "Walter A. Alves" Date: Thu, 23 Feb 2017 02:13:15 -0300 Subject: [PATCH 5/6] Add sudo installation and script deploy in dockerfiles Added the command to run apt-get install sudo. Added the command to deploy the "sudo test" script. --- docker/Dockerfile.ubuntu-1404 | 8 ++++++++ docker/Dockerfile.ubuntu-1604 | 8 ++++++++ docker/Dockerfile.ubuntu-1610 | 8 ++++++++ docker/Dockerfile.ubuntu-1704 | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/docker/Dockerfile.ubuntu-1404 b/docker/Dockerfile.ubuntu-1404 index 06b1dc2..1997b33 100644 --- a/docker/Dockerfile.ubuntu-1404 +++ b/docker/Dockerfile.ubuntu-1404 @@ -6,6 +6,9 @@ RUN mkdir /var/run/sshd RUN echo 'root:test_password' | chpasswd RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config +# Install sudo +RUN apt-get install -y sudo + # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd @@ -14,3 +17,8 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] + +#Load utils scripts +RUN mkdir -p /var/scripts +ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh +RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1604 b/docker/Dockerfile.ubuntu-1604 index 09db7c8..f75f122 100644 --- a/docker/Dockerfile.ubuntu-1604 +++ b/docker/Dockerfile.ubuntu-1604 @@ -7,6 +7,9 @@ RUN mkdir /var/run/sshd RUN echo 'root:test_password' | chpasswd RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config +# Install sudo +RUN apt-get install -y sudo + # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd @@ -15,3 +18,8 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] + +#Load utils scripts +RUN mkdir -p /var/scripts +ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh +RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1610 b/docker/Dockerfile.ubuntu-1610 index df1aa5a..e960bd0 100644 --- a/docker/Dockerfile.ubuntu-1610 +++ b/docker/Dockerfile.ubuntu-1610 @@ -6,6 +6,9 @@ RUN mkdir /var/run/sshd RUN echo 'root:test_password' | chpasswd RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config +# Install sudo +RUN apt-get install -y sudo + # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd @@ -14,3 +17,8 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] + +#Load utils scripts +RUN mkdir -p /var/scripts +ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh +RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1704 b/docker/Dockerfile.ubuntu-1704 index 7158548..0ab3f55 100644 --- a/docker/Dockerfile.ubuntu-1704 +++ b/docker/Dockerfile.ubuntu-1704 @@ -6,6 +6,9 @@ RUN mkdir /var/run/sshd RUN echo 'root:test_password' | chpasswd RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config +# Install sudo +RUN apt-get install -y sudo + # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd @@ -14,3 +17,8 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] + +#Load utils scripts +RUN mkdir -p /var/scripts +ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh +RUN chmod +x /var/scripts/test_sudo.sh From e9aac538250dcf2e767a08b1588a5c4808546d1f Mon Sep 17 00:00:00 2001 From: "Walter A. Alves" Date: Thu, 23 Feb 2017 19:13:23 -0300 Subject: [PATCH 6/6] Remove sudo test deploy Remove the deployment of test_sudo.sh file from Dockerfiles and remove the file from workspace. --- docker/Dockerfile.ubuntu-1404 | 5 ----- docker/Dockerfile.ubuntu-1604 | 5 ----- docker/Dockerfile.ubuntu-1610 | 5 ----- docker/Dockerfile.ubuntu-1704 | 5 ----- docker/scripts/test_sudo.sh | 8 -------- 5 files changed, 28 deletions(-) delete mode 100644 docker/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1404 b/docker/Dockerfile.ubuntu-1404 index 1997b33..99b724a 100644 --- a/docker/Dockerfile.ubuntu-1404 +++ b/docker/Dockerfile.ubuntu-1404 @@ -17,8 +17,3 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] - -#Load utils scripts -RUN mkdir -p /var/scripts -ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh -RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1604 b/docker/Dockerfile.ubuntu-1604 index f75f122..9891e6b 100644 --- a/docker/Dockerfile.ubuntu-1604 +++ b/docker/Dockerfile.ubuntu-1604 @@ -18,8 +18,3 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] - -#Load utils scripts -RUN mkdir -p /var/scripts -ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh -RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1610 b/docker/Dockerfile.ubuntu-1610 index e960bd0..71c5d64 100644 --- a/docker/Dockerfile.ubuntu-1610 +++ b/docker/Dockerfile.ubuntu-1610 @@ -17,8 +17,3 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] - -#Load utils scripts -RUN mkdir -p /var/scripts -ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh -RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/Dockerfile.ubuntu-1704 b/docker/Dockerfile.ubuntu-1704 index 0ab3f55..69c56ff 100644 --- a/docker/Dockerfile.ubuntu-1704 +++ b/docker/Dockerfile.ubuntu-1704 @@ -17,8 +17,3 @@ RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/bin/bash", "-c", "/usr/sbin/sshd && tail -f /dev/null"] - -#Load utils scripts -RUN mkdir -p /var/scripts -ADD ./scripts/test_sudo.sh /var/scripts/test_sudo.sh -RUN chmod +x /var/scripts/test_sudo.sh diff --git a/docker/scripts/test_sudo.sh b/docker/scripts/test_sudo.sh deleted file mode 100644 index fad2420..0000000 --- a/docker/scripts/test_sudo.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -#This script is used to test if an user has sudo access - -echo $1 | sudo -S ls > /dev/null 2> /dev/null - -isSudo=$? -echo $isSudo