Skip to content

Commit 5a923f2

Browse files
committed
Add conditions to the SSH agent post-start command
Signed-off-by: ivinokur <[email protected]>
1 parent ff72383 commit 5a923f2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/library/ssh/event.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import (
2121
"github.com/devfile/devworkspace-operator/pkg/library/lifecycle"
2222
)
2323

24-
const commandLine = `SSH_ENV_PATH=$HOME/ssh-environment \
25-
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
26-
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
27-
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
28-
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
29-
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi`
24+
const commandLine = `(SSH_ENV_PATH=$HOME/ssh-environment \
25+
&& if [ -f /etc/ssh/passphrase ] && [ -w $HOME ] && command -v ssh-add >/dev/null && command -v ssh-agent >/dev/null; then\
26+
ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
27+
&& chmod 600 $SSH_ENV_PATH \
28+
&& source $SSH_ENV_PATH \
29+
&& if timeout 3 ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase && [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then \
30+
echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; \
31+
fi; \
32+
fi) || true`
3033

3134
// AddSshAgentPostStartEvent Start ssh-agent and add the default ssh key to it, if the ssh key has a passphrase.
3235
// Initialise the ssh-agent session env variables in the user .bashrc file.

0 commit comments

Comments
 (0)