@@ -2,7 +2,10 @@ package webhookauthenticator
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
"io/ioutil"
8
11
"net"
@@ -28,6 +31,7 @@ import (
28
31
configinformers "github.com/openshift/client-go/config/informers/externalversions"
29
32
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
30
33
"github.com/openshift/library-go/pkg/controller/factory"
34
+ "github.com/openshift/library-go/pkg/operator/certrotation"
31
35
"github.com/openshift/library-go/pkg/operator/events"
32
36
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
33
37
"github.com/openshift/library-go/pkg/operator/status"
@@ -173,12 +177,29 @@ func (c *webhookAuthenticatorController) ensureKubeConfigSecret(ctx context.Cont
173
177
174
178
kubeconfigComplete := replacer .Replace (string (kubeconfigBytes ))
175
179
180
+ _ , err = tls .X509KeyPair (cert , key )
181
+ if err != nil {
182
+ return nil , fmt .Errorf ("private key doesn't match the certificate of authenticator secret" )
183
+ }
184
+ // extract not-before/not-after timestamps valid x509 certificate
185
+ var block * pem.Block
186
+ block , _ = pem .Decode (cert )
187
+ if block == nil || block .Type != "CERTIFICATE" || len (block .Headers ) != 0 {
188
+ return nil , fmt .Errorf ("invalid first block found in the certificate of authenticator secret" )
189
+ }
190
+ parsedCert , err := x509 .ParseCertificate (block .Bytes )
191
+ if err != nil {
192
+ return nil , fmt .Errorf ("failed to parse the certificate of authenticator secret" )
193
+ }
194
+
176
195
requiredSecret := & corev1.Secret {
177
196
ObjectMeta : metav1.ObjectMeta {
178
197
Name : "webhook-authentication-integrated-oauth" ,
179
198
Namespace : "openshift-config" ,
180
199
Annotations : map [string ]string {
181
- annotations .OpenShiftComponent : "apiserver-auth" ,
200
+ annotations .OpenShiftComponent : "apiserver-auth" ,
201
+ certrotation .CertificateNotBeforeAnnotation : parsedCert .NotBefore .Format (time .RFC3339 ),
202
+ certrotation .CertificateNotAfterAnnotation : parsedCert .NotAfter .Format (time .RFC3339 ),
182
203
},
183
204
},
184
205
Data : map [string ][]byte {
0 commit comments