@@ -10,6 +10,8 @@ import (
1010 "strings"
1111 "time"
1212
13+ promtime "github.com/prometheus/common/model"
14+
1315 "github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatadefaults"
1416 "github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatainterfaces"
1517 "github.com/openshift/origin/pkg/monitortests/network/disruptionpodnetwork"
@@ -283,6 +285,40 @@ var _ = g.Describe(fmt.Sprintf("[sig-arch][Late][Jira:%q]", "kube-apiserver"), g
283285 }
284286 })
285287
288+ g .It ("[OCPFeatureGate:ShortCertRotation] all certificates should expire in no more than 8 hours" , func () {
289+ var errs []error
290+ // Skip router certificates (both certificate and signer)
291+ // These are not being rotated automatically
292+ // OLM: bug https://issues.redhat.com/browse/CNTRLPLANE-379
293+ shortCertRotationIgnoredNamespaces := []string {"openshift-operator-lifecycle-manager" , "openshift-ingress-operator" }
294+
295+ for _ , certKeyPair := range actualPKIContent .CertKeyPairs .Items {
296+ if certKeyPair .Spec .CertMetadata .ValidityDuration == "" {
297+ // Skip certificates with no duration set (proxy ca, key without certificate etc.)
298+ continue
299+ }
300+ if certKeyPair .Spec .CertMetadata .ValidityDuration == "10y" {
301+ // Skip "forever" certificates
302+ continue
303+ }
304+ if isCertKeyPairFromIgnoredNamespace (certKeyPair , shortCertRotationIgnoredNamespaces ) {
305+ continue
306+ }
307+ // Use ParseDuration from prometheus as it can handle days/month/years durations
308+ duration , err := promtime .ParseDuration (certKeyPair .Spec .CertMetadata .ValidityDuration )
309+ if err != nil {
310+ errs = append (errs , fmt .Errorf ("failed to parse validity duration for certificate %q: %v" , certKeyPair .Name , err ))
311+ continue
312+ }
313+ if time .Duration (duration ) > time .Hour * 8 {
314+ errs = append (errs , fmt .Errorf ("certificate %q expires too soon: expected duration to be up to 8h, but was %s" , certKeyPair .Name , duration ))
315+ }
316+ }
317+ if len (errs ) > 0 {
318+ testresult .Flakef ("Errors found: %s" , utilerrors .NewAggregate (errs ).Error ())
319+ }
320+ })
321+
286322})
287323
288324func fetchOnDiskCertificates (ctx context.Context , kubeClient kubernetes.Interface , podRESTConfig * rest.Config , nodeList []* corev1.Node , testPullSpec string ) (* certgraphapi.PKIList , error ) {
@@ -428,3 +464,14 @@ func fetchNodePKIList(_ context.Context, kubeClient kubernetes.Interface, podRES
428464
429465 return pkiList , nil
430466}
467+
468+ func isCertKeyPairFromIgnoredNamespace (cert certgraphapi.CertKeyPair , ignoredNamespaces []string ) bool {
469+ for _ , location := range cert .Spec .SecretLocations {
470+ for _ , namespace := range ignoredNamespaces {
471+ if location .Namespace == namespace {
472+ return true
473+ }
474+ }
475+ }
476+ return false
477+ }
0 commit comments