Skip to content

Commit e39730d

Browse files
Merge pull request #29629 from vrutkovs/short-cert-rotation-cert-duration
CNTRLPLANE-353: Add test which verifes that only short duration tests are present
2 parents 2836632 + 41aecca commit e39730d

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
@@ -784,6 +784,10 @@ spec:
784784
[LinuxOnly] [Feature:SELinux] [Serial] warning is not bumped on two Pods with
785785
the same context on RWO volume [FeatureGate:SELinuxMountReadWriteOncePod]
786786
[Beta] [Feature:SELinuxMountReadWriteOncePodOnly]'
787+
- featureGate: ShortCertRotation
788+
tests:
789+
- testName: '[sig-arch][Late][Jira:"kube-apiserver"] [OCPFeatureGate:ShortCertRotation]
790+
all certificates should expire in no more than 8 hours'
787791
- featureGate: SigstoreImageVerification
788792
tests:
789793
- testName: '[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][Serial]

0 commit comments

Comments
 (0)