
面向 Git 用户的加密工具。
Strongbox 让加密和解密存储在 Git 中的文件变得简单,同时与典型的 Git 工作流保持最小差异。安装后,Strongbox 支持正常使用 git diff 等命令,并且仓库中应被加密的所有文件在你的工作副本中保持解密状态。
如需,它支持为不同目录使用不同的密钥。基于 .gitattributes,它可以覆盖你希望加密的任意数量或多或少的文件。
安装
你可以从 https://github.com/uw-labs/strongbox/releases 获取二进制文件。
或者,假设你有一个可用的 Go 安装,你可以通过以下命令进行安装:
$ go install github.com/uw-labs/strongbox/v2@latest
Homebrew
如果你在 macOS 或 Linux 上并且已安装 Homebrew, 获取 Strongbox 只需运行:
$ brew install uw-labs/tap/strongbox
用法
Strongbox 支持 age 和 siv 加密。Age 是推荐的选项。
| encryption | identity / keyring file | recipient / key file |
|---|---|---|
| age | .strongbox_identity | .strongbox_recipient |
| siv | .strongbox_keyring | .strongbox-keyid |
如果同一目录中同时存在 identity / key 文件,
.strongbox_identity (age) 将被优先使用。
-
作为一次性操作,运行
strongbox -git-config来安装插件。 这将编辑全局 Git 配置以启用 Strongbox 的 filter 和 diff 配置。 -
在每个想要使用 Strongbox 的仓库中,创建
.gitattributes文件, 其中包含由 Strongbox 管理的模式。例如:
secrets/* filter=strongbox diff=strongbox merge=strongbox -
Generate a key to use for the encryption, for example:
strongbox -gen-identity my-keyThis will generate a new age keypair and place it in
~/.strongbox_identity. You can specify alternative location using-identity-fileflag or setting$HOMEenvvar. The generated public key is printed when the command completes:public key: agexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -
Add this public key in the file
.strongbox_recipientin your repository (https://github.com/FiloSottile/age?tab=readme-ov-file#recipient-files). This can be in the same directory as the protected resource(s) or any parent directory. When searching for.strongbox_recipientfor a given resource, Strongbox will recurse up the directory structure until it finds the file. This allows using different keys for different subdirectories within a repository. -
如果 Strongbox 身份文件存储在其他位置
-identity-file可以使用。即strongbox [-identity-file <identity_file_path>] -gen-identity key-name
现有项目
Strongbox 使用 clean 和 smudge 过滤器 来加密和解密文件。
如果您正在克隆一个使用 Strongbox 的项目,在克隆(检出)之前,您的 Strongbox 身份文件中必须包含身份。否则,该过滤器将失败,并且不会在检出时解密文件。
如果您已在本地拥有该项目并添加了身份,您可以删除并 检出文件以强制应用过滤器:
rm <files> && git checkout -- <files>
验证
在 git add 之后,您可以在索引中验证文件已加密:
$ git show :/path/to/file
验证文件在提交中已加密:
$ git show HEAD:/path/to/file
你应该看到的是一个 Strongbox 加密资源,这就是将被推送到远程的内容。
将整个分支(其在远程上的呈现形式)与 master 进行比较:
$ git diff-index -p master
密钥轮换
要轮换密钥,请将 .strongbox_recipient 更新为新值,然后
touch 所有由 .gitattributes 覆盖的文件/目录。所有受影响的文件
现在应显示为“已修改”。
安全性
Strongbox 使用 age 和 rfc5297 中定义的 SIV-AES。
测试
运行集成测试:
$ make test
SIV 手动解密
以下命令可用于在 Git 流程之外解密文件:
# decrypt using default keyring file `$HOME/.strongbox_keyring`
strongbox -decrypt -recursive <path>
# decrypt using `keyring_file_path`
strongbox -keyring <keyring_file_path> -decrypt -recursive <path>
# decrypt using private key `<key>`
strongbox -key <key> -decrypt -recursive <path>
# decrypt single file with given key
strongbox -decrypt -key <key>
已知问题
克隆文件顺序(仅限 SIV)
假设在仓库根目录存在一个 .strongbox-keyid,且同一目录下有一个加密文件,并且 该文件在字母顺序上位于 key-id 文件之前。
Git 按字母数字顺序检出文件,因此如果 strongboxed 文件在 .strongbox-keyid 存在于磁盘上之前被检出,strongbox 将找不到解密密钥。
克隆文件的顺序由索引决定。
变通方法
- 克隆仓库,让解密失败。删除加密文件,并对已删除的文件执行
git checkout。 - 将受影响的文件从
.strongbox-keyid文件移动到子目录