Skip to content

Instantly share code, notes, and snippets.

@marshyon
Created October 26, 2022 21:25
Show Gist options
  • Save marshyon/aafc4cb1b5758fff99203a2ffeb66185 to your computer and use it in GitHub Desktop.
Save marshyon/aafc4cb1b5758fff99203a2ffeb66185 to your computer and use it in GitHub Desktop.
git secret can be used to secure plain text secrets as gpg encrypted data which may be then commited to git repositories

disclaimer

at your own risk

never commit plain text passwords to Git, even private ones - they can always be leaked without your knowing at some point

where appropriate, dont use git secret, instead use a secret vault as in AWS, Azure or something like Hashicorp vault or secured secrets in pipelines, again when appropriate, you know the drill

pre-requisites

ideally linux, WSL or mac although Cygin and friends will also work in windows cmd like shells and no doubt PowerShell environments will now support the same but admittedly I have not tried to make this work for myself

you must have gpg installed and set up with a private key

git ofcourse must be installed

get the tool

git clone https://github.com/sobolevn/git-secret.git git-secret

and see installation instructions to

make build
PREFIX="/usr/local" make install

usage

within a git repo, initialise git secret

git secret init

add current gpg user for git secret to encrypt for

git secret tell -m

edit file hideme.txt and add this to .gitignore so it will not be commited to git

add hideme.txt to git secret

git secret add hideme.txt

encrypt the file

git secret hide

the plain text file can be removed and git can be used to store the encrypted file in the normal way

decrypt the file with

git secret reveal

then edit as required, then re-encrypt with

git secret hide

then remove the plain text file and so on ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment