Skip to content

Commit

Permalink
Merge pull request #64 from buildkite-plugins/SUP-2844-fix-ssh-agent
Browse files Browse the repository at this point in the history
Target the ephemeral ssh-agent PID created when loading secrets
  • Loading branch information
mcncl authored Dec 18, 2024
2 parents 00013da + baa6a14 commit 6f88895
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions hooks/pre-exit
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

if [[ -n "${SSH_AGENT_PID:-}" ]] && ps -p "$SSH_AGENT_PID" &>/dev/null; then
echo "~~~ Stopping ssh-agent ${SSH_AGENT_PID}"
ssh-agent -k
fi
if [[ -n "${EPHEMERAL_SSH_AGENT_PID:-}" ]] && ps -p "$EPHEMERAL_SSH_AGENT_PID" &>/dev/null; then
echo "~~~ Stopping ssh-agent ${EPHEMERAL_SSH_AGENT_PID}"
SSH_AGENT_PID="${EPHEMERAL_SSH_AGENT_PID}" ssh-agent -k
else
echo "~~~ No Ephemeral SSH Agent found"
fi
1 change: 1 addition & 0 deletions lib/shared.bash
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ add_ssh_private_key_to_agent() {
if [[ -z "${SSH_AGENT_PID:-}" ]] ; then
echo "Starting an ephemeral ssh-agent" >&2;
eval "$(ssh-agent -s)"
export EPHEMERAL_SSH_AGENT_PID="${SSH_AGENT_PID}"
fi

echo "Loading ssh-key into ssh-agent (pid ${SSH_AGENT_PID:-})" >&2;
Expand Down

0 comments on commit 6f88895

Please sign in to comment.