Skip to content

Commit 38fac85

Browse files
authored
Merge pull request #46 from CodeNow/SAN-6292-add-cleanup-back-in
Delete certs, consul-resources when the dock finishes initializing.
2 parents d24e8cf + e0fd010 commit 38fac85

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

init.sh

+3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ source "${DOCK_INIT_BASE}/lib/aws.sh"
4040
source "${DOCK_INIT_BASE}/lib/dock.sh"
4141
source "${DOCK_INIT_BASE}/lib/container.sh"
4242
source "${DOCK_INIT_BASE}/lib/iptables.sh"
43+
source "${DOCK_INIT_BASE}/lib/cleanup.sh"
4344

4445
# Initializes the dock
4546
main() {
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

lib/cleanup.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

0 commit comments

Comments
 (0)