Skip to content

Commit 87d9768

Browse files
authored
Merge pull request #12859 from Karthik-K-N/rsa-key
✨ Add EncryptionAlgorithm to Kubeadmconfig
2 parents 0b520b1 + 1c76d86 commit 87d9768

32 files changed

+357
-77
lines changed

api/bootstrap/kubeadm/v1beta1/conversion.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func RestoreKubeadmConfigSpec(restored *bootstrapv1.KubeadmConfigSpec, dst *boot
8181
dst.ClusterConfiguration.CACertificateValidityPeriodDays = restored.ClusterConfiguration.CACertificateValidityPeriodDays
8282
}
8383
}
84+
if restored.ClusterConfiguration.EncryptionAlgorithm != "" {
85+
dst.ClusterConfiguration.EncryptionAlgorithm = restored.ClusterConfiguration.EncryptionAlgorithm
86+
}
8487
}
8588

8689
func RestoreBoolIntentKubeadmConfigSpec(src *KubeadmConfigSpec, dst *bootstrapv1.KubeadmConfigSpec, hasRestored bool, restored *bootstrapv1.KubeadmConfigSpec) error {

api/bootstrap/kubeadm/v1beta1/zz_generated.conversion.go

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

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ const (
7272
KubeadmConfigDataSecretNotAvailableReason = clusterv1.NotAvailableReason
7373
)
7474

75+
// EncryptionAlgorithmType can define an asymmetric encryption algorithm type.
76+
// +kubebuilder:validation:Enum=ECDSA-P256;ECDSA-P384;RSA-2048;RSA-3072;RSA-4096
77+
type EncryptionAlgorithmType string
78+
79+
const (
80+
// EncryptionAlgorithmECDSAP256 defines the ECDSA encryption algorithm type with curve P256.
81+
EncryptionAlgorithmECDSAP256 EncryptionAlgorithmType = "ECDSA-P256"
82+
// EncryptionAlgorithmECDSAP384 defines the ECDSA encryption algorithm type with curve P384.
83+
EncryptionAlgorithmECDSAP384 EncryptionAlgorithmType = "ECDSA-P384"
84+
// EncryptionAlgorithmRSA2048 defines the RSA encryption algorithm type with key size 2048 bits.
85+
EncryptionAlgorithmRSA2048 EncryptionAlgorithmType = "RSA-2048"
86+
// EncryptionAlgorithmRSA3072 defines the RSA encryption algorithm type with key size 3072 bits.
87+
EncryptionAlgorithmRSA3072 EncryptionAlgorithmType = "RSA-3072"
88+
// EncryptionAlgorithmRSA4096 defines the RSA encryption algorithm type with key size 4096 bits.
89+
EncryptionAlgorithmRSA4096 EncryptionAlgorithmType = "RSA-4096"
90+
)
91+
7592
// InitConfiguration contains a list of elements that is specific "kubeadm init"-only runtime
7693
// information.
7794
// +kubebuilder:validation:MinProperties=1
@@ -199,6 +216,16 @@ type ClusterConfiguration struct {
199216
// +kubebuilder:validation:Minimum=1
200217
// +kubebuilder:validation:Maximum=36500
201218
CACertificateValidityPeriodDays int32 `json:"caCertificateValidityPeriodDays,omitempty"`
219+
220+
// encryptionAlgorithm holds the type of asymmetric encryption algorithm used for keys and certificates.
221+
// Can be one of "RSA-2048", "RSA-3072", "RSA-4096", "ECDSA-P256" or "ECDSA-P384".
222+
// For Kubernetes 1.34 or above, "ECDSA-P384" is supported.
223+
// If not specified, Cluster API will use RSA-2048 as default.
224+
// When this field is modified every certificate generated afterward will use the new
225+
// encryptionAlgorithm. Existing CA certificates and service account keys are not rotated.
226+
// This field is only supported with Kubernetes v1.31 or above.
227+
// +optional
228+
EncryptionAlgorithm EncryptionAlgorithmType `json:"encryptionAlgorithm,omitempty"`
202229
}
203230

204231
// IsDefined returns true if the ClusterConfiguration is defined.

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml

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

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml

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

bootstrap/kubeadm/types/upstreamv1beta3/conversion_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func hubClusterConfigurationFuzzer(obj *bootstrapv1.ClusterConfiguration, c rand
276276

277277
obj.CertificateValidityPeriodDays = 0
278278
obj.CACertificateValidityPeriodDays = 0
279+
obj.EncryptionAlgorithm = ""
279280

280281
for i, arg := range obj.APIServer.ExtraArgs {
281282
if arg.Value == nil {

bootstrap/kubeadm/types/upstreamv1beta3/zz_generated.conversion.go

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

bootstrap/kubeadm/types/upstreamv1beta4/conversion.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (dst *JoinConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
6767
func Convert_upstreamv1beta4_ClusterConfiguration_To_v1beta2_ClusterConfiguration(in *ClusterConfiguration, out *bootstrapv1.ClusterConfiguration, s apimachineryconversion.Scope) error {
6868
// Following fields do not exist in CABPK v1beta1 version:
6969
// - Proxy (Not supported yet)
70-
// - EncryptionAlgorithm (Not supported yet)
7170
if err := autoConvert_upstreamv1beta4_ClusterConfiguration_To_v1beta2_ClusterConfiguration(in, out, s); err != nil {
7271
return err
7372
}

bootstrap/kubeadm/types/upstreamv1beta4/conversion_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ func spokeClusterConfigurationFuzzer(obj *ClusterConfiguration, c randfill.Conti
107107
c.FillNoCustom(obj)
108108

109109
obj.Proxy = Proxy{}
110-
obj.EncryptionAlgorithm = ""
111110
obj.CertificateValidityPeriod = ptr.To[metav1.Duration](metav1.Duration{Duration: time.Duration(c.Int31n(3*365)+1) * time.Hour * 24})
112111
obj.CACertificateValidityPeriod = ptr.To[metav1.Duration](metav1.Duration{Duration: time.Duration(c.Int31n(100*365)+1) * time.Hour * 24})
113112

bootstrap/kubeadm/types/upstreamv1beta4/zz_generated.conversion.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)