Skip to content

Commit 41aecca

Browse files
author
Vadim Rutkovsky
committed
Add test which verifes that only short duration tests are present
This test would run only when ShortCertRotation is enabled
1 parent 5b6e4cc commit 41aecca

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

test/extended/operators/certs.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

288324
func 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+
}

test/extended/util/annotate/generated/zz_generated.annotations.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zz_generated.manifests/test-reporting.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ spec:
775775
[LinuxOnly] [Feature:SELinux] [Serial] warning is not bumped on two Pods with
776776
the same context on RWO volume [FeatureGate:SELinuxMountReadWriteOncePod]
777777
[Beta] [Feature:SELinuxMountReadWriteOncePodOnly]'
778+
- featureGate: ShortCertRotation
779+
tests:
780+
- testName: '[sig-arch][Late][Jira:"kube-apiserver"] [OCPFeatureGate:ShortCertRotation]
781+
all certificates should expire in no more than 8 hours'
778782
- featureGate: SigstoreImageVerification
779783
tests:
780784
- testName: '[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][Serial]

0 commit comments

Comments
 (0)