Skip to content

Commit 8ffce15

Browse files
committed
Fix package metadata fields not updated after signing
When creating a signed copy of a package, all RPM metadata fields are now refreshed from the signed file using createrepo_c, ensuring size_package, rpm_header_start, rpm_header_end, time_file, and other fields stay consistent. fixes #4383 Assisted By: Claude Opus 4.6
1 parent 0136f85 commit 8ffce15

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

CHANGES/4383.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated package signing to refresh all RPM metadata fields from the signed package file, ensuring size, header offsets, and other fields stay consistent after signing.

docs/admin/reference/settings.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ appears in the "file" field of the time element for each package in primary.xml.
6969
## MAX_PACKAGE_SIGNING_WORKERS
7070

7171
Sets the number of workers that pulp_rpm uses when concurrently signing packages. Defaults to 5.
72+
73+
74+
## RPM_SIGNING_COPY_LABELS
75+
76+
When set to `True`, pulp_rpm will copy the `pulp_labels` from the original unsigned package
77+
to the newly created signed package during the package signing process. This is useful when
78+
labels should be preserved across signing operations. Defaults to `False`.

pulp_rpm/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
# workaround for: https://github.com/pulp/pulp_rpm/issues/4125
2121
SPECTACULAR_SETTINGS__OAS_VERSION = "3.0.1"
2222
MAX_PACKAGE_SIGNING_WORKERS = 5
23+
RPM_SIGNING_COPY_LABELS = False

pulp_rpm/app/tasks/signing.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from tempfile import NamedTemporaryFile
77

8+
import createrepo_c as cr
89
from django.conf import settings
910

1011
from pulpcore.plugin.models import (
@@ -132,13 +133,22 @@ def _sign_package(package, signing_service, signing_fingerprint):
132133
str(signed_package_path),
133134
(package.signing_keys or []) + [signing_fingerprint],
134135
)
136+
# Read all updated metadata from the signed RPM
137+
cr_pkg = cr.package_from_rpm(str(signed_package_path))
138+
new_pkg_dict = Package.createrepo_to_dict(cr_pkg)
135139
artifact = _save_artifact(signed_package_path)
136-
signed_package = package
137-
signed_package.pk = None
138-
signed_package.pulp_id = None
139-
signed_package.pkgId = artifact.sha256
140-
signed_package.checksum_type = CHECKSUM_TYPES.SHA256
141-
signed_package.signing_keys = signing_keys
140+
new_pkg_dict["pkgId"] = artifact.sha256
141+
new_pkg_dict["checksum_type"] = CHECKSUM_TYPES.SHA256
142+
extra_fields = {}
143+
if settings.RPM_SIGNING_COPY_LABELS:
144+
extra_fields["pulp_labels"] = package.pulp_labels
145+
signed_package = Package(
146+
**new_pkg_dict,
147+
signing_keys=signing_keys,
148+
is_modular=package.is_modular,
149+
**extra_fields,
150+
)
151+
signed_package.location_href = signed_package.filename
142152
signed_package.save()
143153
ContentArtifact.objects.create(
144154
artifact=artifact,

pulp_rpm/tests/functional/api/test_package_signing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def test_signed_repo_modify(
300300
).results[0]
301301
assert signed_package.pulp_href != created_package.pulp_href
302302
assert signed_package.signing_keys == [fingerprint]
303+
assert signed_package.time_file != created_package.time_file
303304
assert sorted(task_result.created_resources) == sorted(
304305
[repository.latest_version_href, signed_package.pulp_href, signed_package.artifact]
305306
)

0 commit comments

Comments
 (0)