@@ -218,16 +218,28 @@ func Unmarshal(ctx context.Context, in map[string][]byte) (*Config, error) {
218218 if err != nil {
219219 return nil , fmt .Errorf ("decrypting existing private key: %w" , err )
220220 }
221- // If there's legacy rootCA entry, check it first.
221+ // Make sure to dedupe along the way just to make sure we do not have
222+ // duplicate entries.
223+ uniqueFulcioCerts := map [string ][]byte {}
224+
225+ // If there's legacy rootCA entry, check it first. This will get converted
226+ // to fulcio-0 when marshaling, but we just want to make sure it's there
227+ // when we're converting from ConfigMap based configuration into secret
228+ // based one.
222229 if legacyRoot , ok := in [LegacyRootCAKey ]; ok && len (legacyRoot ) > 0 {
223- ret . FulcioCerts = append ( ret . FulcioCerts , legacyRoot )
230+ uniqueFulcioCerts [ string ( legacyRoot )] = legacyRoot
224231 }
225- // Then loop through Fulcio roots
232+
226233 for k , v := range in {
227234 if strings .HasPrefix (k , "fulcio-" ) {
228- ret . FulcioCerts = append ( ret . FulcioCerts , v )
235+ uniqueFulcioCerts [ string ( v )] = v
229236 }
230237 }
238+
239+ // Then loop through Fulcio roots that have been deduped above
240+ for _ , v := range uniqueFulcioCerts {
241+ ret .FulcioCerts = append (ret .FulcioCerts , v )
242+ }
231243 return & ret , nil
232244}
233245
@@ -244,7 +256,7 @@ func (c *Config) MarshalConfig(ctx context.Context) (map[string][]byte, error) {
244256 // of files containing them for the RootsPemFile. Names don't matter
245257 // so we just call them fulcio-%
246258 // What matters however is to ensure that the filenames match the keys
247- // in the configmap / secret that we construc so they get properly mounted.
259+ // in the configmap / secret that we construct so they get properly mounted.
248260 rootPems := make ([]string , 0 , len (c .FulcioCerts ))
249261 for i := range c .FulcioCerts {
250262 rootPems = append (rootPems , fmt .Sprintf ("%sfulcio-%d" , rootsPemFileDir , i ))
0 commit comments