From 7ab263cb83f49aa7516ac2e60a5b7beaa72ffc64 Mon Sep 17 00:00:00 2001 From: Hyrum Toth Date: Wed, 20 Jun 2018 13:22:40 -0600 Subject: [PATCH 1/3] New script. set-ssh-key-perms.sh Hoping to use this in docker-composer alongside the other scripts here. --- container/README.md | 9 +++++++++ container/set-ssh-key-perms.sh | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 container/set-ssh-key-perms.sh diff --git a/container/README.md b/container/README.md index 6be3f59..91b2381 100644 --- a/container/README.md +++ b/container/README.md @@ -9,3 +9,12 @@ If the project directory is owned by `root` then files will be written out as `r Credit goes to https://github.com/graze/docker-composer/blob/master/php-7.0/composer-wrapper * Loop over each argument and append the argument if the command matches one we need to use `--ignore-platform-reqs` with. Found using the following search: https://github.com/composer/composer/search?q=ignore-platform-reqs+path%3Asrc%2FComposer%2FCommand%2F Uses `set` to update the arguments, see https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html. + +# `set-ssh-key-perms.sh` + +Credit goes to https://nickjanetakis.com/blog/docker-tip-56-volume-mounting-ssh-keys-into-a-docker-container + +Initial use case is for users of "Docker for Windows". Due to file permission differences with the Windows OS and Linux, you need to adjust them inside the container before use. + +* Copy the ssh keys mounted to `/tmp/` to `/home/dev/` and `/root/`. Ensuring the original are not modified. +* Set permissions on `.ssh/` directories. Ensuring the permissions are correct. diff --git a/container/set-ssh-key-perms.sh b/container/set-ssh-key-perms.sh new file mode 100644 index 0000000..07c7a15 --- /dev/null +++ b/container/set-ssh-key-perms.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Required for volume mounting ssh keys for "Docker for Windows" +# credit to: https://nickjanetakis.com/blog/docker-tip-56-volume-mounting-ssh-keys-into-a-docker-container +# Usage: volume mount your ssh key directory to /tmp/.ssh + +set -e + +cp -R /tmp/.ssh /root/.ssh +chmod 700 /root/.ssh +chmod 644 /root/.ssh/id_rsa.pub +chmod 600 /root/.ssh/id_rsa + +cp -R /tmp/.ssh /home/dev/.ssh +chmod 700 /home/dev/.ssh +chmod 644 /home/dev/.ssh/id_rsa.pub +chmod 600 /home/dev/.ssh/id_rsa + +exec "$@" From d645b4023a57cab98c53d9c8791ac93b2ca628f0 Mon Sep 17 00:00:00 2001 From: Hyrum Toth Date: Wed, 20 Jun 2018 13:26:57 -0600 Subject: [PATCH 2/3] Modified file name to fit convention of other files --- container/README.md | 2 +- container/{set-ssh-key-perms.sh => set-ssh-key-perms} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename container/{set-ssh-key-perms.sh => set-ssh-key-perms} (100%) diff --git a/container/README.md b/container/README.md index 91b2381..14dc228 100644 --- a/container/README.md +++ b/container/README.md @@ -10,7 +10,7 @@ Credit goes to https://github.com/graze/docker-composer/blob/master/php-7.0/comp * Loop over each argument and append the argument if the command matches one we need to use `--ignore-platform-reqs` with. Found using the following search: https://github.com/composer/composer/search?q=ignore-platform-reqs+path%3Asrc%2FComposer%2FCommand%2F Uses `set` to update the arguments, see https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html. -# `set-ssh-key-perms.sh` +# `set-ssh-key-perms` Credit goes to https://nickjanetakis.com/blog/docker-tip-56-volume-mounting-ssh-keys-into-a-docker-container diff --git a/container/set-ssh-key-perms.sh b/container/set-ssh-key-perms similarity index 100% rename from container/set-ssh-key-perms.sh rename to container/set-ssh-key-perms From aa7000a97e2ba25fc341855f895fc531bf499434 Mon Sep 17 00:00:00 2001 From: Hyrum Toth Date: Wed, 20 Jun 2018 13:46:20 -0600 Subject: [PATCH 3/3] Directory and file check in case no files mounted. --- container/set-ssh-key-perms | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/container/set-ssh-key-perms b/container/set-ssh-key-perms index 07c7a15..ef8b11d 100644 --- a/container/set-ssh-key-perms +++ b/container/set-ssh-key-perms @@ -5,14 +5,20 @@ set -e -cp -R /tmp/.ssh /root/.ssh -chmod 700 /root/.ssh -chmod 644 /root/.ssh/id_rsa.pub -chmod 600 /root/.ssh/id_rsa +if [ -d /tmp/.ssh ]; then + cp -R /tmp/.ssh /root/.ssh + cp -R /tmp/.ssh /home/dev/.ssh + chmod 700 /root/.ssh + chmod 700 /home/dev/.ssh -cp -R /tmp/.ssh /home/dev/.ssh -chmod 700 /home/dev/.ssh -chmod 644 /home/dev/.ssh/id_rsa.pub -chmod 600 /home/dev/.ssh/id_rsa + if [ -f /tmp/.ssh/id_rsa.pub ]; then + chmod 644 /root/.ssh/id_rsa.pub + chmod 644 /home/dev/.ssh/id_rsa.pub + fi + if [ -f /tmp/.ssh/id_rsa ]; then + chmod 600 /root/.ssh/id_rsa + chmod 600 /home/dev/.ssh/id_rsa + fi +fi exec "$@"