@@ -17,6 +17,7 @@ limitations under the License.
1717package genericapiserver
1818
1919import (
20+ "crypto/x509"
2021 "fmt"
2122 "io"
2223 "net"
@@ -165,7 +166,7 @@ type SecureServingInfo struct {
165166 // SNICerts are named CertKeys for serving secure traffic with SNI support.
166167 SNICerts []NamedCertKey
167168 // ClientCA is the certificate bundle for all the signers that you'll recognize for incoming client certificates
168- ClientCA string
169+ ClientCA * x509. CertPool
169170}
170171
171172type CertKey struct {
@@ -254,14 +255,42 @@ func (c *Config) ApplyOptions(options *options.ServerRunOptions) *Config {
254255 },
255256 },
256257 SNICerts : []NamedCertKey {},
257- ClientCA : options .ClientCAFile ,
258258 }
259259 if options .TLSCertFile == "" && options .TLSPrivateKeyFile == "" {
260260 secureServingInfo .ServerCert .Generate = true
261261 secureServingInfo .ServerCert .CertFile = path .Join (options .CertDirectory , "apiserver.crt" )
262262 secureServingInfo .ServerCert .KeyFile = path .Join (options .CertDirectory , "apiserver.key" )
263263 }
264264
265+ if len (options .ClientCAFile ) > 0 {
266+ clientCAs , err := certutil .CertsFromFile (options .ClientCAFile )
267+ if err != nil {
268+ // normally this would be no-no, but its the minimal change to backport to 1.5 and
269+ // every caller is going to do this.
270+ panic (fmt .Errorf ("unable to load client CA file: %v" , err ))
271+ }
272+ if secureServingInfo .ClientCA == nil {
273+ secureServingInfo .ClientCA = x509 .NewCertPool ()
274+ }
275+ for _ , cert := range clientCAs {
276+ secureServingInfo .ClientCA .AddCert (cert )
277+ }
278+ }
279+ if len (options .RequestHeaderClientCAFile ) > 0 {
280+ clientCAs , err := certutil .CertsFromFile (options .RequestHeaderClientCAFile )
281+ if err != nil {
282+ // normally this would be no-no, but its the minimal change to backport to 1.5 and
283+ // every caller is going to do this.
284+ panic (fmt .Errorf ("unable to load requestheader client CA file: %v" , err ))
285+ }
286+ if secureServingInfo .ClientCA == nil {
287+ secureServingInfo .ClientCA = x509 .NewCertPool ()
288+ }
289+ for _ , cert := range clientCAs {
290+ secureServingInfo .ClientCA .AddCert (cert )
291+ }
292+ }
293+
265294 secureServingInfo .SNICerts = nil
266295 for _ , nkc := range options .SNICertKeys {
267296 secureServingInfo .SNICerts = append (secureServingInfo .SNICerts , NamedCertKey {
0 commit comments