Skip to content

Commit 2b4622e

Browse files
fix: redact api key in log files
1 parent 05f3afb commit 2b4622e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

solutions/standard-openshift/ansible/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ resource "terraform_data" "execute_playbooks" {
169169
]
170170
}
171171

172+
# Again replace the API Key in any logs where it may have been included in plain text
173+
provisioner "remote-exec" {
174+
inline = [
175+
"APIKEY=\"${local.ibmcloud_api_key}\"",
176+
"grep -RIl -- \"$APIKEY\" \"/root\" | while IFS= read -r file; do",
177+
"sed -i 's/'\"$APIKEY\"'/***redacted***/g' \"$file\"",
178+
"done"
179+
]
180+
}
181+
172182
# print output of openshift installation if applicable, else do nothing
173183
provisioner "remote-exec" {
174184
inline = [
@@ -273,6 +283,16 @@ resource "terraform_data" "execute_playbooks_with_vault" {
273283
]
274284
}
275285

286+
# Again replace the API Key in any logs where it may have been included in plain text
287+
provisioner "remote-exec" {
288+
inline = [
289+
"APIKEY=\"${local.ibmcloud_api_key}\"",
290+
"grep -RIl -- \"$APIKEY\" \"/root\" | while IFS= read -r file; do",
291+
"sed -i 's/'\"$APIKEY\"'/***redacted***/g' \"$file\"",
292+
"done"
293+
]
294+
}
295+
276296
# Again delete Ansible Vault password used to encrypt the var
277297
# files with sensitive information and private ssh key
278298
provisioner "remote-exec" {

solutions/standard-openshift/ansible/templates-ansible/deploy-openshift-cluster/ansible_exec.sh.tftpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ if [ $? -ne 0 ]; then
2727
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
2828
rm -f password_file
2929
rm -rf $${ansible_private_key_file}
30+
# remove API Key from any logs where it may have been included in plain text
31+
grep -RIl -- "$IBMCLOUD_API_KEY" "/root" | while IFS= read -r file; do
32+
sed -i 's/'"$IBMCLOUD_API_KEY"'/***redacted***/g' "$file"
33+
done
3034
exit 1
3135
fi
3236
echo \"Playbook command successful\"
3337
rm -rf $${ansible_private_key_file}
3438
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
3539
rm -f password_file
40+
# remove API Key from any logs where it may have been included in plain text
41+
grep -RIl -- "$IBMCLOUD_API_KEY" "/root" | while IFS= read -r file; do
42+
sed -i 's/'"$IBMCLOUD_API_KEY"'/***redacted***/g' "$file"
43+
done

solutions/standard-openshift/ansible/templates-ansible/deploy-openshift-cluster/ansible_exec_vault.sh.tftpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ if [ $? -ne 0 ]; then
2727
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
2828
rm -f password_file
2929
rm -rf $${ansible_private_key_file}
30+
# remove API Key from any logs where it may have been included in plain text
31+
grep -RIl -- "$IBMCLOUD_API_KEY" "/root" | while IFS= read -r file; do
32+
sed -i 's/'"$IBMCLOUD_API_KEY"'/***redacted***/g' "$file"
33+
done
3034
exit 1
3135
fi
3236
echo \"Playbook command successful\"
3337
rm -rf $${ansible_private_key_file}
3438
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
3539
rm -f password_file
40+
41+
# remove API Key from any logs where it may have been included in plain text
42+
grep -RIl -- "$IBMCLOUD_API_KEY" "/root" | while IFS= read -r file; do
43+
sed -i 's/'"$IBMCLOUD_API_KEY"'/***redacted***/g' "$file"
44+
done

0 commit comments

Comments
 (0)