Skip to content

Commit f703423

Browse files
Merge pull request #164 from marun/4.2-reload-serving-cert
[release-4.2] Bug 1809258: Reload serving certs
2 parents 2eb032f + f2f4093 commit f703423

33 files changed

+4457
-2
lines changed

Gopkg.lock

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

dynamiccertificates/cert_key.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package dynamiccertificates
18+
19+
import (
20+
"bytes"
21+
)
22+
23+
// CertKeyContentProvider provides a certificate and matching private key
24+
type CertKeyContentProvider interface {
25+
// Name is just an identifier
26+
Name() string
27+
// CurrentCertKeyContent provides cert and key byte content
28+
CurrentCertKeyContent() ([]byte, []byte)
29+
}
30+
31+
// SNICertKeyContentProvider provides a certificate and matching private key as well as optional explicit names
32+
type SNICertKeyContentProvider interface {
33+
CertKeyContentProvider
34+
// SNINames provides names used for SNI. May return nil.
35+
SNINames() []string
36+
}
37+
38+
// certKeyContent holds the content for the cert and key
39+
type certKeyContent struct {
40+
cert []byte
41+
key []byte
42+
}
43+
44+
func (c *certKeyContent) Equal(rhs *certKeyContent) bool {
45+
if c == nil || rhs == nil {
46+
return c == rhs
47+
}
48+
49+
return bytes.Equal(c.key, rhs.key) && bytes.Equal(c.cert, rhs.cert)
50+
}
51+
52+
// sniCertKeyContent holds the content for the cert and key as well as any explicit names
53+
type sniCertKeyContent struct {
54+
certKeyContent
55+
sniNames []string
56+
}
57+
58+
func (c *sniCertKeyContent) Equal(rhs *sniCertKeyContent) bool {
59+
if c == nil || rhs == nil {
60+
return c == rhs
61+
}
62+
63+
if len(c.sniNames) != len(rhs.sniNames) {
64+
return false
65+
}
66+
67+
for i := range c.sniNames {
68+
if c.sniNames[i] != rhs.sniNames[i] {
69+
return false
70+
}
71+
}
72+
73+
return c.certKeyContent.Equal(&rhs.certKeyContent)
74+
}

dynamiccertificates/client_ca.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package dynamiccertificates
18+
19+
import (
20+
"bytes"
21+
"crypto/x509"
22+
)
23+
24+
// CAContentProvider provides ca bundle byte content
25+
type CAContentProvider interface {
26+
// Name is just an identifier
27+
Name() string
28+
// CurrentCABundleContent provides ca bundle byte content. Errors can be contained to the controllers initializing
29+
// the value. By the time you get here, you should always be returning a value that won't fail.
30+
CurrentCABundleContent() []byte
31+
// VerifyOptions provides VerifyOptions for authenticators
32+
VerifyOptions() (x509.VerifyOptions, bool)
33+
}
34+
35+
// dynamicCertificateContent holds the content that overrides the baseTLSConfig
36+
type dynamicCertificateContent struct {
37+
// clientCA holds the content for the clientCA bundle
38+
clientCA caBundleContent
39+
servingCert certKeyContent
40+
sniCerts []sniCertKeyContent
41+
}
42+
43+
// caBundleContent holds the content for the clientCA bundle. Wrapping the bytes makes the Equals work nicely with the
44+
// method receiver.
45+
type caBundleContent struct {
46+
caBundle []byte
47+
}
48+
49+
func (c *dynamicCertificateContent) Equal(rhs *dynamicCertificateContent) bool {
50+
if c == nil || rhs == nil {
51+
return c == rhs
52+
}
53+
54+
if !c.clientCA.Equal(&rhs.clientCA) {
55+
return false
56+
}
57+
58+
if !c.servingCert.Equal(&rhs.servingCert) {
59+
return false
60+
}
61+
62+
if len(c.sniCerts) != len(rhs.sniCerts) {
63+
return false
64+
}
65+
66+
for i := range c.sniCerts {
67+
if !c.sniCerts[i].Equal(&rhs.sniCerts[i]) {
68+
return false
69+
}
70+
}
71+
72+
return true
73+
}
74+
75+
func (c *caBundleContent) Equal(rhs *caBundleContent) bool {
76+
if c == nil || rhs == nil {
77+
return c == rhs
78+
}
79+
80+
return bytes.Equal(c.caBundle, rhs.caBundle)
81+
}

dynamiccertificates/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package dynamiccertificates
2+
3+
// This package contains the forked contents of
4+
// k8s.io/apiserver/pkg/server/dynamiccertificates from kube 1.17. The scope
5+
// of the fork was considerably less than the changes that would have been
6+
// required to bump the release-4.3 branch of oauth-proxy to 1.17.

0 commit comments

Comments
 (0)