Repository navigation
fix: de-duplicate dnsNames when multiple Gateway/ListenerSet listeners share a Secret - #8978
Conversation
|
Hi @speer. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
kunalworldwide
left a comment
There was a problem hiding this comment.
De-duplicating hosts before splitting into DNS names and IPs is the right fix. The regression test clearly shows how two listeners with the same hostname and Secret previously produced two identical dnsNames, causing ACME finalize to fail.
Using a map-based dedup before extractCertificateInput is clean and preserves the existing order semantics. One minor suggestion: consider also asserting in the test that the resulting Certificate has exactly the expected SANs and no extras, so future regressions in the split logic are caught too.
LGTM.
…s share a Secret Listeners referencing the same Secret and hostname produced repeated entries in Certificate.spec.dnsNames, so the CSR carried more SANs than the ACME order had identifiers and finalize failed. De-duplicate hosts before building dnsNames/ipAddresses. Signed-off-by: Stefan Peer <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a Gateway API certificate-shim edge case where multiple listeners referencing the same Secret and hostname could cause duplicated entries in Certificate.spec.dnsNames, leading to ACME finalize failures due to a CSR SAN count mismatch.
Changes:
- Refactors host processing into a new
splitHostshelper that de-duplicates host entries and splits them into DNS names vs IP addresses while preserving first-seen order. - Updates certificate construction to use
splitHostsinstead of inline host splitting logic. - Adds regression coverage in
TestSyncfor the “multiple listeners share Secret+hostname” scenario and adds focused unit tests forsplitHosts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/controller/certificate-shim/sync.go | Introduces splitHosts to de-duplicate and split host inputs, and uses it during Certificate spec construction. |
| pkg/controller/certificate-shim/sync_test.go | Adds a Gateway regression test to ensure no duplicated dnsNames and a dedicated splitHosts unit test table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for contributing! Seems like a sensible fix /ok-to-test |
|
/retest |
|
All tests are passing, this is good to merge. Thanks! /lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ThatsMrTalbot The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/cherry-pick release-1.21 with claude fable-5 |
|
@wallrj: new pull request created: #9234 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Pre-backport safety review Before merging the cherry-pick to 1. The dedup can be undone by annotations
2.
|
|
Tracking issues for the follow-ups from the review above:
[Claude Fable 5.1] |
certNeedsUpdate compared dnsNames, secretName, issuerRef and the private key settings of the desired and existing Certificate, but never looked at spec.ipAddresses. buildCertificates does populate ipAddresses from the IP-literal hosts of an Ingress, Gateway or ListenerSet, so a change to the IP SANs was computed and then dropped because the shim decided the existing Certificate was already up to date. The same gap kept the de-duplication from cert-manager#8978 from repairing Certificates that already carried duplicate IP SANs. Compare ipAddresses by length and then element by element, exactly like dnsNames, so IP SAN additions, removals, re-orderings and de-duplication reach the existing Certificate. Add a unit test for certNeedsUpdate covering equal, nil-vs-empty, changed, added, removed, de-duplicated and re-ordered ipAddresses, and a TestSync case that changes the IP-literal host of an Ingress and expects the existing Certificate to be updated. Signed-off-by: KR-Ravindra <[email protected]>
certNeedsUpdate compared dnsNames, secretName, the issuer reference and the private key settings, but never read Spec.IPAddresses. buildCertificates does set IPAddresses on the desired Certificate, so the new value was computed and then discarded: a change to the IP SANs of an Ingress or a Gateway never reached an existing Certificate. This also limited what cert-manager#8978 repairs. A Certificate created by an older cert-manager with duplicate IP SANs kept its duplicates after the upgrade, leaving issuance stuck on badCSR until the Certificate was deleted by hand. Compare IPAddresses the same way DNSNames is compared. Signed-off-by: David-Uka <[email protected]>
@wallrj Thank you for the release! We tested the version in our environment and I can confirm that it works as expected. |
Pull Request Motivation
Listeners referencing the same Secret and hostname produced repeated entries in Certificate.spec.dnsNames, so the CSR carried more SANs than the ACME order had identifiers and finalize failed. De-duplicate hosts before building dnsNames/ipAddresses.
Kind
/kind bug
Release Note