@@ -22,7 +22,6 @@ import (
2222 "encoding/json"
2323 "encoding/pem"
2424 "fmt"
25- "slices"
2625
2726 "github.com/api7/gopkg/pkg/log"
2827 "github.com/pkg/errors"
@@ -52,7 +51,6 @@ func (t *Translator) TranslateGateway(tctx *provider.TranslateContext, obj *gate
5251 result .SSL = append (result .SSL , ssl ... )
5352 }
5453 }
55- result .SSL = mergeSSLWithSameID (result .SSL )
5654
5755 rk := utils .NamespacedNameKind (obj )
5856 gatewayProxy , ok := tctx .GatewayProxies [rk ]
@@ -82,7 +80,7 @@ func (t *Translator) translateSecret(tctx *provider.TranslateContext, listener g
8280 sslObjs := make ([]* adctypes.SSL , 0 )
8381 switch * listener .TLS .Mode {
8482 case gatewayv1 .TLSModeTerminate :
85- for _ , ref := range listener .TLS .CertificateRefs {
83+ for refIndex , ref := range listener .TLS .CertificateRefs {
8684 ns := obj .GetNamespace ()
8785 if ref .Namespace != nil {
8886 ns = string (* ref .Namespace )
@@ -123,9 +121,14 @@ func (t *Translator) translateSecret(tctx *provider.TranslateContext, listener g
123121 }
124122 sslObj .Snis = append (sslObj .Snis , hosts ... )
125123 }
124+ << << << < HEAD
126125 // Note: use cert as id to avoid duplicate certificate across ssl objects
127126 sslObj .ID = id .GenID (string (cert ))
128127 log .Debugw ("generated ssl id" , zap .String ("ssl id" , sslObj .ID ), zap .String ("secret" , secret .Namespace + "/" + secret .Name ))
128+ == == == =
129+ sslObj .ID = id .GenID (fmt .Sprintf ("%s_%s_%d" , adctypes .ComposeSSLName (internaltypes .KindGateway , obj .Namespace , obj .Name ), listener .Name , refIndex ))
130+ t .Log .V (1 ).Info ("generated ssl id" , "ssl id" , sslObj .ID , "secret" , secretNN .String ())
131+ >> >> >> > 5 f0d1af1 (fix : generate unique SSL IDs to prevent certificate conflicts across different hosts (#2592 ))
129132 sslObj .Labels = label .GenLabel (obj )
130133 sslObjs = append (sslObjs , sslObj )
131134 }
@@ -242,47 +245,3 @@ func (t *Translator) fillPluginMetadataFromGatewayProxy(pluginMetadata adctypes.
242245 pluginMetadata [pluginName ] = pluginConfig
243246 }
244247}
245-
246- // mergeSSLWithSameID merge ssl with same id
247- func mergeSSLWithSameID (sslList []* adctypes.SSL ) []* adctypes.SSL {
248- if len (sslList ) <= 1 {
249- return sslList
250- }
251-
252- // create a map to store ssl with same id
253- sslMap := make (map [string ]* adctypes.SSL )
254- for _ , ssl := range sslList {
255- if existing , exists := sslMap [ssl .ID ]; exists {
256- // if ssl with same id exists, merge their snis
257- // use map to deduplicate
258- sniMap := make (map [string ]struct {})
259- // add existing snis
260- for _ , sni := range existing .Snis {
261- sniMap [sni ] = struct {}{}
262- }
263- // add new snis
264- for _ , sni := range ssl .Snis {
265- sniMap [sni ] = struct {}{}
266- }
267- // rebuild deduplicated snis list
268- newSnis := make ([]string , 0 , len (sniMap ))
269- for sni := range sniMap {
270- newSnis = append (newSnis , sni )
271- }
272-
273- slices .Sort (newSnis )
274- // update existing ssl object
275- existing .Snis = newSnis
276- } else {
277- slices .Sort (ssl .Snis )
278- // if new ssl id, add to map
279- sslMap [ssl .ID ] = ssl
280- }
281- }
282-
283- mergedSSL := make ([]* adctypes.SSL , 0 , len (sslMap ))
284- for _ , ssl := range sslMap {
285- mergedSSL = append (mergedSSL , ssl )
286- }
287- return mergedSSL
288- }
0 commit comments