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.
note that with newer GPG 2.2 you would use the following to import the key:
echo $PASSPHRASE | gpg --pinentry loopback --import --passphrase-fd 0 $GPG_PRIVATE_KEY
and the following to use the key:
echo $PASSPHRASE | gpg --pinentry loopback --passphrase-fd 0 --output "${SECRET%.*}" --decrypt "${SECRET%.*}.secret"