Repository navigation
Reuse the existing signed package when the unsigned content is unchanged - #829
Merged
Merged
Conversation
Signing is not deterministic: the Unity attestation carries an RFC 3161 timestamp, so signing identical content produces a different tarball, a different SHA-1 and a different published checksum. A full rebuild (image update) therefore rewrites the checksum of every package, which invalidates downstream mirrors and caches for no reason. Record the SHA-256 of the unsigned tarball next to each signed package and reuse the signed artifact when a rebuild produces the same unsigned bytes. The conversion now writes the unsigned tarball to a sibling file, hashes it, and only calls the signer when the digest differs from the recorded one. forceUpdate no longer deletes signed packages up front, so the reuse path can see the previous artifact; the conversion still runs for every version. The recorded digest is removed together with the package, and a failed conversion keeps the previous signed artifact when it was reused.
Add offline unit tests covering first signed package generation, byte-for-byte reuse when unsigned content is unchanged across forced rebuilds, re-signing when content or sidecar state changes, sidecar cleanup in DeleteUnityPackage, and no-sidecar behavior when signing is disabled or excluded. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Keep the existing signed tarball untouched while extracting and running the signer into a temporary staging directory, and require the signed output file to exist and be non-empty before replacing the published tarball and writing the .unsigned.sha256 sidecar. Also remove stale sidecar files when a package is excluded from signing. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every build of a package runs
upm pack, and signing is not deterministic: the attestation embeds an RFC 3161 timestamp, so the same content signed twice produces different bytes. The signed tarball, its SHA-1 and thedist.shasumin the registry metadata therefore change on every rebuild, even when the package content is identical.This happens on every image update, because a changed registry version clears the cache and regenerates all packages. Downstream mirrors and clients then see a checksum change for packages that did not change, and anything caching by checksum has to re-download everything.
Change
<file>.tgz.unsignedand hashed with SHA-256.<file>.tgz.unsigned.sha256digest matches and the signed tarball and.sha1are present, the existing signed package is kept and the signer is not called.<file>.tgz.unsignedandupm packsigns into a temporary staging directory before replacing the published.tgzand writing<file>.tgz.unsigned.sha256, so a failed signing run does not overwrite the existing signed tarball or record a sidecar for an unsigned package.forceUpdatekeeps signed packages on disk for packages eligible for signing so the reuse path can see them, while still deleting stale.tgz,.sha1, and.tgz.unsigned.sha256artifacts when signing is disabled or excluded for a package.DeleteUnityPackagedeletes<file>.tgz.unsigned.sha256alongside.tgzand.sha1.src/UnityNuGet.Tests/RegistryCacheSigningTests.cscovering initial signing, unchangedforceUpdatereuse, content/sidecar/artifact invalidation,DeleteUnityPackagecleanup, disabled/regex-excluded signing, and failed-signer preservation/recovery.Packages without a recorded digest (all existing ones) are signed once, then start reusing.
Validation
dotnet test src/UnityNuGet.Tests -c Releaseoffline suites (RegistryCacheSigningTests,PackageWithoutAssembliesTests,UnityPackageSignerTests,UnityMetaTests,VersionRangeConverterTests,PlatformDefinitionTests,NuGetHelperTests,NpmPackageListAllResponseConverterTests,NativeLibrariesTests,RoslynAnalyzersHelperTests, andRegistryCacheTests.GetNpmVersion): 132 passed, 0 failed (using an in-memory.nupkgand cross-platformupmshim for signing tests).dotnet test src/UnityNuGet.Server.Tests -c Release: 12 passed, 0 failed.Notes