yum 安装和更新失败 - 为“CentOS-7 - 更新”存储库列出的 GPG 密钥已经安装,但它们不正确

ile*_*ras 6 yum centos gpg

我被这个更新终止错误难住了。

此错误会压缩所有更新,直到我在更新存储库上禁用 gpgcheck。IE /etc/yum.repos.d/CentOS-Base.repo|[更新].gpgcheck=0

它发生在我拥有的每台机器上 - 起初我以为这是一个“宠物/雪花”类型的问题,但不,它影响了整个牛群。

warning: /var/cache/yum/x86_64/7/updates/packages/scap-security-guide-0.1.36-9.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f533f4fa: NOKEY
Public key for scap-security-guide-0.1.36-9.el7.centos.noarch.rpm is not installed
scap-security-guide-0.1.36-9.el7.centos.noarch.rpm                               | 4.4 MB  00:00:03
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

The GPG keys listed for the "CentOS-7 - Updates" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.


 Failing package is: scap-security-guide-0.1.36-9.el7.centos.noarch
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Run Code Online (Sandbox Code Playgroud)

gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 显示正确的指纹。

diff/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7匹配。

file 说 /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 是 PGP 公钥块。

stat 说这是一个普通文件。

ls -lZa /etc/pki/rpm-gpg/ 显示 root:root 拥有的所有文件,安全上下文:system_u:object_r:cert_t:s0

lsattr /etc/pki/rpm-gpg/ 显示没有设置属性。

没有报告磁盘错误。

自 2016 年安装操作系统以来,没有任何其他更新失败的内存或记录。

软件包的 URL 是http://mirror.centos.org/centos/7.5.1804/updates/x86_64/Packages/scap-security-guide-doc-0.1.36-9.el7.centos.noarch.rpm

yum provides scap-security-guide 说:scap-security-guide-0.1.36-9.el7.centos.noarch 在回购中:更新

/etc/yum.repos.d/CentOS-Base.repo (excerpt)
[base]
name=CentOS-$releasever - Base
mirrorlist= http://mirrorlist.centos.org/?release= $releasever&arch=$basearch&repo=os&infra=$infra
#baseurl= http://mirror.centos.org/centos/ $releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#发布的更新
[updates]
name=CentOS-$releasever - 更新
mirrorlist= http://mirrorlist.centos.org/?release= $releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl= http://mirror.centos.org/ centos/ $releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

/etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1 bugtracker_url
= http:// /bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#安装 deltarpm 后添加
deltarpm=-1

重新启动后,我运行了 yum clean all它清理了所有活动的存储库:base epel extras mariadb psychotic updates
其次是 rm -rf /var/cache/yum
在重新运行之前yum update
它再次抛出错误并继续这样做

Centos 7.4
Centos 7.5

xx4*_*x4h 1

也许镜像确实有问题或者某种 MITM。

首先(缓存完好,所以在删除之前/var/cache/yum)获取Key ID(Key ID的最后8​​个字符,第9个是换行符)

rpm -qpi /var/cache/yum/x86_64/7/updates/packages/scap-security-guide-0.1.36-9.el7.centos.noarch.rpm | tail -c9
Run Code Online (Sandbox Code Playgroud)

就我而言,这是f4a80eb5(我认为在你的情况下应该是相同的)

接下来,我们列出所有 rpm 已知的 gpg 公钥并搜索使用我们的软件包的那个

rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n' | grep f4a80eb5
Run Code Online (Sandbox Code Playgroud)

这应该给我们一个结果

gpg-pubkey-f4a80eb5-53a7ff4b    gpg(CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>)
Run Code Online (Sandbox Code Playgroud)

如果命令没有输出rpm -q gpg-pubkey,这可能是以下两种情况之一

  1. rpm 无法看到公钥,您可能需要使用以下命令导入它

    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    Run Code Online (Sandbox Code Playgroud)
  2. 来自镜像的包使用正确的密钥进行签名,这可能是中间人攻击或镜像超越。

如果你得到一个结果,我真的不知道现在可能是什么问题。我会strace深入研究并实际找出问题所在。