Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmakarov committed Jan 20, 2017
2 parents 91e4038 + 1103159 commit 9f42d1c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM alpine:3.4

MAINTAINER Team Docksal, https://docksal.io

RUN apk add --no-cache \
bash \
openssh \
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016-2017 Docksal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 29 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
# Docker SSH Agent for Docksal
# SSH Agent Docker image for Docksal

## How to use
This image(s) is part of the [Docksal](http://docksal.io) image library.

### 0. Build
The exposed ssh-agent socket will be accessible to all users (not only root) in any container.
This is achieved by exposing a proxy socket (`/.ssh-agent/proxy-socket`) via socat.

```
docker build -t docksal/ssh-agent:stable -f Dockerfile .
```

### 1. Run a long-lived container
## Usage

```
docker run -d --name=ssh-agent docksal/ssh-agent:stable
### 1. Start the ssh-agent container

```bash
docker run -d --name=ssh-agent docksal/ssh-agent
```

### 2. Add your ssh keys

Run a temporary container with volume mounted from host that includes your SSH keys. SSH key id_rsa will be added to ssh-agent (you can replace id_rsa with your key name):
Replace `~/.ssh` with the path to your keys and `id_rsa` with the key name.
If the key has a passphrase, you will be asked to enter it.

```
docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/root/.ssh -it docksal/ssh-agent:stable ssh-add /root/.ssh/id_rsa
```bash
docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/root/.ssh -it ssh-agent ssh-add /root/.ssh/id_rsa
```

### 3. Delete all ssh keys from ssh-agent
### 3. Access SSH keys from the ssh-agent in other containers

Run a temporary container and delete all known keys from ssh-agent:
Mount the ssh-agent socket and set the `SSH_AUTH_SOCK` variable in other containers.

```
docker run --rm --volumes-from=ssh-agent -it docksal/ssh-agent:stable ssh-add -D
```
Docker

### 4. Add ssh-agent socket to other container:
```bash
docker run --rm --volumes-from=ssh-agent -e SSH_AUTH_SOCK=/.ssh-agent/proxy-socket-it <image> ssh-add -l
```

Use two options for running your container:
Docker Compose

```
```yaml
...
volumes_from:
- ssh-agent
...
environment:
- SSH_AUTH_SOCK=/.ssh-agent/socket
- SSH_AUTH_SOCK /.ssh-agent/proxy-socket
...
```

It works only for root user. ssh-agent socket is accessible only to the user which started this agent or for root user. So other users don't have access to /.ssh-agent/socket. If you have another user (for example docker) in your container, do next things:
- install 'socat' utility in your container
- make proxy-socket in your conatainer:
```
sudo socat UNIX-LISTEN:~/.ssh/socket,fork UNIX-CONNECT:/.ssh-agent/socket &
```
- change owner for this proxy-socket
```
sudo chown $(id -u) ~/.ssh/socket
```
- you need use different SSH_AUTH_SOCK for this user:
```
SSH_AUTH_SOCK=~/.ssh/socket
### Deleting all keys from the ssh-agent

```bash
docker run --rm --volumes-from=ssh-agent -it docksal/ssh-agent ssh-add -D
```

0 comments on commit 9f42d1c

Please sign in to comment.