Skip to content

Commit 18f48b3

Browse files
committed
initial import
0 parents  commit 18f48b3

File tree

8 files changed

+84
-0
lines changed

8 files changed

+84
-0
lines changed

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM alpine
2+
MAINTAINER Anil Madhavapeddy <[email protected]>
3+
RUN apk update && apk add openssh && \
4+
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ tini
5+
RUN mkdir /root/.ssh && \
6+
chmod 700 /root/.ssh && \
7+
ssh-keygen -A
8+
COPY ssh-find-agent.sh /root/ssh-find-agent.sh
9+
EXPOSE 22
10+
VOLUME ["/root/.ssh/authorized_keys"]
11+
ENTRYPOINT ["/usr/bin/tini","--"]
12+
CMD ["/usr/sbin/sshd","-D"]

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
all:
2+
./pinata-build-sshd.sh
3+
@echo Please run "make install"
4+
5+
PREFIX ?= /usr/local
6+
BINDIR ?= $(PREFIX)/bin
7+
8+
install:
9+
@if [ ! -d "$(PREFIX)" ]; then echo Error: need a $(PREFIX) directory; exit 1; fi
10+
@mkdir -p $(PREFIX)/share/pinata-ssh-agent
11+
cp Dockerfile $(PREFIX)/share/pinata-ssh-agent
12+
cp ssh-build.sh $(PREFIX)/share/pinata-ssh-agent/ssh-build
13+
cp ssh-find-agent.sh $(PREFIX)/share/pinata-ssh-agent/ssh-find-agent.sh
14+
@mkdir -p $(BINDIR)
15+
cp pinata-build-sshd.sh $(BINDIR)/pinata-build-sshd
16+
cp pinata-ssh-forward.sh $(BINDIR)/pinata-ssh-forward
17+
cp pinata-ssh-mount.sh $(BINDIR)/pinata-ssh-mount

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Forward SSH agent socket into a container
2+
3+
Still experimental -- contact [email protected] if you want help.

pinata-build-sshd.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
cd /usr/local/share/pinata-ssh-agent
4+
docker build -t pinata-sshd .

pinata-ssh-forward.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh -e
2+
3+
IMAGE_NAME=pinata-sshd
4+
CONTAINER_NAME=pinata-sshd
5+
LOCAL_STATE=~/.pinata-sshd
6+
LOCAL_PORT=2244
7+
8+
docker rm -f ${CONTAINER_NAME} >/dev/null 2>&1 || true
9+
rm -rf ${LOCAL_STATE}
10+
mkdir -p ${LOCAL_STATE}
11+
12+
docker run --name ${CONTAINER_NAME} \
13+
-v ~/.ssh/id_rsa.pub:/root/.ssh/authorized_keys \
14+
-v ${LOCAL_STATE}:/tmp \
15+
-d -p ${LOCAL_PORT}:22 ${IMAGE_NAME} > /dev/null
16+
17+
IP=`docker inspect --format '{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostIp }}' ${CONTAINER_NAME}`
18+
ssh-keyscan -p ${LOCAL_PORT} ${IP} > ${LOCAL_STATE}/known_hosts 2>/dev/null
19+
20+
ssh -f -o "UserKnownHostsFile=${LOCAL_STATE}/known_hosts" \
21+
-A -p ${LOCAL_PORT} root@${IP} \
22+
/root/ssh-find-agent.sh
23+
24+
echo 'Agent forwarding successfully started.'
25+
echo 'Run "pinata-ssh-mount" to get a command-line fragment that'
26+
echo 'can be added to "docker run" to mount the SSH agent socket.'
27+
echo ""
28+
echo 'For example:'
29+
echo 'docker run -it `pinata-ssh-mount` ocaml/opam ssh [email protected]'

pinata-ssh-mount.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
LOCAL_STATE=~/.pinata-sshd
4+
AGENT=`cat ${LOCAL_STATE}/agent_socket_path | sed -e 's,/tmp/,,g'`
5+
echo "-v ${LOCAL_STATE}/$AGENT:/tmp/ssh-agent.sock --env SSH_AUTH_SOCK=/tmp/ssh-agent.sock"

ssh-build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
IMAGE_NAME=pinata-sshd
4+
5+
docker build -q -t ${IMAGE_NAME} .

ssh-find-agent.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh -e
2+
# Log the location of the SSH agent to a file
3+
4+
finish() {
5+
rm -f /tmp/agent_socket_path
6+
}
7+
trap finish EXIT
8+
echo $SSH_AUTH_SOCK > /tmp/agent_socket_path
9+
tail -f /dev/null

0 commit comments

Comments
 (0)