git-crypt icon indicating copy to clipboard operation
git-crypt copied to clipboard

[Question] How would a deployment server decrypt a file? Assuming it's a `.env` file

Open simkimsia opened this issue 3 years ago • 3 comments

hi there, I'm completely new to git-crypt.

I read an article about this git-crypt and I have a question. Suppose I use git-crypt to encrypt a .env file for production environment secrets. I push it to my github repo.

My deployment server would typically run a git pull and it has the deploy key stored on the same GitHub repo ensuring it's read-only.

Now how would the deployment server decrypt the .env correctly?

simkimsia avatar Jan 03 '21 08:01 simkimsia

Presumably your deployment system would pass along the required credentials ... a GPG private key or a passphrase as an environment variable. The secret passed along in memory as part of the deployment is presumably smaller than whatever you have encrypted in the repository and doesn't need to be versioned. You use the secret from your deployment system to unlock the repository after checkout.

alerque avatar Jan 07 '21 14:01 alerque

Git-crypt supports providing a symmetric key with git-crypt unlock filename. You can get this key by running git-crypt export-key filename. Normally this symmetric key sits inside .git-crypt directory, encrypted with your gpg key.

etam avatar Apr 07 '22 13:04 etam

Assuming your deployment system can pass your base64-encoded git-crypt key in an environment variable named GIT_CRYPT_KEY, you could unlock as follows:

# Unlock git-crypt.
echo $GIT_CRYPT_KEY | base64 -d | git-crypt unlock -

An example with GitHub Actions: https://github.com/eidorb/aws/blob/c77af3896df081bc7e7d690d2617628ae7bdc870/.github/workflows/deploy.yml#L52-L53.

eidorb avatar Jul 03 '22 05:07 eidorb