Skip to content

Commit 7f2e0aa

Browse files
matejmatuskayuravk
authored andcommitted
removeobsoletegpgkeys: Adjust for converting
When doing upgrade + conversion, removing obsolete GPG from the current (or target for that matter) distro doesn't make sense, because we are moving to a different distro. Instead, all distro provided keys from the source distro need to be removed, as the target distro uses it's own keys. Those are imported elsewhere later during the upgrade. A new list is added to the gpg-signatures.json maps, which contains the names of the fake RPMs "generated" upon importing a GPG key into the RPM DB. These are in the order the key IDs ("keys" in the map) are in, however the mapping is not always 1:1 (e.g. the Centos SIG Extras keys). The key id could be mapped to the RPM names, however since the RPM NVR format is: gpg-pubkey-<last 8 chars from key ID>-<creation time of the signature packet> there could be a collision between the key IDs. Some key RPMs are missing in Alma Linux map as I couldn't find out what keys some the fingerprints correspond to. Jira: RHEL-110190 I addded annotations to the keys at: https://github.com/oamg/leapp-repository/wiki/gpg%E2%80%90signatures.json-key-annotations. (cherry picked from commit 37a071d) Keep in the map: - CloudLinux TuxCare key "d07bf2a08d50eb66": ["gpg-pubkey-8d50eb66-64061978"] - CentOS7 (AltArch) key "6c7cb6ef305d49d6": ["gpg-pubkey-305d49d6-55b78768"]
1 parent 7ce17e6 commit 7f2e0aa

7 files changed

Lines changed: 234 additions & 123 deletions

File tree

repos/system_upgrade/common/actors/removeobsoletegpgkeys/actor.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ class RemoveObsoleteGpgKeys(Actor):
88
"""
99
Remove obsoleted RPM GPG keys.
1010
11-
New version might make existing RPM GPG keys obsolete. This might be caused
12-
for example by the hashing algorithm becoming deprecated or by the key
13-
getting replaced.
11+
The definition of what keys are considered obsolete depends on whether the
12+
upgrade also does a conversion:
13+
- If not converting, the obsolete keys are those that are no longer valid
14+
on the target version. This might be caused for example by the hashing
15+
algorithm becoming deprecated or by the key getting replaced. Note that
16+
only keys provided by the vendor of the OS are handled.
17+
- If converting, the obsolete keys are all of the keys provided by the
18+
vendor of the source distribution.
1419
1520
A DNFWorkaround is registered to actually remove the keys.
1621
"""
Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import itertools
2+
13
from leapp.libraries.common.config import get_source_distro_id, get_target_distro_id
24
from leapp.libraries.common.config.version import get_target_major_version
35
from leapp.libraries.common.distro import get_distribution_data
@@ -6,25 +8,48 @@
68
from leapp.models import DNFWorkaround, InstalledRPM
79

810

11+
def _is_key_installed(key):
12+
"""
13+
:param key: The NVR of the gpg key RPM (e.g. gpg-pubkey-1d997668-61bae63b)
14+
"""
15+
name, version, release = key.rsplit("-", 2)
16+
return has_package(InstalledRPM, name, version=version, release=release)
17+
18+
919
def _get_obsolete_keys():
1020
"""
11-
Return keys obsoleted in target and previous versions
21+
Get keys obsoleted in target and previous major versions
1222
"""
1323
distribution = get_target_distro_id()
14-
obsoleted_keys_map = get_distribution_data(distribution).get('obsoleted-keys', {})
24+
obsoleted_keys_map = get_distribution_data(distribution).get("obsoleted-keys", {})
1525
keys = []
1626
for version in range(7, int(get_target_major_version()) + 1):
1727
try:
1828
for key in obsoleted_keys_map[str(version)]:
19-
name, version, release = key.rsplit("-", 2)
20-
if has_package(InstalledRPM, name, version=version, release=release):
29+
if _is_key_installed(key):
2130
keys.append(key)
2231
except KeyError:
2332
pass
2433

2534
return keys
2635

2736

37+
def _get_source_distro_keys():
38+
"""
39+
Get all known keys of the source distro
40+
41+
This includes keys from all relevant previous OS versions as all of those
42+
might be present on the system.
43+
"""
44+
distribution = get_source_distro_id()
45+
keys = get_distribution_data(distribution).get("keys", {})
46+
return [
47+
key
48+
for key in itertools.chain.from_iterable(keys.values())
49+
if _is_key_installed(key)
50+
]
51+
52+
2853
def register_dnfworkaround(keys):
2954
api.produce(
3055
DNFWorkaround(
@@ -36,13 +61,12 @@ def register_dnfworkaround(keys):
3661

3762

3863
def process():
39-
if get_source_distro_id() != get_target_distro_id():
40-
# TODO adjust for conversions, in the current state it would not have
41-
# any effect, just skip it
42-
return
43-
44-
keys = _get_obsolete_keys()
45-
if not keys:
46-
return
64+
if get_source_distro_id() == get_target_distro_id():
65+
# only upgrading - remove keys obsoleted in previous versions
66+
keys = _get_obsolete_keys()
67+
else:
68+
# also converting - we need to remove all keys from the source distro
69+
keys = _get_source_distro_keys()
4770

48-
register_dnfworkaround(keys)
71+
if keys:
72+
register_dnfworkaround(keys)

0 commit comments

Comments
 (0)