diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..64b2baf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +* +!index.js +!ONVAULT +!package.json diff --git a/ONVAULT b/ONVAULT index 54edcf4..6ca92f5 100755 --- a/ONVAULT +++ b/ONVAULT @@ -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...' @@ -45,8 +49,8 @@ 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 @@ -54,6 +58,9 @@ if curl -s "${VAULT_URI}/_ping"; then 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 $@ diff --git a/index.js b/index.js index 6de406a..af904c0 100644 --- a/index.js +++ b/index.js @@ -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'; @@ -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]; @@ -33,6 +35,7 @@ app.get('/ssh.tgz', function (req, res) { var filestream = fs.createReadStream(file); filestream.pipe(res); + fs.unlink(file) }); }); }); diff --git a/package.json b/package.json index c8bfb35..0843fb6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "express": "^4.12.3", - "mime": "^1.3.4" + "mime": "^1.3.4", + "mkdirp": "^0.5.1" } }