GitLab CI 上的 Blackbox,无法加载 GPG 私钥

Blackbox on GitLab CI, unable to load GPG private key

我正在尝试使用 Blackbox 来加密我正在使用的存储库中的敏感文件,但我无法使 GitLab CI 管道加载 GPG 密钥所需的私钥解密文件。

在 ,您可以看到 GitLab CI 运行ner 的输出,其中很明显:

但是,当我 运行 命令 gpg -v --import /tmp/server.gpg 时,我一直收到 gpg: no valid OpenPGP data found.。这毫无意义。

我已经关注了我能找到的所有关于此的帖子,但它们要么是关于验证文件内容而不是实际导入正确的密钥,要么是密钥实际上是格式错误的,而我的显然不是。

我将不胜感激,因为我在这件事上没有取得任何进展。

谢谢!

来自 GitLab 的输出 CI 运行ner:

Running with gitlab-ci-multi-runner 9.1.0 (0118d89) on docker-auto-scale (e11ae361)
Using Docker executor with image golang:1.8.1 ...
Using docker image sha256:3858bc6d4732445082339c9ccccfe56bf599d1fe7d9e850fb67ceec76807ed8d for predefined container...
Pulling docker image golang:1.8.1 ...
Using docker image golang:1.8.1 ID=sha256:6d0bfafa0452c6398be979f89614b5e3cb5d10e853ccd4f5791c4971a88065e0 for build container...
Running on runner-e11ae361-project-3172553-concurrent-0 via runner-e11ae361-machine-1493644095-36064084-digital-ocean-2gb...
Cloning repository...
Cloning into '/builds/project/repo'...
Checking out 7013b30a as feature/blackbox...
Skipping Git submodules setup
$ git clone https://github.com/StackExchange/blackbox
Cloning into 'blackbox'...
$ cd blackbox
$ make manual-install
Symlinking files from ./bin to /usr/local/bin
Done.
$ echo $GPG_PRIVATE_KEY > /tmp/server.gpg
$ chmod 400 /tmp/server.gpg
$ cat /tmp/server.gpg
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v2

[redacted]
-----END PGP PRIVATE KEY BLOCK-----
$ gpg -v --list-keys
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during 
this run
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: using PGP trust model
$ gpg -v --import /tmp/server.gpg
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
ERROR: Job failed: exit code 1

我找到了答案。在我的 .gitlab-ci.yml 中,我更改了我的 GPG 读取实现:

- echo $GPG_PRIVATE_KEY > /tmp/server.gpg
- gpg -v --import /tmp/server.gpg

至:

- gpg -v --import <(echo "$GPG_PRIVATE_KEY")

这解决了问题。

在存储库设置中将变量更改为键入“文件”而不是“变量”。

然后将GPG密钥作为文件正常导入:

gpg -v --import $GPG_PRIVATE_KEY

参考:https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui