Skip to content

Support for identity password over environment file #5

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ RUN apk add --no-cache \
bash \
openssh \
socat \
expect \
&& rm -rf /var/cache/apk/*

# Copy expect script
COPY ssh-add-pass.sh /ssh-add-pass.sh

# Copy entrypoint script to container
COPY entry.sh /entry.sh

Expand Down
43 changes: 43 additions & 0 deletions entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,49 @@ case "$1" in

# Return first command exit code
exit ${PIPESTATUS[0]}
;;
ssh-add-pass)
shift # remove argument from array

# .ssh folder from host is expected to be mounted on /.ssh
# We copy keys from there into /root/.ssh and fix permissions (necessary on Windows hosts)
host_ssh_path="/.ssh"
if [ -d $host_ssh_path ]; then
debug_msg "Copying host SSH keys and setting proper permissions..."
cp -av $host_ssh_path/. ~/.ssh/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
chmod 644 ~/.ssh/*.pub
fi

# Make sure the key exists if provided.
# When $ssh_key_path is empty, ssh-agent will be looking for both id_rsa and id_dsa in the home directory.
ssh_key_path=""
if [ -n "$1" ] && [ -f "/root/.ssh/$1" ]; then
ssh_key_path="/root/.ssh/$1"
shift # remove argument from array
fi

# Calling ssh-add. This should handle all cases.
_command="/ssh-add-pass.sh $ssh_key_path $@"
debug_msg "Executing: $_command"

# When $key_path is empty, ssh-agent will be looking for both id_rsa and id_dsa in the home directory.
# NOTE: We do a sed hack here to strip out '/root/.ssh' from the key path in the output from ssh-add, since this
# path may confuse people.
# echo "Press ENTER or CTRL+C to skip entering passphrase (if any)."
$_command 2>&1 0>&1 | sed 's/\/root\/.ssh\///g'

# Return first command exit code
exit ${PIPESTATUS[0]}
;;
ssh-add-list)
shift # remove argument from array

_command="ssh-add -l"

$_command 2>&1 0>&1 | sed 's/\/root\/.ssh\///g'
exit ${PIPESTATUS[0]}
;;
*)
exec $@
Expand Down
15 changes: 15 additions & 0 deletions ssh-add-pass.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if [ $# -ne 2 ] ; then
echo "Usage: ssh-add-pass.sh keyfile passfile"
exit 1
fi

pass=$(cat $2)

expect << EOF
spawn ssh-add $1
expect "Enter passphrase"
send "$pass\r"
expect eof
EOF