mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
refactor tls init for reuse
This commit is contained in:
parent
7309e1f707
commit
b3c8f71aca
@ -284,23 +284,9 @@ func (s *KubeletServer) Run(_ []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.TLSCertFile == "" && s.TLSPrivateKeyFile == "" {
|
||||
s.TLSCertFile = path.Join(s.CertDirectory, "kubelet.crt")
|
||||
s.TLSPrivateKeyFile = path.Join(s.CertDirectory, "kubelet.key")
|
||||
if err := util.GenerateSelfSignedCert(util.GetHostname(s.HostnameOverride), s.TLSCertFile, s.TLSPrivateKeyFile); err != nil {
|
||||
return fmt.Errorf("unable to generate self signed cert: %v", err)
|
||||
}
|
||||
glog.V(4).Infof("Using self-signed cert (%s, %s)", s.TLSCertFile, s.TLSPrivateKeyFile)
|
||||
}
|
||||
tlsOptions := &kubelet.TLSOptions{
|
||||
Config: &tls.Config{
|
||||
// Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability).
|
||||
MinVersion: tls.VersionTLS10,
|
||||
// Populate PeerCertificates in requests, but don't yet reject connections without certificates.
|
||||
ClientAuth: tls.RequestClientCert,
|
||||
},
|
||||
CertFile: s.TLSCertFile,
|
||||
KeyFile: s.TLSPrivateKeyFile,
|
||||
tlsOptions, err := s.InitializeTLS()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mounter := mount.New()
|
||||
@ -391,6 +377,30 @@ func (s *KubeletServer) Run(_ []string) error {
|
||||
select {}
|
||||
}
|
||||
|
||||
// InitializeTLS checks for a configured TLSCertFile and TLSPrivateKeyFile: if unspecified a new self-signed
|
||||
// certificate and key file are generated. Returns a configured kubelet.TLSOptions object.
|
||||
func (s *KubeletServer) InitializeTLS() (*kubelet.TLSOptions, error) {
|
||||
if s.TLSCertFile == "" && s.TLSPrivateKeyFile == "" {
|
||||
s.TLSCertFile = path.Join(s.CertDirectory, "kubelet.crt")
|
||||
s.TLSPrivateKeyFile = path.Join(s.CertDirectory, "kubelet.key")
|
||||
if err := util.GenerateSelfSignedCert(util.GetHostname(s.HostnameOverride), s.TLSCertFile, s.TLSPrivateKeyFile); err != nil {
|
||||
return nil, fmt.Errorf("unable to generate self signed cert: %v", err)
|
||||
}
|
||||
glog.V(4).Infof("Using self-signed cert (%s, %s)", s.TLSCertFile, s.TLSPrivateKeyFile)
|
||||
}
|
||||
tlsOptions := &kubelet.TLSOptions{
|
||||
Config: &tls.Config{
|
||||
// Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability).
|
||||
MinVersion: tls.VersionTLS10,
|
||||
// Populate PeerCertificates in requests, but don't yet reject connections without certificates.
|
||||
ClientAuth: tls.RequestClientCert,
|
||||
},
|
||||
CertFile: s.TLSCertFile,
|
||||
KeyFile: s.TLSPrivateKeyFile,
|
||||
}
|
||||
return tlsOptions, nil
|
||||
}
|
||||
|
||||
func (s *KubeletServer) authPathClientConfig(useDefaults bool) (*client.Config, error) {
|
||||
authInfo, err := clientauth.LoadFromFile(s.AuthPath.Value())
|
||||
if err != nil && !useDefaults {
|
||||
|
Loading…
Reference in New Issue
Block a user