Skip to content

Commit d2ddcae

Browse files
committed
webhook-authenticator: set not-before/not-after annotations for
webhook-authentication-integrated-oauth secret
1 parent b0bfaf3 commit d2ddcae

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/controllers/webhookauthenticator/webhookauthenticator_controller.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package webhookauthenticator
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"crypto/x509"
57
"encoding/base64"
68
"fmt"
79
"net"
@@ -28,6 +30,7 @@ import (
2830
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
2931
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
3032
"github.com/openshift/library-go/pkg/controller/factory"
33+
"github.com/openshift/library-go/pkg/operator/certrotation"
3134
"github.com/openshift/library-go/pkg/operator/events"
3235
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
3336
"github.com/openshift/library-go/pkg/operator/status"
@@ -196,12 +199,26 @@ func (c *webhookAuthenticatorController) ensureKubeConfigSecret(ctx context.Cont
196199

197200
kubeconfigComplete := replacer.Replace(string(kubeconfigBytes))
198201

202+
pair, err := tls.X509KeyPair(cert, key)
203+
if err != nil {
204+
return nil, fmt.Errorf("invalid TLS keypair in authenticator secret: %w", err)
205+
}
206+
if len(pair.Certificate) == 0 {
207+
return nil, fmt.Errorf("no certificate data found in authenticator secret")
208+
}
209+
parsedCert, err := x509.ParseCertificate(pair.Certificate[0])
210+
if err != nil {
211+
return nil, fmt.Errorf("failed to parse leaf certificate from authenticator secret: %w", err)
212+
}
213+
199214
requiredSecret := &corev1.Secret{
200215
ObjectMeta: metav1.ObjectMeta{
201216
Name: webhookSecretName,
202217
Namespace: configNamespace,
203218
Annotations: map[string]string{
204-
annotations.OpenShiftComponent: "apiserver-auth",
219+
annotations.OpenShiftComponent: "apiserver-auth",
220+
certrotation.CertificateNotBeforeAnnotation: parsedCert.NotBefore.Format(time.RFC3339),
221+
certrotation.CertificateNotAfterAnnotation: parsedCert.NotAfter.Format(time.RFC3339),
205222
},
206223
},
207224
Data: map[string][]byte{

0 commit comments

Comments
 (0)