上 git-secret:在 Git 存儲庫中加密和存儲密鑰( 三 )

  • 由于 --home-directory 的位置與主機系統共享 , 因此套接字創建將失敗 。
  • 對應的錯誤信息是:
    gpg: can't connect to the agent: IPC connect call failedgpg-agent: error binding socket to '/var/www/app/.gitsecret/keys/S.gpg-agent': I/O error解決此問題,可以通過將其他 gpg 配置文件放在 .gitsecret/keys 目錄中,將 gpg 配置為對套接字使用不同的位置:
    S.gpg-agent
    %Assuan%socket=/tmp/S.gpg-agents.gpg-agent.ssh
    %Assuan%socket=/tmp/S.gpg-agentgpg-agent.conf
    extra-socket /tmp/S.gpg-agent.extrabrowser-socket /tmp/S.gpg-agent.browser添加、列出和刪除用戶要添加新用戶,必須首先導入其公用 gpg 密鑰 。然后運行:
    email="pascal.landau@example.com"git secret tell "$email"在這種情況下 , 用戶pascal.landau@example.com 現在將能夠解密這些密鑰 。要顯示用戶請運行:
    git secret whoknows$ git secret whoknowspascal.landau@example.com要刪除用戶,請運行:
    email="pascal@example.com"git secret killperson "$email"這時此命令在 git-secret >= 0.5.0 中已重命名為 removeperson
    $ git secret killperson pascal.landau@example.comgit-secret: removed keys.git-secret: now [pascal.landau@example.com] do not have an access to the repository.git-secret: make sure to hide the existing secrets again.用戶 pascal@example.com 將無法再解密這些密鑰 。
    注意刪除用戶后需要重新加密機密,并輪換加密的密鑰 。
    添加、列出和刪除文件以進行加密運行 git secret add [filenames...] 來為文件加密:
    git secret add .env如果 .env 沒有被添加到 .gitignore ,git-secret 將顯示警告并自動添加 。
    git-secret: these files are not in .gitignore: .envgit-secret: auto adding them to .envgit-secret: 1 item(s) added.如已添加,則添加文件時不會發出警告 。
    $ git secret add .envgit-secret: 1 item(s) added.只需要添加一次文件 。然后將它們存在 .gitsecret/paths/mapping.cfg :
    $ cat .gitsecret/paths/mapping.cfg.env:505070fc20233cb426eac6a3414399d0f466710c993198b1088e897fdfbbb2d5還可以通過以下方式顯示添加的文件:
    git secret list$ git secret list.env需要主要的是,這個時候文件尚未加密,如果要從加密中刪除文件 , 請運行:
    git secret list$ git secret list.env輸出:
    $ git secret remove .envgit-secret: removed from index.git-secret: ensure that files: [.env] are now not ignored.加密文件要加密文件,請運行:
    git secret hide輸出:
    $ git secret hidegit-secret: done. 1 of 1 files are hidden.所有通過 git secret tell 被添加的用戶能夠解密這些已經加密的文件,這也意味著每當添加新用戶時 , 您都需要再次運行此命令 。
    解密文件可以通過以下方式解密文件:
    git secret reveal輸出:
    $ git secret revealFile '/var/www/app/.env' exists. Overwrite? (y/N) ygit-secret: done. 1 of 1 files are revealed.
    • 文件被解密并將覆蓋當前未加密的文件 。
    • 使用 -f 選項強制覆蓋并以非交互方式運行 。
    • 如果只想檢查加密文件的內容,可以使用 git secret cat $filename 例如,git secret cat. env 。
    gpg 密鑰受密碼保護時,需要通過 -p 選項傳遞密碼 。以下是密碼示例 123456
    git secret reveal -p 123456顯示加密和解密文件間的變化加密文件的一個問題是,無法在遠程工具的代碼審查期間審查加密文件 。為了了解進行了哪些更改,顯示加密文件和解密文件之間的更改能夠幫助解決這個問題 ??梢酝ㄟ^以下方式完成:
    git secret changes輸出:
    $ echo "foo" >> .env$ git secret changesgit-secret: changes in /var/www/app/.env:--- /dev/fd/63+++ /var/www/app/.env@@ -34,3 +34,4 @@ MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}"+foo注意底部的 +foo. 它是通過在第一行 echo "foo">>>.env 添加的 。
    本文是git-secret用法的上篇,在下篇中我們將會介紹git-secret的初始設置、Makefile調整等內容,保持關注哦~

    推薦閱讀