-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple helper script to encrypt secrets
- Loading branch information
1 parent
1e291bb
commit fe0f464
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ __pycache__/ | |
dqm2m_production.db_test | ||
*.env* | ||
*.pkl | ||
*.log.* | ||
*.log.* | ||
*.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# Script that encodes k8s secrets with base64. | ||
# Might have many bugs!!! | ||
|
||
# Unencoded file to read secrets from | ||
IN_FILE=k8_secret.yaml | ||
|
||
# File to write output to | ||
OUT_FILE=k8_secret_encrypted.yaml | ||
|
||
# Files can also be passed as arguments to the script | ||
if [ ! -z $1 ]; | ||
then | ||
IN_FILE=$1 | ||
fi | ||
|
||
if [ ! -z $2 ]; | ||
then | ||
OUT_FILE=$2 | ||
fi | ||
|
||
# Do not split with spaces in for loop | ||
IFS=$'\n' | ||
|
||
# Copy input file to output, so that we can start replacing it in-place. | ||
cat $IN_FILE > $OUT_FILE | ||
# Use awk to get the secrets out of k8_secret, found under the "data" section in the yaml. | ||
for i in $(awk '/^[^ ]/{ f=/^data:/; next } f{ if (match($0, /^\s+[a-zA-Z0-9_]+\s*:.+/)) { print $0 }}' $OUT_FILE); do | ||
# For each line containing a secret, encode its value in the OUT_FILE in place. | ||
# Set base64's wrap to zero to have it all in one line. | ||
# Use commas in the sed regexp, as we may have '/' in the values (e.g. CMSWEB_FRONTEND_PROXY_URL). | ||
# Leading spaces are not preserved in the replacement string, so we're adding them manually. | ||
sed -r "s,^$i$, $(echo $i | awk '{print $1}') $(echo $i | awk '{printf $2}' | base64 --wrap 0) # $(echo $i | awk '{printf $2}'),g" -i $OUT_FILE | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters