Skip to content

Commit

Permalink
Merge pull request #22 from NikolausDemmel/feature/tweaks
Browse files Browse the repository at this point in the history
A few small tweaks and improvements
  • Loading branch information
maxcnunes authored Aug 7, 2016
2 parents c202988 + 743cf01 commit c385a46
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!index.js
!ONVAULT
!package.json
11 changes: 9 additions & 2 deletions ONVAULT
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ log () {
echo -e "${GREEN}[Dockito Vault]${NC} $@"
}

# don't go through proxy for accessing vault
no_proxy_old="$no_proxy"
export no_proxy="$VAULT_HOST"

if ! curl -s "${VAULT_URI}/_ping"; then
COUNTER=0
echo 'Waiting 10s for dockito/vault to be ready...'
Expand All @@ -46,15 +50,18 @@ if curl -s "${VAULT_URI}/_ping"; then

log "Downloading private keys..."
curl -s "${VAULT_URI}/ssh.tgz" | tar -C ~/.ssh/ -zxf -
chown `whoami` ~/.ssh/*
chmod 600 ~/.ssh/*
chown -f `whoami` ~/.ssh/* || true
chmod -f 600 ~/.ssh/* || true

log "Using ssh key: $VAULT_SSH_KEY"
if [[ "$VAULT_SSH_KEY" != "id_rsa" ]]; then
# configure the ssh to any host to use this ssh key
echo -e "\nHost *\nIdentityFile ~/.ssh/$VAULT_SSH_KEY" >> ~/.ssh/config
fi

# restore 'no_proxy' for executing the actual command
export no_proxy="$no_proxy_old"

log "Executing command: $@"
eval $@

Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var express = require('express'),
fs = require('fs'),
exec = require('child_process').exec,
mime = require('mime'),
path = require('path');
path = require('path'),
mkdirp = require('mkdirp');


var host = process.env.HTTP_HOST || '0.0.0.0';
Expand All @@ -21,6 +22,7 @@ app.get('/_ping', function (req, res) {
Bundle containing all the user's private keys and ssh configuration
*/
app.get('/ssh.tgz', function (req, res) {
mkdirp("/vault/.ssh");
exec('mktemp -q /tmp/ssh.XXXXXX', function (err, stdout) {
var file = stdout.match(/(.+)/)[0];

Expand All @@ -33,6 +35,7 @@ app.get('/ssh.tgz', function (req, res) {

var filestream = fs.createReadStream(file);
filestream.pipe(res);
fs.unlink(file)
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.12.3",
"mime": "^1.3.4"
"mime": "^1.3.4",
"mkdirp": "^0.5.1"
}
}

0 comments on commit c385a46

Please sign in to comment.