Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few small tweaks and improvements #22

Merged
merged 5 commits into from
Aug 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,15 +49,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"
}
}