fix: support multi sni config #2590
Open
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.
Type of change:
What this PR does / why we need it:
Problem Description
This PR fixes a critical bug where wildcard certificates could not be properly used across multiple SNIs when the same certificate is referenced by different Kubernetes resources (Ingress, Gateway, or ApisixTls).
Root Cause:
The original implementation generated SSL IDs based on certificate content using
id.GenID(string(cert))
. This caused ID collisions when multiple resources used the same certificate:Impact:
*.example.com
) could not support multiple different SNIsSolution
Changed SSL ID generation from certificate-content-based to
namespace + secretName + sni
-based:Before:
After:
This ensures:
Code Changes
Modified Files:
internal/adc/translator/ingress.go
translateIngressTLS()
to return[]*adctypes.SSL
instead of*adctypes.SSL
namespace + "_" + secretName + "_" + sni
internal/adc/translator/gateway.go
translateSecret()
to create one SSL object per SNIsecretNN.Namespace + "_" + secretNN.Name + "_" + sni
mergeSSLWithSameID()
function (no longer needed)slices
importinternal/adc/translator/apisixtls.go
TranslateApisixTls()
to create one SSL object per SNIsecretKey.Namespace + "_" + secretKey.Name + "_" + sni
Total Changes:
Example Scenario
Before (Broken):
After (Fixed):
Compatibility Impact
BREAKING CHANGE
This is a breaking change because SSL IDs will change after upgrade:
Upgrade Procedure:
Memory Impact:
Testing
Tested scenarios:
Related Issues
Fixes #[issue-number] (if applicable)
Pre-submission checklist:
Note on backward compatibility: This is a breaking change that fixes a critical bug. The benefits (fixing wildcard certificate support) outweigh the migration cost. Users need to manually clean up orphaned SSL objects after upgrade. This has been noted in the upgrade guide.
Note on tests: Integration tests will be added in a follow-up commit to cover:
Note on documentation: CHANGELOG and upgrade guide updates will be included before merge.
SSL Configuration
Wildcard Certificates
Wildcard certificates can now be used across multiple resources and SNIs:
Both SNIs will work correctly. Each SNI creates a separate SSL object in APISIX.