Skip to content

Commit 7887213

Browse files
matzewmarkusthoemmesStavros Kontopoulos
authored
Adding back vendor patches (#5)
* Rollback certificate algorithm changes (knative#1281) (knative#1283) Co-authored-by: Markus Thömmes <markusthoemmes@me.com> * mute noisy metrics * [SRVKS-790] Patch subresource to unblock webhooks on 4.9 (knative#1361) Co-authored-by: Markus Thömmes <markusthoemmes@me.com> Co-authored-by: Stavros Kontopoulos <skontopo@redhat.com>
1 parent 7cbbff8 commit 7887213

6 files changed

Lines changed: 25 additions & 24 deletions

File tree

vendor/k8s.io/apimachinery/pkg/apis/meta/v1/types.go

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

vendor/knative.dev/pkg/controller/stats_reporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (r *reporter) ReportReconcile(duration time.Duration, success string, key t
197197
return err
198198
}
199199

200-
metrics.RecordBatch(ctx, reconcileCountStat.M(1),
201-
reconcileLatencyStat.M(duration.Milliseconds()))
200+
// TODO skonto: fix latency histogram
201+
metrics.RecordBatch(ctx, reconcileCountStat.M(1))
202202
return nil
203203
}

vendor/knative.dev/pkg/webhook/certificates/certificates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
const (
3838
// Time used for updating a certificate before it expires.
39-
oneDay = 24 * time.Hour
39+
oneWeek = 7 * 24 * time.Hour
4040
)
4141

4242
type reconciler struct {
@@ -89,7 +89,7 @@ func (r *reconciler) reconcileCertificate(ctx context.Context) error {
8989
certData, err := x509.ParseCertificate(cert.Certificate[0])
9090
if err != nil {
9191
logger.Errorw("Error parsing certificate", zap.Error(err))
92-
} else if time.Now().Add(oneDay).Before(certData.NotAfter) {
92+
} else if time.Now().Add(oneWeek).Before(certData.NotAfter) {
9393
return nil
9494
}
9595
}

vendor/knative.dev/pkg/webhook/certificates/resources/certs.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package resources
1818

1919
import (
2020
"context"
21-
"crypto/ed25519"
2221
"crypto/rand"
22+
"crypto/rsa"
2323
"crypto/x509"
2424
"crypto/x509/pkix"
2525
"encoding/pem"
@@ -62,7 +62,7 @@ func createCertTemplate(name, namespace string, notAfter time.Time) (*x509.Certi
6262
Organization: []string{organization},
6363
CommonName: commonName,
6464
},
65-
SignatureAlgorithm: x509.PureEd25519,
65+
SignatureAlgorithm: x509.SHA256WithRSA,
6666
NotBefore: time.Now(),
6767
NotAfter: notAfter,
6868
BasicConstraintsValid: true,
@@ -112,9 +112,9 @@ func createCert(template, parent *x509.Certificate, pub, parentPriv interface{})
112112
return
113113
}
114114

115-
func createCA(ctx context.Context, name, namespace string, notAfter time.Time) (ed25519.PrivateKey, *x509.Certificate, []byte, error) {
115+
func createCA(ctx context.Context, name, namespace string, notAfter time.Time) (*rsa.PrivateKey, *x509.Certificate, []byte, error) {
116116
logger := logging.FromContext(ctx)
117-
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
117+
rootKey, err := rsa.GenerateKey(rand.Reader, 2048)
118118
if err != nil {
119119
logger.Errorw("error generating random key", zap.Error(err))
120120
return nil, nil, nil, err
@@ -126,12 +126,12 @@ func createCA(ctx context.Context, name, namespace string, notAfter time.Time) (
126126
return nil, nil, nil, err
127127
}
128128

129-
rootCert, rootCertPEM, err := createCert(rootCertTmpl, rootCertTmpl, publicKey, privateKey)
129+
rootCert, rootCertPEM, err := createCert(rootCertTmpl, rootCertTmpl, &rootKey.PublicKey, rootKey)
130130
if err != nil {
131131
logger.Errorw("error signing the CA cert", zap.Error(err))
132132
return nil, nil, nil, err
133133
}
134-
return privateKey, rootCert, rootCertPEM, nil
134+
return rootKey, rootCert, rootCertPEM, nil
135135
}
136136

137137
// CreateCerts creates and returns a CA certificate and certificate and
@@ -148,7 +148,7 @@ func CreateCerts(ctx context.Context, name, namespace string, notAfter time.Time
148148
}
149149

150150
// Then create the private key for the serving cert
151-
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
151+
servKey, err := rsa.GenerateKey(rand.Reader, 2048)
152152
if err != nil {
153153
logger.Errorw("error generating random key", zap.Error(err))
154154
return nil, nil, nil, err
@@ -160,18 +160,13 @@ func CreateCerts(ctx context.Context, name, namespace string, notAfter time.Time
160160
}
161161

162162
// create a certificate which wraps the server's public key, sign it with the CA private key
163-
_, servCertPEM, err := createCert(servCertTemplate, caCertificate, publicKey, caKey)
163+
_, servCertPEM, err := createCert(servCertTemplate, caCertificate, &servKey.PublicKey, caKey)
164164
if err != nil {
165165
logger.Errorw("error signing server certificate template", zap.Error(err))
166166
return nil, nil, nil, err
167167
}
168-
privKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
169-
if err != nil {
170-
logger.Errorw("error marshaling private key", zap.Error(err))
171-
return nil, nil, nil, err
172-
}
173168
servKeyPEM := pem.EncodeToMemory(&pem.Block{
174-
Type: "PRIVATE KEY", Bytes: privKeyBytes,
169+
Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(servKey),
175170
})
176171
return servKeyPEM, servCertPEM, caCertificatePEM, nil
177172
}

vendor/knative.dev/pkg/webhook/certificates/resources/secret.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const (
3232
// CACert is the name of the key associated with the certificate of the CA for
3333
// the keypair.
3434
CACert = "ca-cert.pem"
35-
36-
oneWeek = 7 * 24 * time.Hour
3735
)
3836

3937
// MakeSecret synthesizes a Kubernetes Secret object with the keys specified by
@@ -43,7 +41,7 @@ var MakeSecret = MakeSecretInternal
4341

4442
// MakeSecretInternal is only public so MakeSecret can be restored in testing. Use MakeSecret.
4543
func MakeSecretInternal(ctx context.Context, name, namespace, serviceName string) (*corev1.Secret, error) {
46-
serverKey, serverCert, caCert, err := CreateCerts(ctx, serviceName, namespace, time.Now().Add(oneWeek))
44+
serverKey, serverCert, caCert, err := CreateCerts(ctx, serviceName, namespace, time.Now().AddDate(1, 0, 0))
4745
if err != nil {
4846
return nil, err
4947
}

vendor/knative.dev/pkg/webhook/stats_reporter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ func (r *reporter) ReportRequest(req *admissionv1.AdmissionRequest, resp *admiss
9999
return err
100100
}
101101

102-
metrics.RecordBatch(ctx, requestCountM.M(1),
103-
// Convert time.Duration in nanoseconds to milliseconds
104-
responseTimeInMsecM.M(float64(d.Milliseconds())))
102+
// TODO skonto: fix latency histogram
103+
metrics.Record(ctx, requestCountM.M(1))
105104
return nil
106105
}
107106

0 commit comments

Comments
 (0)