Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Get --auth-credentials from a VAULT instance (#432)
Browse files Browse the repository at this point in the history
* Get --auth-credentials from a VAULT instance

* removed jq dependency
  • Loading branch information
albertostratio authored and lloesche committed Mar 31, 2017
1 parent 022bf01 commit 8811443
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ It is possible to pass `--auth-credentials=` option if your Marathon requires au
$ ./marathon_lb.py --marathon http://localhost:8080 --auth-credentials=admin:password
```

It is possible to get the auth credentials (user & password) from VAULT if you define the following
environment variables before running marathon-lb: VAULT_TOKEN, VAULT_HOST, VAULT_PORT, VAULT_PATH
where VAULT_PATH is the root path where your user and password are located.

This will refresh `haproxy.cfg`, and if there were any changes, then it will
automatically reload HAProxy. Only apps with the label `HAPROXY_GROUP=external`
will be exposed on this LB.
Expand Down
7 changes: 7 additions & 0 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ case "$MODE" in
;;
esac

if [ -n "${VAULT_TOKEN-}" ] && [ -n "${VAULT_HOST-}" ] && [ -n "${VAULT_PORT-}" ] && [ -n "${VAULT_PATH-}" ]; then
MARATHON_LB_PASSWORD=$(curl -k -L -H "X-Vault-Token:$VAULT_TOKEN" "$VAULT_URL" -s| python -m json.tool | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["data"]["pass"]')
MARATHON_LB_USER=$(curl -k -L -H "X-Vault-Token:$VAULT_TOKEN" "$VAULT_URL" -s | python -m json.tool | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["data"]["user"]')
CREDENTIALS="$MARATHON_LB_USER:$MARATHON_LB_PASSWORD"
ARGS="$ARGS --auth-credentials $CREDENTIALS"
fi

for arg in "$@"; do
escaped=$(printf %q "$arg")
ARGS="$ARGS $escaped"
Expand Down

0 comments on commit 8811443

Please sign in to comment.