First, let's generate a strong passphrase to protect the private key. As we are being git driven we do this inside our environment repo:
# ensure that we don't accidentally publish the passphrase to the key
echo passphrase >> .gitignore
git add .gitignore
git commit -m "ignore passphrase"
# generate a random passphrase
base64 < /dev/urandom | head -c 20 > passphrase
# print it out
echo $(<passphrase)
IMPORTANT: You might want to backup this passphrase. If you are using git-secret
how to backup passphrase
is covered below.
Now generate a key pair for OCD deployment tools using that passphrase using the cli wizard:
gpg --full-generate-key
Now you can export both the public and private key using the email you provided to the wizard:
mkdir gpg
[email protected]
EXPORT_FINGER=$(gpg --list-secret-key --with-colons $EXPORT_EMAIL | awk -F':' '$1=="fpr"{print $10}' | head -1)
gpg --export-secret-key -a $EXPORT_EMAIL > gpg/$EXPORT_FINGER.prv.key && git add gpg/$EXPORT_FINGER.prv.key
gpg --export -a $EXPORT_EMAIL > gpg/$EXPORT_FINGER.pub.key && git add gpg/$EXPORT_FINGER.pub.key
git commit
The script .s2i/bin/run
will try to use an enviroment variable PASSPHRASE
to import the secret key and to decrypt the files.
You simply need to ensure that the actual passphrase is set as an environment variable on your application.
You can add the passphrase as a kubernetes secret with:
Then download it into your script rather than set it with an env var using:
PASSPHRASE=$(oc get secrets openshift-passphrase -o yaml | grep passphrase: | awk '{print $2}' | base64 --decode)
That assumes you have
oc
command working in your image. See https://github.com/ocd-scm/ocd-environment-webhook/blob/0.1.0/bin/oc_wrapper.sh which will refresh a login when it times out. That script needs an account to login to openshift that is allowed to read the secret.