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

Is there a way to do unattended unlock with gpg passphrase?

Open xueshanf opened this issue 8 years ago • 5 comments

The use case is for CI/CD system to be able to download git repo, and run git-crypt unlock with a deployment gpg key, protected with passphrase.

xueshanf avatar Sep 01 '16 05:09 xueshanf

I'm designing the deploy process for a current project under the assumption that this is possible, but I haven't actually scripted the CI end yet. In your version would the GPG key itself be coming out of the CI environment or just its passphrase?

alerque avatar Sep 01 '16 07:09 alerque

you should be able to use gpg-agent, evaluate the exported variables- then get the password into the agent [maybe using gpg with --passphrase --batch], then the decrypted key would be in memory in the agent, then try the unlock

jmalacho avatar Sep 14 '16 21:09 jmalacho

Gpg agent plus preset passphrase. You set up gpg home and pass it in environment variable. See for example https://github.com/zalora/nixsap/blob/master/modules/apps/gnupg/default.nix

ip1981 avatar May 02 '17 12:05 ip1981

Here is my guide to how to do this inside a docker container (build time)

git-crypt — Unattended Unlock with GPG Passphrase in Docker

Dockerfile

a7medkamel avatar Jun 04 '18 21:06 a7medkamel

One can also remove passphrase after importing key, this should not be more risky compared to agent since is supposed to be used in CI and all imported keys will be removed after job is finished.

If you have passphrase in variable PASSPHRASE and [email protected] key in file foo.key:

# Import key with password (without decrypting)
gpg --import --batch --pinentry-mode loopback foo.key
# Remove password sequence: old password, new line, empty password, new line
echo -e "$PASSPHRASE\n\n" | gpg --change-passphrase --batch --pinentry-mode loopback --command-fd 0 foo
git-crypt unlock

Peter-Sh avatar Dec 01 '21 08:12 Peter-Sh