File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -40,9 +40,12 @@ source "${DOCK_INIT_BASE}/lib/aws.sh"
4040source " ${DOCK_INIT_BASE} /lib/dock.sh"
4141source " ${DOCK_INIT_BASE} /lib/container.sh"
4242source " ${DOCK_INIT_BASE} /lib/iptables.sh"
43+ source " ${DOCK_INIT_BASE} /lib/cleanup.sh"
4344
4445# Initializes the dock
4546main () {
47+ # Make sure to setup the exit trap first so we never have a dock with creds hanging about
48+ cleanup::set_exit_trap
4649 consul::connect
4750 consul::get_environment
4851 consul::configure_consul_template
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # An "on exit" trap to clean up sensitive keys and files on the dock itself.
4+ # Note that this will have no effect if the `DONT_DELETE_KEYS` environment has
5+ # been set (useful for testing)
6+ cleanup::exit_trap () {
7+ # Delete the keys unless the `DONT_DELETE_KEYS` flag is set
8+ if [[ " ${DONT_DELETE_KEYS} " == " " ]]; then
9+ log::info ' [CLEANUP TRAP] Removing Keys'
10+ rm -f " ${CERT_PATH} " /ca-key.pem \
11+ " ${CERT_PATH} " /pass \
12+ " ${DOCK_INIT_BASE} " /consul-resources/template-config.hcl \
13+ " ${DOCK_INIT_BASE} " /consul-resources/vault/** /auth-token \
14+ " ${DOCK_INIT_BASE} " /consul-resources/vault/** /token-* \
15+ " ${DOCK_INIT_BASE} " /key/rollbar.token
16+ fi
17+ }
18+
19+ # Sets the cleanup trap for the entire script
20+ cleanup::set_exit_trap () {
21+ log::info " Setting key cleanup trap"
22+ trap ' cleanup::exit_trap' EXIT
23+ }
You can’t perform that action at this time.
0 commit comments