Skip to content

Commit d12768e

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 d12768e

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
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 `True`.

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 = True

pulp_rpm/app/tasks/signing.py

Lines changed: 14 additions & 7 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 (
@@ -18,7 +19,6 @@
1819
from pulpcore.plugin.tasking import add_and_remove, general_create
1920
from pulpcore.plugin.util import get_url
2021

21-
from pulp_rpm.app.constants import CHECKSUM_TYPES
2222
from pulp_rpm.app.models.content import RpmPackageSigningResult, RpmPackageSigningService
2323
from pulp_rpm.app.models.package import Package
2424
from pulp_rpm.app.models.repository import RpmRepository
@@ -132,13 +132,20 @@ def _sign_package(package, signing_service, signing_fingerprint):
132132
str(signed_package_path),
133133
(package.signing_keys or []) + [signing_fingerprint],
134134
)
135+
# Read all updated metadata from the signed RPM
136+
cr_pkg = cr.package_from_rpm(str(signed_package_path))
137+
new_pkg_dict = Package.createrepo_to_dict(cr_pkg)
135138
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
139+
extra_fields = {}
140+
if settings.RPM_SIGNING_COPY_LABELS:
141+
extra_fields["pulp_labels"] = package.pulp_labels
142+
signed_package = Package(
143+
**new_pkg_dict,
144+
signing_keys=signing_keys,
145+
is_modular=package.is_modular,
146+
**extra_fields,
147+
)
148+
signed_package.location_href = signed_package.filename
142149
signed_package.save()
143150
ContentArtifact.objects.create(
144151
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)