Skip to content

Fail a signature refetch instead of serving the stale signature - #832

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/stale-release-signature
Nov 28, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/stale-release-signature

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #819.

proxyReleaseSignature refetches a cached Release.gpg or repomd.xml.asc when it was fetched before its release file. When that refetch failed, refreshMetadata fell back to the cached copy, which is the old signature, so the client got the new release file with the old signature and gpgv reported BADSIG.

Now a stale result there becomes the upstream error (502), so apt and dnf keep their old lists and retry. A signature fetched after its release file still gets the usual stale fallback.

Pairing release file and signature by digest, as the Arch handler does, would also keep serving during an outage, but needs more state; this keeps the change small.

  • TestStaleSignatureNotServedWithNewerRelease covers Debian and RPM: 502 while upstream fails, the new signature once it is back. It fails on main.
  • go test ./internal/handler/ and golangci-lint run ./internal/handler/ pass.

Summary by CodeRabbit

  • Bug Fixes
    • Cached Debian and RPM signatures are no longer served when they belong to an older release than the latest fetched release. If the signature cannot be refreshed because the upstream source is unavailable, the request returns an error; retry after the source recovers.
  • Documentation
    • Clarified when RPM detached signatures are refreshed and what happens if the upstream refresh fails.

When a cached Release.gpg or repomd.xml.asc predates its release file and the refetch fails, the stale fallback served the old signature with the new release file, which apt and dnf reject as a bad signature. Return the upstream error instead, so the client can retry.

Fixes git-pkgs#819.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The signature handler now returns a fetch error instead of serving a stale cached signature when its release file has been refreshed. Tests cover Debian and RPM failure and recovery cases. The Metadata TTL documentation now includes RPM detached signatures.

Changes: Detached signature refresh

Layer / File(s) Summary
Reject stale signature fallback
internal/handler/release_index.go, internal/handler/release_signature_test.go, docs/configuration.md
The handler treats a stale signature result as a fetch error. Tests verify a 502 Bad Gateway response during upstream failure and the refreshed signature after recovery for Debian and RPM. The TTL documentation describes the RPM signature refresh behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: andrew

Merge Risk: Minimal · up to b0319

This change makes a failed signature refetch return a 502 instead of serving a stale signature with a newer release file, so apt and dnf can retry. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Fail a signature refetch instead of serving the stale signature" matches the main change. The PR makes a failed refetch of a stale Release.gpg or repomd.xml.asc return an upstream error (50…
Linked Issues check Passed Issue #819 asks that a failed refetch of a stale Release.gpg or repomd.xml.asc not fall back to the old cached signature. The reviewed head changes proxyReleaseSignature in internal/handler/release_in…
Out of Scope Changes check Passed The changes are limited to the issue's scope. release_index.go adds the stale-to-error conversion and an explanatory comment. release_signature_test.go adds a failure toggle to the signedArchive helpe…
Full details: Title check

Explanation

The title "Fail a signature refetch instead of serving the stale signature" matches the main change. The PR makes a failed refetch of a stale Release.gpg or repomd.xml.asc return an upstream error (502) instead of serving the stale cached signature, as the summary and objectives describe. The title is specific and does not use vague terms.

Full details: Linked Issues check

Explanation

Issue #819 asks that a failed refetch of a stale Release.gpg or repomd.xml.asc not fall back to the old cached signature. The reviewed head changes proxyReleaseSignature in internal/handler/release_index.go. When refreshMetadata returns a stale result with no error, the function now sets res.err from res.upstreamErr and returns the metadata fetch error (502) through writeMetadataFetchError. Apt and dnf then keep their old lists and retry, which is the first outcome #819 describes. The signature-predates-release check is unchanged, so a signature fetched after its release file still uses the stale fallback. The new test TestStaleSignatureNotServedWithNewerRelease covers Debian and RPM: 502 while upstream fails, and the new signature after recovery. The pairing-by-digest alternative is not required; the PR description states it is out of scope. Residual uncertainty: the diff does not show refreshMetadata. The fix depends on it setting upstreamErr whenever it returns a stale result. The PR summary and the test support this, but I did not confirm it in refreshMetadata.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the issue's scope. release_index.go adds the stale-to-error conversion and an explanatory comment. release_signature_test.go adds a failure toggle to the signedArchive helper, updates existing callers for the extra return value, and adds the Debian and RPM regression test. docs/configuration.md documents that RPM detached signatures fail rather than serve stale when the refetch fails. The documentation and test changes support the code change and do not add unrelated behavior.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 710ee30a-2d12-4f0d-ad2b-c5b96c1d5840
Commits

Reviewing files that changed from the base of the PR and between 81fc611 and b0319ed.

Files selected for processing: 3

  • docs/configuration.md
  • internal/handler/release_index.go
  • internal/handler/release_signature_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@andrew
andrew merged commit 3c6495a into git-pkgs:main Nov 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale fallback can serve an old detached signature with a refreshed release file

2 participants