Instead of storing environment variables in Gitlab, we encrypt the .env
file using gpg
and commit the encrypted file to the repository. Let’s say that we used key stored in environment variable KEY
, encrypting is easy gpg -c .env
. It will prompt for passphrase and create an encrypted file .env.gpg
.
To decrypt in the pipeline,
gpg --yes --batch --passphrase-file <(echo $KEY) -d ./.env.gpg > .env
I am usually nervous talking about security since there are many ways things can go wrong. But here is my take on the pros of this approach.
Cons