@@ -101,6 +101,10 @@ func (i *TestInstaller) CheckInstalled(s install.Strategy) (bool, error) {
101
101
return true , nil
102
102
}
103
103
104
+ func (i * TestInstaller ) ShouldRotateCerts (s install.Strategy ) (bool , error ) {
105
+ return false , nil
106
+ }
107
+
104
108
func (i * TestInstaller ) CertsRotateAt () time.Time {
105
109
return time.Time {}
106
110
}
@@ -543,14 +547,15 @@ func roleBinding(name, namespace, roleName, serviceAccountName, serviceAccountNa
543
547
return roleBinding
544
548
}
545
549
546
- func tlsSecret (name , namespace string , certPEM , privPEM []byte ) * corev1.Secret {
550
+ func tlsSecret (name , namespace string , caPEM , certPEM , privPEM []byte ) * corev1.Secret {
547
551
secret := & corev1.Secret {
548
552
ObjectMeta : metav1.ObjectMeta {
549
553
Labels : map [string ]string {install .OLMManagedLabelKey : install .OLMManagedLabelValue },
550
554
},
551
555
Data : map [string ][]byte {
552
- "tls.crt" : certPEM ,
553
- "tls.key" : privPEM ,
556
+ install .OLMCAPEMKey : caPEM ,
557
+ "tls.crt" : certPEM ,
558
+ "tls.key" : privPEM ,
554
559
},
555
560
Type : corev1 .SecretTypeTLS ,
556
561
}
@@ -565,7 +570,7 @@ func withCA(secret *corev1.Secret, caPEM []byte) *corev1.Secret {
565
570
return secret
566
571
}
567
572
568
- func keyPairToTLSSecret (name , namespace string , kp * certs.KeyPair ) * corev1.Secret {
573
+ func keyPairToTLSSecret (name , namespace string , caPEM [] byte , kp * certs.KeyPair ) * corev1.Secret {
569
574
var privPEM []byte
570
575
var certPEM []byte
571
576
@@ -577,7 +582,7 @@ func keyPairToTLSSecret(name, namespace string, kp *certs.KeyPair) *corev1.Secre
577
582
}
578
583
}
579
584
580
- return tlsSecret (name , namespace , certPEM , privPEM )
585
+ return tlsSecret (name , namespace , caPEM , certPEM , privPEM )
581
586
}
582
587
583
588
func signedServingPair (notAfter time.Time , ca * certs.KeyPair , hosts []string ) * certs.KeyPair {
@@ -1322,7 +1327,7 @@ func TestTransitionCSV(t *testing.T) {
1322
1327
install .OLMCAHashAnnotationKey : validCAHash ,
1323
1328
}))),
1324
1329
),
1325
- withAnnotations (keyPairToTLSSecret ("a1-service-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), map [string ]string {
1330
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), map [string ]string {
1326
1331
install .OLMCAHashAnnotationKey : validCAHash ,
1327
1332
}),
1328
1333
service ("a1" , namespace , "a1" , 80 ),
@@ -1388,6 +1393,11 @@ func TestTransitionCSV(t *testing.T) {
1388
1393
crds : []runtime.Object {
1389
1394
crd ("c1" , "v1" , "g1" ),
1390
1395
},
1396
+ objs : []runtime.Object {
1397
+ withAnnotations (keyPairToTLSSecret (install .SecretName (install .ServiceName ("a1" )), namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ).Add (install .DefaultCertMinFresh ), validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), map [string ]string {
1398
+ install .OLMCAHashAnnotationKey : validCAHash ,
1399
+ }),
1400
+ },
1391
1401
},
1392
1402
expected : expected {
1393
1403
csvStates : map [string ]csvState {
@@ -1548,7 +1558,7 @@ func TestTransitionCSV(t *testing.T) {
1548
1558
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1549
1559
install .OLMCAHashAnnotationKey : validCAHash ,
1550
1560
})),
1551
- withLabels (withAnnotations (keyPairToTLSSecret ("a1-service-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), map [string ]string {
1561
+ withLabels (withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), map [string ]string {
1552
1562
install .OLMCAHashAnnotationKey : validCAHash ,
1553
1563
}), map [string ]string {install .OLMManagedLabelKey : install .OLMManagedLabelValue }),
1554
1564
service ("a1-service" , namespace , "a1" , 80 ),
@@ -1617,7 +1627,7 @@ func TestTransitionCSV(t *testing.T) {
1617
1627
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1618
1628
install .OLMCAHashAnnotationKey : "a-pretty-bad-hash" ,
1619
1629
})),
1620
- withAnnotations (keyPairToTLSSecret ("v1.a1-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1630
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1621
1631
install .OLMCAHashAnnotationKey : validCAHash ,
1622
1632
}),
1623
1633
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -1686,7 +1696,7 @@ func TestTransitionCSV(t *testing.T) {
1686
1696
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1687
1697
install .OLMCAHashAnnotationKey : validCAHash ,
1688
1698
})),
1689
- withAnnotations (keyPairToTLSSecret ("v1.a1-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1699
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1690
1700
install .OLMCAHashAnnotationKey : "also-a-pretty-bad-hash" ,
1691
1701
}),
1692
1702
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -1755,7 +1765,7 @@ func TestTransitionCSV(t *testing.T) {
1755
1765
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1756
1766
install .OLMCAHashAnnotationKey : "a-pretty-bad-hash" ,
1757
1767
})),
1758
- withAnnotations (keyPairToTLSSecret ("v1.a1-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1768
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1759
1769
install .OLMCAHashAnnotationKey : "also-a-pretty-bad-hash" ,
1760
1770
}),
1761
1771
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -1824,7 +1834,7 @@ func TestTransitionCSV(t *testing.T) {
1824
1834
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1825
1835
install .OLMCAHashAnnotationKey : validCAHash ,
1826
1836
})),
1827
- withAnnotations (keyPairToTLSSecret ("v1.a1-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1837
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1828
1838
install .OLMCAHashAnnotationKey : validCAHash ,
1829
1839
}),
1830
1840
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -1893,7 +1903,7 @@ func TestTransitionCSV(t *testing.T) {
1893
1903
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1894
1904
install .OLMCAHashAnnotationKey : validCAHash ,
1895
1905
})),
1896
- withAnnotations (tlsSecret ("v1.a1-cert" , namespace , []byte ("bad-cert" ), []byte ("bad-key" )), map [string ]string {
1906
+ withAnnotations (tlsSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , []byte ("bad-cert" ), []byte ("bad-key" )), map [string ]string {
1897
1907
install .OLMCAHashAnnotationKey : validCAHash ,
1898
1908
}),
1899
1909
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -1962,7 +1972,7 @@ func TestTransitionCSV(t *testing.T) {
1962
1972
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
1963
1973
install .OLMCAHashAnnotationKey : expiredCAHash ,
1964
1974
})),
1965
- withAnnotations (keyPairToTLSSecret ("v1.a1-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), expiredCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1975
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), expiredCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
1966
1976
install .OLMCAHashAnnotationKey : expiredCAHash ,
1967
1977
}),
1968
1978
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -2031,7 +2041,7 @@ func TestTransitionCSV(t *testing.T) {
2031
2041
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
2032
2042
install .OLMCAHashAnnotationKey : expiredCAHash ,
2033
2043
})),
2034
- withAnnotations (keyPairToTLSSecret ("v1.a1-cert" , namespace , signedServingPair (time .Now ().Add (24 * time .Hour ), expiredCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
2044
+ withAnnotations (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (time .Now ().Add (24 * time .Hour ). Add ( install . DefaultCertMinFresh ), expiredCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
2035
2045
install .OLMCAHashAnnotationKey : expiredCAHash ,
2036
2046
}),
2037
2047
service ("v1-a1" , namespace , "a1" , 80 ),
@@ -4448,6 +4458,15 @@ func TestSyncOperatorGroups(t *testing.T) {
4448
4458
}
4449
4459
roleBinding .Labels [install .OLMManagedLabelKey ] = install .OLMManagedLabelValue
4450
4460
4461
+ // Generate valid and expired CA fixtures
4462
+ validCA , err := generateCA (time .Now ().Add (10 * 365 * 24 * time .Hour ), install .Organization )
4463
+ require .NoError (t , err )
4464
+ validCAPEM , _ , err := validCA .ToPEM ()
4465
+ require .NoError (t , err )
4466
+ certSecret := withAnnotations (keyPairToTLSSecret (install .SecretName (install .ServiceName (deploymentName )), operatorNamespace , validCAPEM , signedServingPair (time .Now ().Add (48 * time .Hour ), validCA , []string {"v1-a1.ns" , "v1-a1.ns.svc" })), map [string ]string {
4467
+ install .OLMCAHashAnnotationKey : certs .PEMSHA256 (validCAPEM ),
4468
+ })
4469
+
4451
4470
type initial struct {
4452
4471
operatorGroup * operatorsv1.OperatorGroup
4453
4472
csvs []* v1alpha1.ClusterServiceVersion
@@ -5032,6 +5051,7 @@ func TestSyncOperatorGroups(t *testing.T) {
5032
5051
serviceAccount ,
5033
5052
role ,
5034
5053
roleBinding ,
5054
+ certSecret ,
5035
5055
},
5036
5056
crds : []* apiextensionsv1.CustomResourceDefinition {crd },
5037
5057
},
@@ -5137,6 +5157,7 @@ func TestSyncOperatorGroups(t *testing.T) {
5137
5157
serviceAccount ,
5138
5158
role ,
5139
5159
roleBinding ,
5160
+ certSecret ,
5140
5161
},
5141
5162
crds : []* apiextensionsv1.CustomResourceDefinition {crd },
5142
5163
},
@@ -5245,6 +5266,7 @@ func TestSyncOperatorGroups(t *testing.T) {
5245
5266
serviceAccount ,
5246
5267
role ,
5247
5268
roleBinding ,
5269
+ certSecret ,
5248
5270
},
5249
5271
crds : []* apiextensionsv1.CustomResourceDefinition {crd },
5250
5272
},
@@ -6029,7 +6051,7 @@ func TestCARotation(t *testing.T) {
6029
6051
deployment ("a1" , namespace , "sa" , addAnnotations (defaultTemplateAnnotations , map [string ]string {
6030
6052
install .OLMCAHashAnnotationKey : validCAHash ,
6031
6053
})),
6032
- withLabels (withAnnotations (withCA (keyPairToTLSSecret ("a1-service-cert" , namespace , signedServingPair (expiresAt .Time , validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), validCAPEM ), map [string ]string {
6054
+ withLabels (withAnnotations (withCA (keyPairToTLSSecret (install . SecretName ( install . ServiceName ( "a1" )) , namespace , validCAPEM , signedServingPair (expiresAt .Time , validCA , []string {"a1-service.ns" , "a1-service.ns.svc" })), validCAPEM ), map [string ]string {
6033
6055
install .OLMCAHashAnnotationKey : validCAHash ,
6034
6056
}), map [string ]string {install .OLMManagedLabelKey : install .OLMManagedLabelValue }),
6035
6057
service ("a1-service" , namespace , "a1" , 80 , ownerReference ),
0 commit comments