我正在尝试使用Blackbox加密我正在使用的存储库中的敏感文件,但我无法使GitLab CI管道加载解密文件所需的私有GPG密钥。
在,你可以看到GitLab CI跑者的输出,其中很明显:
然而,当我运行命令gpg -v --import /tmp/server.gpg
时,我不断获得gpg: no valid OpenPGP data found.
。这毫无意义。
我已经跟踪了我可以找到的所有帖子,但它们要么是关于验证文件内容而不是实际导入正确的密钥,要么密钥实际上是格式错误的,我的显然不是。
我很感激任何帮助,因为我没有取得任何进展。
谢谢!
GitLab CI跑步者的输出:
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
答案 0 :(得分:6)
我找到了答案。在我的.gitlab-ci.yml
中,我改变了我的GPG阅读实现:
- echo $GPG_PRIVATE_KEY > /tmp/server.gpg
- gpg -v --import /tmp/server.gpg
为:
- gpg -v --import <(echo "$GPG_PRIVATE_KEY")
这解决了这个问题。
答案 1 :(得分:0)
在存储库设置中,将变量更改为键入“文件”而不是“变量”。
然后通常将GPG密钥作为文件导入:
gpg -v --import $GPG_PRIVATE_KEY
参考:https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui