Merge pull request #120417 from neolit123/1.29-v1beta4-ecdsa
kubeadm: add v1beta4.ClusterConfiguration.EncryptionAlgorithm
This commit is contained in:
		@@ -91,6 +91,7 @@ func fuzzClusterConfiguration(obj *kubeadm.ClusterConfiguration, c fuzz.Continue
 | 
				
			|||||||
	obj.APIServer.ExtraEnvs = []kubeadm.EnvVar{}
 | 
						obj.APIServer.ExtraEnvs = []kubeadm.EnvVar{}
 | 
				
			||||||
	obj.Scheduler.ExtraEnvs = []kubeadm.EnvVar{}
 | 
						obj.Scheduler.ExtraEnvs = []kubeadm.EnvVar{}
 | 
				
			||||||
	obj.Etcd.Local.ExtraEnvs = []kubeadm.EnvVar{}
 | 
						obj.Etcd.Local.ExtraEnvs = []kubeadm.EnvVar{}
 | 
				
			||||||
 | 
						obj.EncryptionAlgorithm = kubeadm.EncryptionAlgorithmRSA
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func fuzzDNS(obj *kubeadm.DNS, c fuzz.Continue) {
 | 
					func fuzzDNS(obj *kubeadm.DNS, c fuzz.Continue) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,8 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package kubeadm
 | 
					package kubeadm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"crypto/x509"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime/schema"
 | 
						"k8s.io/apimachinery/pkg/runtime/schema"
 | 
				
			||||||
@@ -141,6 +139,10 @@ type ClusterConfiguration struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// The cluster name
 | 
						// The cluster name
 | 
				
			||||||
	ClusterName string
 | 
						ClusterName string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// EncryptionAlgorithm holds the type of asymmetric encryption algorithm used for keys and certificates.
 | 
				
			||||||
 | 
						// Can be "RSA" (default algorithm, key size is 2048) or "ECDSA" (uses the P-256 eliptic curve).
 | 
				
			||||||
 | 
						EncryptionAlgorithm EncryptionAlgorithmType
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ControlPlaneComponent holds settings common to control plane component of the cluster
 | 
					// ControlPlaneComponent holds settings common to control plane component of the cluster
 | 
				
			||||||
@@ -403,13 +405,18 @@ func (cfg *ClusterConfiguration) GetControlPlaneImageRepository() string {
 | 
				
			|||||||
	return cfg.ImageRepository
 | 
						return cfg.ImageRepository
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PublicKeyAlgorithm returns the type of encryption keys used in the cluster.
 | 
					// EncryptionAlgorithmType returns the type of encryption keys used in the cluster.
 | 
				
			||||||
func (cfg *ClusterConfiguration) PublicKeyAlgorithm() x509.PublicKeyAlgorithm {
 | 
					func (cfg *ClusterConfiguration) EncryptionAlgorithmType() EncryptionAlgorithmType {
 | 
				
			||||||
	if features.Enabled(cfg.FeatureGates, features.PublicKeysECDSA) {
 | 
						// If the feature gate is set to true, or false respect it.
 | 
				
			||||||
		return x509.ECDSA
 | 
						// If the feature gate is not set, use the EncryptionAlgorithm field (v1beta4).
 | 
				
			||||||
 | 
						// TODO: remove this function when the feature gate is removed.
 | 
				
			||||||
 | 
						if enabled, ok := cfg.FeatureGates[features.PublicKeysECDSA]; ok {
 | 
				
			||||||
 | 
							if enabled {
 | 
				
			||||||
 | 
								return EncryptionAlgorithmECDSA
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							return EncryptionAlgorithmRSA
 | 
				
			||||||
	return x509.RSA
 | 
						}
 | 
				
			||||||
 | 
						return cfg.EncryptionAlgorithm
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HostPathMount contains elements describing volumes that are mounted from the
 | 
					// HostPathMount contains elements describing volumes that are mounted from the
 | 
				
			||||||
@@ -518,3 +525,13 @@ type Arg struct {
 | 
				
			|||||||
type EnvVar struct {
 | 
					type EnvVar struct {
 | 
				
			||||||
	v1.EnvVar
 | 
						v1.EnvVar
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// EncryptionAlgorithmType can define an asymmetric encryption algorithm type.
 | 
				
			||||||
 | 
					type EncryptionAlgorithmType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// EncryptionAlgorithmECDSA defines the ECDSA encryption algorithm type.
 | 
				
			||||||
 | 
						EncryptionAlgorithmECDSA EncryptionAlgorithmType = "ECDSA"
 | 
				
			||||||
 | 
						// EncryptionAlgorithmRSA defines the RSA encryption algorithm type.
 | 
				
			||||||
 | 
						EncryptionAlgorithmRSA EncryptionAlgorithmType = "RSA"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,9 +38,26 @@ func Convert_v1beta3_InitConfiguration_To_kubeadm_InitConfiguration(in *InitConf
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(&ClusterConfiguration{}, &out.ClusterConfiguration, s)
 | 
						err = Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(&ClusterConfiguration{}, &out.ClusterConfiguration, s)
 | 
				
			||||||
 | 
						// Required to pass fuzzer tests. This ClusterConfiguration is empty and is never defaulted.
 | 
				
			||||||
 | 
						// If we call Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration() it will receive
 | 
				
			||||||
 | 
						// a default value, thus here we need to reset it back to "".
 | 
				
			||||||
 | 
						out.EncryptionAlgorithm = ""
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Convert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration is required due to missing EncryptionAlgorithm in v1beta3.
 | 
				
			||||||
 | 
					func Convert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in *kubeadm.ClusterConfiguration, out *ClusterConfiguration, s conversion.Scope) error {
 | 
				
			||||||
 | 
						return autoConvert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in, out, s)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration is required due to missing EncryptionAlgorithm in v1beta3.
 | 
				
			||||||
 | 
					func Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in *ClusterConfiguration, out *kubeadm.ClusterConfiguration, s conversion.Scope) error {
 | 
				
			||||||
 | 
						// Required to pass validation and fuzzer tests. The field is missing in v1beta3, thus we have to
 | 
				
			||||||
 | 
						// default it to a sane (default) value in the internal type.
 | 
				
			||||||
 | 
						out.EncryptionAlgorithm = kubeadm.EncryptionAlgorithmRSA
 | 
				
			||||||
 | 
						return autoConvert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in, out, s)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Convert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent is required due to the missing ControlPlaneComponent.ExtraEnvs in v1beta3.
 | 
					// Convert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent is required due to the missing ControlPlaneComponent.ExtraEnvs in v1beta3.
 | 
				
			||||||
func Convert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent(in *ControlPlaneComponent, out *kubeadm.ControlPlaneComponent, s conversion.Scope) error {
 | 
					func Convert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent(in *ControlPlaneComponent, out *kubeadm.ControlPlaneComponent, s conversion.Scope) error {
 | 
				
			||||||
	out.ExtraEnvs = []kubeadm.EnvVar{}
 | 
						out.ExtraEnvs = []kubeadm.EnvVar{}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,16 +69,6 @@ func RegisterConversions(s *runtime.Scheme) error {
 | 
				
			|||||||
	}); err != nil {
 | 
						}); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := s.AddGeneratedConversionFunc((*ClusterConfiguration)(nil), (*kubeadm.ClusterConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
					 | 
				
			||||||
		return Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(a.(*ClusterConfiguration), b.(*kubeadm.ClusterConfiguration), scope)
 | 
					 | 
				
			||||||
	}); err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := s.AddGeneratedConversionFunc((*kubeadm.ClusterConfiguration)(nil), (*ClusterConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
					 | 
				
			||||||
		return Convert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(a.(*kubeadm.ClusterConfiguration), b.(*ClusterConfiguration), scope)
 | 
					 | 
				
			||||||
	}); err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := s.AddGeneratedConversionFunc((*DNS)(nil), (*kubeadm.DNS)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
						if err := s.AddGeneratedConversionFunc((*DNS)(nil), (*kubeadm.DNS)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
				
			||||||
		return Convert_v1beta3_DNS_To_kubeadm_DNS(a.(*DNS), b.(*kubeadm.DNS), scope)
 | 
							return Convert_v1beta3_DNS_To_kubeadm_DNS(a.(*DNS), b.(*kubeadm.DNS), scope)
 | 
				
			||||||
	}); err != nil {
 | 
						}); err != nil {
 | 
				
			||||||
@@ -184,6 +174,11 @@ func RegisterConversions(s *runtime.Scheme) error {
 | 
				
			|||||||
	}); err != nil {
 | 
						}); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if err := s.AddConversionFunc((*kubeadm.ClusterConfiguration)(nil), (*ClusterConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
				
			||||||
 | 
							return Convert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(a.(*kubeadm.ClusterConfiguration), b.(*ClusterConfiguration), scope)
 | 
				
			||||||
 | 
						}); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := s.AddConversionFunc((*kubeadm.ControlPlaneComponent)(nil), (*ControlPlaneComponent)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
						if err := s.AddConversionFunc((*kubeadm.ControlPlaneComponent)(nil), (*ControlPlaneComponent)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
				
			||||||
		return Convert_kubeadm_ControlPlaneComponent_To_v1beta3_ControlPlaneComponent(a.(*kubeadm.ControlPlaneComponent), b.(*ControlPlaneComponent), scope)
 | 
							return Convert_kubeadm_ControlPlaneComponent_To_v1beta3_ControlPlaneComponent(a.(*kubeadm.ControlPlaneComponent), b.(*ControlPlaneComponent), scope)
 | 
				
			||||||
	}); err != nil {
 | 
						}); err != nil {
 | 
				
			||||||
@@ -209,6 +204,11 @@ func RegisterConversions(s *runtime.Scheme) error {
 | 
				
			|||||||
	}); err != nil {
 | 
						}); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if err := s.AddConversionFunc((*ClusterConfiguration)(nil), (*kubeadm.ClusterConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
				
			||||||
 | 
							return Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(a.(*ClusterConfiguration), b.(*kubeadm.ClusterConfiguration), scope)
 | 
				
			||||||
 | 
						}); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := s.AddConversionFunc((*ControlPlaneComponent)(nil), (*kubeadm.ControlPlaneComponent)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
						if err := s.AddConversionFunc((*ControlPlaneComponent)(nil), (*kubeadm.ControlPlaneComponent)(nil), func(a, b interface{}, scope conversion.Scope) error {
 | 
				
			||||||
		return Convert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent(a.(*ControlPlaneComponent), b.(*kubeadm.ControlPlaneComponent), scope)
 | 
							return Convert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent(a.(*ControlPlaneComponent), b.(*kubeadm.ControlPlaneComponent), scope)
 | 
				
			||||||
	}); err != nil {
 | 
						}); err != nil {
 | 
				
			||||||
@@ -336,11 +336,6 @@ func autoConvert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration is an autogenerated conversion function.
 | 
					 | 
				
			||||||
func Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in *ClusterConfiguration, out *kubeadm.ClusterConfiguration, s conversion.Scope) error {
 | 
					 | 
				
			||||||
	return autoConvert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in, out, s)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func autoConvert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in *kubeadm.ClusterConfiguration, out *ClusterConfiguration, s conversion.Scope) error {
 | 
					func autoConvert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in *kubeadm.ClusterConfiguration, out *ClusterConfiguration, s conversion.Scope) error {
 | 
				
			||||||
	// INFO: in.ComponentConfigs opted out of conversion generation
 | 
						// INFO: in.ComponentConfigs opted out of conversion generation
 | 
				
			||||||
	if err := Convert_kubeadm_Etcd_To_v1beta3_Etcd(&in.Etcd, &out.Etcd, s); err != nil {
 | 
						if err := Convert_kubeadm_Etcd_To_v1beta3_Etcd(&in.Etcd, &out.Etcd, s); err != nil {
 | 
				
			||||||
@@ -369,14 +364,10 @@ func autoConvert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in
 | 
				
			|||||||
	// INFO: in.CIImageRepository opted out of conversion generation
 | 
						// INFO: in.CIImageRepository opted out of conversion generation
 | 
				
			||||||
	out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
 | 
						out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
 | 
				
			||||||
	out.ClusterName = in.ClusterName
 | 
						out.ClusterName = in.ClusterName
 | 
				
			||||||
 | 
						// WARNING: in.EncryptionAlgorithm requires manual conversion: does not exist in peer-type
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Convert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration is an autogenerated conversion function.
 | 
					 | 
				
			||||||
func Convert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in *kubeadm.ClusterConfiguration, out *ClusterConfiguration, s conversion.Scope) error {
 | 
					 | 
				
			||||||
	return autoConvert_kubeadm_ClusterConfiguration_To_v1beta3_ClusterConfiguration(in, out, s)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func autoConvert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent(in *ControlPlaneComponent, out *kubeadm.ControlPlaneComponent, s conversion.Scope) error {
 | 
					func autoConvert_v1beta3_ControlPlaneComponent_To_kubeadm_ControlPlaneComponent(in *ControlPlaneComponent, out *kubeadm.ControlPlaneComponent, s conversion.Scope) error {
 | 
				
			||||||
	// WARNING: in.ExtraArgs requires manual conversion: inconvertible types (map[string]string vs []k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm.Arg)
 | 
						// WARNING: in.ExtraArgs requires manual conversion: inconvertible types (map[string]string vs []k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm.Arg)
 | 
				
			||||||
	out.ExtraVolumes = *(*[]kubeadm.HostPathMount)(unsafe.Pointer(&in.ExtraVolumes))
 | 
						out.ExtraVolumes = *(*[]kubeadm.HostPathMount)(unsafe.Pointer(&in.ExtraVolumes))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,6 +60,9 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// DefaultImagePullPolicy is the default image pull policy in kubeadm
 | 
						// DefaultImagePullPolicy is the default image pull policy in kubeadm
 | 
				
			||||||
	DefaultImagePullPolicy = corev1.PullIfNotPresent
 | 
						DefaultImagePullPolicy = corev1.PullIfNotPresent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// DefaultEncryptionAlgorithm is the default encryption algorithm.
 | 
				
			||||||
 | 
						DefaultEncryptionAlgorithm = EncryptionAlgorithmRSA
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func addDefaultingFuncs(scheme *runtime.Scheme) error {
 | 
					func addDefaultingFuncs(scheme *runtime.Scheme) error {
 | 
				
			||||||
@@ -99,6 +102,10 @@ func SetDefaults_ClusterConfiguration(obj *ClusterConfiguration) {
 | 
				
			|||||||
		obj.ClusterName = DefaultClusterName
 | 
							obj.ClusterName = DefaultClusterName
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if obj.EncryptionAlgorithm == "" {
 | 
				
			||||||
 | 
							obj.EncryptionAlgorithm = DefaultEncryptionAlgorithm
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SetDefaults_Etcd(obj)
 | 
						SetDefaults_Etcd(obj)
 | 
				
			||||||
	SetDefaults_APIServer(&obj.APIServer)
 | 
						SetDefaults_APIServer(&obj.APIServer)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,9 @@ limitations under the License.
 | 
				
			|||||||
//   - Replace the existing string/string extra argument maps with structured extra arguments that support duplicates.
 | 
					//   - Replace the existing string/string extra argument maps with structured extra arguments that support duplicates.
 | 
				
			||||||
//     The change applies to `ClusterConfiguration` - `APIServer.ExtraArgs, `ControllerManager.ExtraArgs`,
 | 
					//     The change applies to `ClusterConfiguration` - `APIServer.ExtraArgs, `ControllerManager.ExtraArgs`,
 | 
				
			||||||
//     `Scheduler.ExtraArgs`, `Etcd.Local.ExtraArgs`. Also to `NodeRegistrationOptions.KubeletExtraArgs`.
 | 
					//     `Scheduler.ExtraArgs`, `Etcd.Local.ExtraArgs`. Also to `NodeRegistrationOptions.KubeletExtraArgs`.
 | 
				
			||||||
 | 
					//   - Add `ClusterConfiguration.EncryptionAlgorithm` that can be used to set the asymmetric encryption algorithm
 | 
				
			||||||
 | 
					//     used for this cluster's keys and certificates. Can be "RSA" (default algorithm, key size is 2048) or
 | 
				
			||||||
 | 
					//     "ECDSA" (uses the P-256 eliptic curve).
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Migration from old kubeadm config versions
 | 
					// Migration from old kubeadm config versions
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -140,6 +140,11 @@ type ClusterConfiguration struct {
 | 
				
			|||||||
	// The cluster name
 | 
						// The cluster name
 | 
				
			||||||
	// +optional
 | 
						// +optional
 | 
				
			||||||
	ClusterName string `json:"clusterName,omitempty"`
 | 
						ClusterName string `json:"clusterName,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// EncryptionAlgorithm holds the type of asymmetric encryption algorithm used for keys and certificates.
 | 
				
			||||||
 | 
						// Can be "RSA" (default algorithm, key size is 2048) or "ECDSA" (uses the P-256 eliptic curve).
 | 
				
			||||||
 | 
						// +optional
 | 
				
			||||||
 | 
						EncryptionAlgorithm EncryptionAlgorithmType `json:"encryptionAlgorithm,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ControlPlaneComponent holds settings common to control plane component of the cluster
 | 
					// ControlPlaneComponent holds settings common to control plane component of the cluster
 | 
				
			||||||
@@ -513,3 +518,13 @@ type Arg struct {
 | 
				
			|||||||
type EnvVar struct {
 | 
					type EnvVar struct {
 | 
				
			||||||
	corev1.EnvVar `json:",inline"`
 | 
						corev1.EnvVar `json:",inline"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// EncryptionAlgorithmType can define an asymmetric encryption algorithm type.
 | 
				
			||||||
 | 
					type EncryptionAlgorithmType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// EncryptionAlgorithmECDSA defines the ECDSA encryption algorithm type.
 | 
				
			||||||
 | 
						EncryptionAlgorithmECDSA EncryptionAlgorithmType = "ECDSA"
 | 
				
			||||||
 | 
						// EncryptionAlgorithmRSA defines the RSA encryption algorithm type.
 | 
				
			||||||
 | 
						EncryptionAlgorithmRSA EncryptionAlgorithmType = "RSA"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -385,6 +385,7 @@ func autoConvert_v1beta4_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in
 | 
				
			|||||||
	out.ImageRepository = in.ImageRepository
 | 
						out.ImageRepository = in.ImageRepository
 | 
				
			||||||
	out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
 | 
						out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
 | 
				
			||||||
	out.ClusterName = in.ClusterName
 | 
						out.ClusterName = in.ClusterName
 | 
				
			||||||
 | 
						out.EncryptionAlgorithm = kubeadm.EncryptionAlgorithmType(in.EncryptionAlgorithm)
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -421,6 +422,7 @@ func autoConvert_kubeadm_ClusterConfiguration_To_v1beta4_ClusterConfiguration(in
 | 
				
			|||||||
	// INFO: in.CIImageRepository opted out of conversion generation
 | 
						// INFO: in.CIImageRepository opted out of conversion generation
 | 
				
			||||||
	out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
 | 
						out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
 | 
				
			||||||
	out.ClusterName = in.ClusterName
 | 
						out.ClusterName = in.ClusterName
 | 
				
			||||||
 | 
						out.EncryptionAlgorithm = EncryptionAlgorithmType(in.EncryptionAlgorithm)
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,6 +72,7 @@ func ValidateClusterConfiguration(c *kubeadm.ClusterConfiguration) field.ErrorLi
 | 
				
			|||||||
	allErrs = append(allErrs, ValidateHostPort(c.ControlPlaneEndpoint, field.NewPath("controlPlaneEndpoint"))...)
 | 
						allErrs = append(allErrs, ValidateHostPort(c.ControlPlaneEndpoint, field.NewPath("controlPlaneEndpoint"))...)
 | 
				
			||||||
	allErrs = append(allErrs, ValidateImageRepository(c.ImageRepository, field.NewPath("imageRepository"))...)
 | 
						allErrs = append(allErrs, ValidateImageRepository(c.ImageRepository, field.NewPath("imageRepository"))...)
 | 
				
			||||||
	allErrs = append(allErrs, ValidateEtcd(&c.Etcd, field.NewPath("etcd"))...)
 | 
						allErrs = append(allErrs, ValidateEtcd(&c.Etcd, field.NewPath("etcd"))...)
 | 
				
			||||||
 | 
						allErrs = append(allErrs, ValidateEncryptionAlgorithm(string(c.EncryptionAlgorithm), field.NewPath("encryptionAlgorithm"))...)
 | 
				
			||||||
	allErrs = append(allErrs, componentconfigs.Validate(c)...)
 | 
						allErrs = append(allErrs, componentconfigs.Validate(c)...)
 | 
				
			||||||
	return allErrs
 | 
						return allErrs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -337,6 +338,17 @@ func ValidateEtcd(e *kubeadm.Etcd, fldPath *field.Path) field.ErrorList {
 | 
				
			|||||||
	return allErrs
 | 
						return allErrs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ValidateEncryptionAlgorithm validates the public key algorithm
 | 
				
			||||||
 | 
					func ValidateEncryptionAlgorithm(algo string, fldPath *field.Path) field.ErrorList {
 | 
				
			||||||
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
 | 
						if algo != string(kubeadm.EncryptionAlgorithmRSA) && algo != string(kubeadm.EncryptionAlgorithmECDSA) {
 | 
				
			||||||
 | 
							msg := fmt.Sprintf("Invalid encryption algorithm. Must be %q or %q",
 | 
				
			||||||
 | 
								kubeadm.EncryptionAlgorithmRSA, kubeadm.EncryptionAlgorithmECDSA)
 | 
				
			||||||
 | 
							allErrs = append(allErrs, field.Invalid(fldPath, algo, msg))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return allErrs
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ValidateCertSANs validates alternative names
 | 
					// ValidateCertSANs validates alternative names
 | 
				
			||||||
func ValidateCertSANs(altnames []string, fldPath *field.Path) field.ErrorList {
 | 
					func ValidateCertSANs(altnames []string, fldPath *field.Path) field.ErrorList {
 | 
				
			||||||
	allErrs := field.ErrorList{}
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -514,6 +514,7 @@ func TestValidateInitConfiguration(t *testing.T) {
 | 
				
			|||||||
						DNSDomain:     "cluster.local",
 | 
											DNSDomain:     "cluster.local",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					CertificatesDir:     "/some/cert/dir",
 | 
										CertificatesDir:     "/some/cert/dir",
 | 
				
			||||||
 | 
										EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmRSA,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
									NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
				
			||||||
			}, false},
 | 
								}, false},
 | 
				
			||||||
@@ -529,6 +530,7 @@ func TestValidateInitConfiguration(t *testing.T) {
 | 
				
			|||||||
						DNSDomain:     "cluster.local",
 | 
											DNSDomain:     "cluster.local",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					CertificatesDir:     "/some/cert/dir",
 | 
										CertificatesDir:     "/some/cert/dir",
 | 
				
			||||||
 | 
										EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmRSA,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
									NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
				
			||||||
			}, false},
 | 
								}, false},
 | 
				
			||||||
@@ -544,6 +546,7 @@ func TestValidateInitConfiguration(t *testing.T) {
 | 
				
			|||||||
						DNSDomain:     "cluster.local",
 | 
											DNSDomain:     "cluster.local",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					CertificatesDir:     "/some/other/cert/dir",
 | 
										CertificatesDir:     "/some/other/cert/dir",
 | 
				
			||||||
 | 
										EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmRSA,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			}, false},
 | 
								}, false},
 | 
				
			||||||
		{"valid InitConfiguration with incorrect IPv4 pod subnet",
 | 
							{"valid InitConfiguration with incorrect IPv4 pod subnet",
 | 
				
			||||||
@@ -559,6 +562,7 @@ func TestValidateInitConfiguration(t *testing.T) {
 | 
				
			|||||||
						PodSubnet:     "10.0.1.15",
 | 
											PodSubnet:     "10.0.1.15",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					CertificatesDir:     "/some/other/cert/dir",
 | 
										CertificatesDir:     "/some/other/cert/dir",
 | 
				
			||||||
 | 
										EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmRSA,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
									NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
				
			||||||
			}, false},
 | 
								}, false},
 | 
				
			||||||
@@ -581,6 +585,7 @@ func TestValidateInitConfiguration(t *testing.T) {
 | 
				
			|||||||
						PodSubnet:     "10.0.1.15/16",
 | 
											PodSubnet:     "10.0.1.15/16",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					CertificatesDir:     "/some/other/cert/dir",
 | 
										CertificatesDir:     "/some/other/cert/dir",
 | 
				
			||||||
 | 
										EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmRSA,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
									NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
				
			||||||
			}, true},
 | 
								}, true},
 | 
				
			||||||
@@ -602,6 +607,7 @@ func TestValidateInitConfiguration(t *testing.T) {
 | 
				
			|||||||
						DNSDomain:     "cluster.local",
 | 
											DNSDomain:     "cluster.local",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					CertificatesDir:     "/some/other/cert/dir",
 | 
										CertificatesDir:     "/some/other/cert/dir",
 | 
				
			||||||
 | 
										EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmECDSA,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
									NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: nodename, CRISocket: criPath},
 | 
				
			||||||
			}, true},
 | 
								}, true},
 | 
				
			||||||
@@ -1187,6 +1193,26 @@ func TestValidateEtcd(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValidateEncryptionAlgorithm(t *testing.T) {
 | 
				
			||||||
 | 
						var tests = []struct {
 | 
				
			||||||
 | 
							name           string
 | 
				
			||||||
 | 
							algo           string
 | 
				
			||||||
 | 
							expectedErrors bool
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{name: "valid RSA", algo: string(kubeadmapi.EncryptionAlgorithmRSA), expectedErrors: false},
 | 
				
			||||||
 | 
							{name: "valid ECDSA", algo: string(kubeadmapi.EncryptionAlgorithmECDSA), expectedErrors: false},
 | 
				
			||||||
 | 
							{name: "invalid algorithm", algo: "foo", expectedErrors: true},
 | 
				
			||||||
 | 
							{name: "empty algorithm returns an error", algo: "", expectedErrors: true},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, tc := range tests {
 | 
				
			||||||
 | 
							actual := ValidateEncryptionAlgorithm(tc.algo, field.NewPath("encryptionAlgorithm"))
 | 
				
			||||||
 | 
							actualErrors := len(actual) > 0
 | 
				
			||||||
 | 
							if actualErrors != tc.expectedErrors {
 | 
				
			||||||
 | 
								t.Errorf("error: validate public key algorithm: %q\n\texpected: %t\n\t  actual: %t", tc.algo, tc.expectedErrors, actualErrors)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetClusterNodeMask(t *testing.T) {
 | 
					func TestGetClusterNodeMask(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name          string
 | 
							name          string
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -188,7 +188,7 @@ func runCertsSa(c workflow.RunData) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// create the new service account key (or use existing)
 | 
						// create the new service account key (or use existing)
 | 
				
			||||||
	return certsphase.CreateServiceAccountKeyAndPublicKeyFiles(data.CertificateWriteDir(), data.Cfg().ClusterConfiguration.PublicKeyAlgorithm())
 | 
						return certsphase.CreateServiceAccountKeyAndPublicKeyFiles(data.CertificateWriteDir(), data.Cfg().ClusterConfiguration.EncryptionAlgorithmType())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func runCerts(c workflow.RunData) error {
 | 
					func runCerts(c workflow.RunData) error {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,10 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// InitFeatureGates are the default feature gates for the init command
 | 
					// InitFeatureGates are the default feature gates for the init command
 | 
				
			||||||
var InitFeatureGates = FeatureList{
 | 
					var InitFeatureGates = FeatureList{
 | 
				
			||||||
	PublicKeysECDSA:      {FeatureSpec: featuregate.FeatureSpec{Default: false, PreRelease: featuregate.Alpha}},
 | 
						PublicKeysECDSA: {
 | 
				
			||||||
 | 
							FeatureSpec:        featuregate.FeatureSpec{Default: false, PreRelease: featuregate.Deprecated},
 | 
				
			||||||
 | 
							DeprecationMessage: "The PublicKeysECDSA feature gate is deprecated and will be removed after the feature 'ClusterConfiguration.EncryptionAlgorithm' is added.",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
	RootlessControlPlane: {FeatureSpec: featuregate.FeatureSpec{Default: false, PreRelease: featuregate.Alpha}},
 | 
						RootlessControlPlane: {FeatureSpec: featuregate.FeatureSpec{Default: false, PreRelease: featuregate.Alpha}},
 | 
				
			||||||
	EtcdLearnerMode:      {FeatureSpec: featuregate.FeatureSpec{Default: true, PreRelease: featuregate.Beta}},
 | 
						EtcdLearnerMode:      {FeatureSpec: featuregate.FeatureSpec{Default: true, PreRelease: featuregate.Beta}},
 | 
				
			||||||
	UpgradeAddonsBeforeControlPlane: {
 | 
						UpgradeAddonsBeforeControlPlane: {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,7 +60,7 @@ func (k *KubeadmCert) GetConfig(ic *kubeadmapi.InitConfiguration) (*pkiutil.Cert
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	k.config.PublicKeyAlgorithm = ic.ClusterConfiguration.PublicKeyAlgorithm()
 | 
						k.config.EncryptionAlgorithm = ic.ClusterConfiguration.EncryptionAlgorithmType()
 | 
				
			||||||
	return &k.config, nil
 | 
						return &k.config, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,12 +69,12 @@ func CreatePKIAssets(cfg *kubeadmapi.InitConfiguration) error {
 | 
				
			|||||||
	fmt.Printf("[certs] Valid certificates and keys now exist in %q\n", cfg.CertificatesDir)
 | 
						fmt.Printf("[certs] Valid certificates and keys now exist in %q\n", cfg.CertificatesDir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Service accounts are not x509 certs, so handled separately
 | 
						// Service accounts are not x509 certs, so handled separately
 | 
				
			||||||
	return CreateServiceAccountKeyAndPublicKeyFiles(cfg.CertificatesDir, cfg.ClusterConfiguration.PublicKeyAlgorithm())
 | 
						return CreateServiceAccountKeyAndPublicKeyFiles(cfg.CertificatesDir, cfg.ClusterConfiguration.EncryptionAlgorithmType())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CreateServiceAccountKeyAndPublicKeyFiles creates new public/private key files for signing service account users.
 | 
					// CreateServiceAccountKeyAndPublicKeyFiles creates new public/private key files for signing service account users.
 | 
				
			||||||
// If the sa public/private key files already exist in the target folder, they are used only if evaluated equals; otherwise an error is returned.
 | 
					// If the sa public/private key files already exist in the target folder, they are used only if evaluated equals; otherwise an error is returned.
 | 
				
			||||||
func CreateServiceAccountKeyAndPublicKeyFiles(certsDir string, keyType x509.PublicKeyAlgorithm) error {
 | 
					func CreateServiceAccountKeyAndPublicKeyFiles(certsDir string, keyType kubeadmapi.EncryptionAlgorithmType) error {
 | 
				
			||||||
	klog.V(1).Infoln("creating new public/private key files for signing service account users")
 | 
						klog.V(1).Infoln("creating new public/private key files for signing service account users")
 | 
				
			||||||
	_, err := keyutil.PrivateKeyFromFile(filepath.Join(certsDir, kubeadmconstants.ServiceAccountPrivateKeyName))
 | 
						_, err := keyutil.PrivateKeyFromFile(filepath.Join(certsDir, kubeadmconstants.ServiceAccountPrivateKeyName))
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -347,7 +347,7 @@ func TestCreateServiceAccountKeyAndPublicKeyFiles(t *testing.T) {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			err := CreateServiceAccountKeyAndPublicKeyFiles(dir, x509.RSA)
 | 
								err := CreateServiceAccountKeyAndPublicKeyFiles(dir, kubeadmapi.EncryptionAlgorithmRSA)
 | 
				
			||||||
			if (err != nil) != tt.expectedErr {
 | 
								if (err != nil) != tt.expectedErr {
 | 
				
			||||||
				t.Fatalf("expected error: %v, got: %v, error: %v", tt.expectedErr, err != nil, err)
 | 
									t.Fatalf("expected error: %v, got: %v, error: %v", tt.expectedErr, err != nil, err)
 | 
				
			||||||
			} else if tt.expectedErr {
 | 
								} else if tt.expectedErr {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -228,7 +228,7 @@ func (rm *Manager) RenewUsingLocalCA(name string) (bool, error) {
 | 
				
			|||||||
	// extract the certificate config
 | 
						// extract the certificate config
 | 
				
			||||||
	cfg := &pkiutil.CertConfig{
 | 
						cfg := &pkiutil.CertConfig{
 | 
				
			||||||
		Config:              certToConfig(cert),
 | 
							Config:              certToConfig(cert),
 | 
				
			||||||
		PublicKeyAlgorithm: rm.cfg.PublicKeyAlgorithm(),
 | 
							EncryptionAlgorithm: rm.cfg.EncryptionAlgorithmType(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// reads the CA
 | 
						// reads the CA
 | 
				
			||||||
@@ -271,7 +271,7 @@ func (rm *Manager) CreateRenewCSR(name, outdir string) error {
 | 
				
			|||||||
	// extracts the certificate config
 | 
						// extracts the certificate config
 | 
				
			||||||
	cfg := &pkiutil.CertConfig{
 | 
						cfg := &pkiutil.CertConfig{
 | 
				
			||||||
		Config:              certToConfig(cert),
 | 
							Config:              certToConfig(cert),
 | 
				
			||||||
		PublicKeyAlgorithm: rm.cfg.PublicKeyAlgorithm(),
 | 
							EncryptionAlgorithm: rm.cfg.EncryptionAlgorithmType(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// generates the CSR request and save it
 | 
						// generates the CSR request and save it
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -482,7 +482,7 @@ func createKubeConfigAndCSR(kubeConfigDir string, kubeadmConfig *kubeadmapi.Init
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	clientCertConfig := newClientCertConfigFromKubeConfigSpec(spec, nil)
 | 
						clientCertConfig := newClientCertConfigFromKubeConfigSpec(spec, nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	clientKey, err := pkiutil.NewPrivateKey(clientCertConfig.PublicKeyAlgorithm)
 | 
						clientKey, err := pkiutil.NewPrivateKey(clientCertConfig.EncryptionAlgorithm)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,16 +60,16 @@ const (
 | 
				
			|||||||
	rsaKeySize             = 2048
 | 
						rsaKeySize             = 2048
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CertConfig is a wrapper around certutil.Config extending it with PublicKeyAlgorithm.
 | 
					// CertConfig is a wrapper around certutil.Config extending it with EncryptionAlgorithm.
 | 
				
			||||||
type CertConfig struct {
 | 
					type CertConfig struct {
 | 
				
			||||||
	certutil.Config
 | 
						certutil.Config
 | 
				
			||||||
	NotAfter            *time.Time
 | 
						NotAfter            *time.Time
 | 
				
			||||||
	PublicKeyAlgorithm x509.PublicKeyAlgorithm
 | 
						EncryptionAlgorithm kubeadmapi.EncryptionAlgorithmType
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewCertificateAuthority creates new certificate and private key for the certificate authority
 | 
					// NewCertificateAuthority creates new certificate and private key for the certificate authority
 | 
				
			||||||
func NewCertificateAuthority(config *CertConfig) (*x509.Certificate, crypto.Signer, error) {
 | 
					func NewCertificateAuthority(config *CertConfig) (*x509.Certificate, crypto.Signer, error) {
 | 
				
			||||||
	key, err := NewPrivateKey(config.PublicKeyAlgorithm)
 | 
						key, err := NewPrivateKey(config.EncryptionAlgorithm)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, errors.Wrap(err, "unable to create private key while generating CA certificate")
 | 
							return nil, nil, errors.Wrap(err, "unable to create private key while generating CA certificate")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -86,7 +86,7 @@ func NewCertificateAuthority(config *CertConfig) (*x509.Certificate, crypto.Sign
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// NewIntermediateCertificateAuthority creates new certificate and private key for an intermediate certificate authority
 | 
					// NewIntermediateCertificateAuthority creates new certificate and private key for an intermediate certificate authority
 | 
				
			||||||
func NewIntermediateCertificateAuthority(parentCert *x509.Certificate, parentKey crypto.Signer, config *CertConfig) (*x509.Certificate, crypto.Signer, error) {
 | 
					func NewIntermediateCertificateAuthority(parentCert *x509.Certificate, parentKey crypto.Signer, config *CertConfig) (*x509.Certificate, crypto.Signer, error) {
 | 
				
			||||||
	key, err := NewPrivateKey(config.PublicKeyAlgorithm)
 | 
						key, err := NewPrivateKey(config.EncryptionAlgorithm)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, errors.Wrap(err, "unable to create private key while generating intermediate CA certificate")
 | 
							return nil, nil, errors.Wrap(err, "unable to create private key while generating intermediate CA certificate")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -105,7 +105,7 @@ func NewCertAndKey(caCert *x509.Certificate, caKey crypto.Signer, config *CertCo
 | 
				
			|||||||
		return nil, nil, errors.New("must specify at least one ExtKeyUsage")
 | 
							return nil, nil, errors.New("must specify at least one ExtKeyUsage")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	key, err := NewPrivateKey(config.PublicKeyAlgorithm)
 | 
						key, err := NewPrivateKey(config.EncryptionAlgorithm)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, errors.Wrap(err, "unable to create private key")
 | 
							return nil, nil, errors.Wrap(err, "unable to create private key")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -120,7 +120,7 @@ func NewCertAndKey(caCert *x509.Certificate, caKey crypto.Signer, config *CertCo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// NewCSRAndKey generates a new key and CSR and that could be signed to create the given certificate
 | 
					// NewCSRAndKey generates a new key and CSR and that could be signed to create the given certificate
 | 
				
			||||||
func NewCSRAndKey(config *CertConfig) (*x509.CertificateRequest, crypto.Signer, error) {
 | 
					func NewCSRAndKey(config *CertConfig) (*x509.CertificateRequest, crypto.Signer, error) {
 | 
				
			||||||
	key, err := NewPrivateKey(config.PublicKeyAlgorithm)
 | 
						key, err := NewPrivateKey(config.EncryptionAlgorithm)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, errors.Wrap(err, "unable to create private key")
 | 
							return nil, nil, errors.Wrap(err, "unable to create private key")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -623,8 +623,8 @@ func EncodePublicKeyPEM(key crypto.PublicKey) ([]byte, error) {
 | 
				
			|||||||
// NewPrivateKey returns a new private key.
 | 
					// NewPrivateKey returns a new private key.
 | 
				
			||||||
var NewPrivateKey = GeneratePrivateKey
 | 
					var NewPrivateKey = GeneratePrivateKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GeneratePrivateKey(keyType x509.PublicKeyAlgorithm) (crypto.Signer, error) {
 | 
					func GeneratePrivateKey(keyType kubeadmapi.EncryptionAlgorithmType) (crypto.Signer, error) {
 | 
				
			||||||
	if keyType == x509.ECDSA {
 | 
						if keyType == kubeadmapi.EncryptionAlgorithmECDSA {
 | 
				
			||||||
		return ecdsa.GenerateKey(elliptic.P256(), cryptorand.Reader)
 | 
							return ecdsa.GenerateKey(elliptic.P256(), cryptorand.Reader)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,7 +52,7 @@ func TestMain(m *testing.M) {
 | 
				
			|||||||
		Config: certutil.Config{
 | 
							Config: certutil.Config{
 | 
				
			||||||
			CommonName: "Root CA 1",
 | 
								CommonName: "Root CA 1",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		PublicKeyAlgorithm: x509.RSA,
 | 
							EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmRSA,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		panic(fmt.Sprintf("Failed generating Root CA: %v", err))
 | 
							panic(fmt.Sprintf("Failed generating Root CA: %v", err))
 | 
				
			||||||
@@ -112,7 +112,7 @@ func TestHasServerAuth(t *testing.T) {
 | 
				
			|||||||
	// Override NewPrivateKey to reuse the same key for all certs
 | 
						// Override NewPrivateKey to reuse the same key for all certs
 | 
				
			||||||
	// since this test is only checking cert.ExtKeyUsage
 | 
						// since this test is only checking cert.ExtKeyUsage
 | 
				
			||||||
	privateKeyFunc := NewPrivateKey
 | 
						privateKeyFunc := NewPrivateKey
 | 
				
			||||||
	NewPrivateKey = func(x509.PublicKeyAlgorithm) (crypto.Signer, error) {
 | 
						NewPrivateKey = func(kubeadmapi.EncryptionAlgorithmType) (crypto.Signer, error) {
 | 
				
			||||||
		return rootCAKey, nil
 | 
							return rootCAKey, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
@@ -141,7 +141,7 @@ func TestHasServerAuth(t *testing.T) {
 | 
				
			|||||||
					CommonName: "test",
 | 
										CommonName: "test",
 | 
				
			||||||
					Usages:     []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
 | 
										Usages:     []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				PublicKeyAlgorithm: x509.ECDSA,
 | 
									EncryptionAlgorithm: kubeadmapi.EncryptionAlgorithmECDSA,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expected: true,
 | 
								expected: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,6 @@ package testing
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"crypto"
 | 
						"crypto"
 | 
				
			||||||
	"crypto/x509"
 | 
					 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
@@ -29,6 +28,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
 | 
				
			||||||
	"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
 | 
						"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -75,7 +75,7 @@ func install() (cleanup func()) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newPrivateKey(keyType x509.PublicKeyAlgorithm) (crypto.Signer, error) {
 | 
					func newPrivateKey(keyType kubeadmapi.EncryptionAlgorithmType) (crypto.Signer, error) {
 | 
				
			||||||
	lock.Lock()
 | 
						lock.Lock()
 | 
				
			||||||
	defer lock.Unlock()
 | 
						defer lock.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -108,7 +108,7 @@ func newPrivateKey(keyType x509.PublicKeyAlgorithm) (crypto.Signer, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	keyName := ""
 | 
						keyName := ""
 | 
				
			||||||
	switch keyType {
 | 
						switch keyType {
 | 
				
			||||||
	case x509.ECDSA:
 | 
						case kubeadmapi.EncryptionAlgorithmECDSA:
 | 
				
			||||||
		ecdsa++
 | 
							ecdsa++
 | 
				
			||||||
		keyName = fmt.Sprintf("%d.ecdsa", ecdsa)
 | 
							keyName = fmt.Sprintf("%d.ecdsa", ecdsa)
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user