@@ -2,7 +2,10 @@ package nodekubeconfigcontroller
2
2
3
3
import (
4
4
"context"
5
+ "crypto/tls"
6
+ "crypto/x509"
5
7
"encoding/base64"
8
+ "encoding/pem"
6
9
"fmt"
7
10
"strings"
8
11
"time"
@@ -14,6 +17,7 @@ import (
14
17
"github.com/openshift/cluster-kube-apiserver-operator/bindata"
15
18
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/operatorclient"
16
19
"github.com/openshift/library-go/pkg/controller/factory"
20
+ "github.com/openshift/library-go/pkg/operator/certrotation"
17
21
"github.com/openshift/library-go/pkg/operator/events"
18
22
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
19
23
"github.com/openshift/library-go/pkg/operator/resource/resourceread"
@@ -112,6 +116,22 @@ func ensureNodeKubeconfigs(ctx context.Context, client coreclientv1.CoreV1Interf
112
116
return fmt .Errorf ("system:admin client private key missing from secret %s/node-system-admin-client" , operatorclient .OperatorNamespace )
113
117
}
114
118
119
+ // Ensure secret key matches the certificate
120
+ _ , err = tls .X509KeyPair (systemAdminClientCert , systemAdminClientKey )
121
+ if err != nil {
122
+ return fmt .Errorf ("system:admin client private key doesn't match the certificate from secret %s/node-system-admin-client" , operatorclient .OperatorNamespace )
123
+ }
124
+ // extract not-before/not-after timestamps valid x509 certificate
125
+ var block * pem.Block
126
+ block , _ = pem .Decode (systemAdminClientCert )
127
+ if block == nil || block .Type != "CERTIFICATE" || len (block .Headers ) != 0 {
128
+ return fmt .Errorf ("invalid first block found for certificate from secret %s/node-system-admin-client" , operatorclient .OperatorNamespace )
129
+ }
130
+ parsedCert , err := x509 .ParseCertificate (block .Bytes )
131
+ if err != nil {
132
+ return fmt .Errorf ("failed to parse the certificate from secret %s/node-system-admin-client" , operatorclient .OperatorNamespace )
133
+ }
134
+
115
135
servingCABundleCM , err := configmapLister .ConfigMaps (operatorclient .TargetNamespace ).Get ("kube-apiserver-server-ca" )
116
136
if err != nil {
117
137
return err
@@ -152,6 +172,8 @@ func ensureNodeKubeconfigs(ctx context.Context, client coreclientv1.CoreV1Interf
152
172
requiredSecret .Annotations = map [string ]string {}
153
173
}
154
174
requiredSecret .Annotations [annotations .OpenShiftComponent ] = "kube-apiserver"
175
+ requiredSecret .Annotations [certrotation .CertificateNotBeforeAnnotation ] = parsedCert .NotBefore .Format (time .RFC3339 )
176
+ requiredSecret .Annotations [certrotation .CertificateNotAfterAnnotation ] = parsedCert .NotAfter .Format (time .RFC3339 )
155
177
156
178
_ , _ , err = resourceapply .ApplySecret (ctx , client , recorder , requiredSecret )
157
179
if err != nil {
0 commit comments