Skip to content

Commit 1c76d86

Browse files
committed
Address review comme
1 parent a41ee45 commit 1c76d86

File tree

9 files changed

+28
-15
lines changed

9 files changed

+28
-15
lines changed

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ type ClusterConfiguration struct {
219219

220220
// encryptionAlgorithm holds the type of asymmetric encryption algorithm used for keys and certificates.
221221
// 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.
222223
// 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.
223226
// This field is only supported with Kubernetes v1.31 or above.
224227
// +optional
225228
EncryptionAlgorithm EncryptionAlgorithmType `json:"encryptionAlgorithm,omitempty"`

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

Lines changed: 3 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: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml

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

controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml

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

controlplane/kubeadm/internal/cluster.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ func (m *Management) GetWorkloadCluster(ctx context.Context, clusterKey client.O
142142
var clientCert tls.Certificate
143143
if keyData != nil {
144144
// Get client cert from cache if possible, otherwise generate it and add it to the cache.
145-
// TODO: When we implement ClusterConfiguration.EncryptionAlgorithm we should add it to
146-
// the ClientCertEntries and make it part of the key.
147145
if entry, ok := m.ClientCertCache.Has(ClientCertEntry{Cluster: clusterKey, EncryptionAlgorithm: keyEncryptionAlgorithm}.Key()); ok {
148146
clientCert = *entry.ClientCert
149147
} else {

test/e2e/data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ spec:
9999
apiServer:
100100
# host.docker.internal is required by kubetest when running on MacOS because of the way ports are proxied.
101101
certSANs: [localhost, 127.0.0.1, 0.0.0.0, host.docker.internal]
102+
encryptionAlgorithm: "RSA-4096"
102103
---
103104
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
104105
kind: DockerMachineTemplate

util/certs/certs.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ func NewSigner(keyEncryptionAlgorithm bootstrapv1.EncryptionAlgorithmType) (cryp
131131
if rsaKeySize == 0 {
132132
return nil, errors.Errorf("cannot obtain key size from unknown RSA algorithm: %q", keyEncryptionAlgorithm)
133133
}
134-
pk, err := rsa.GenerateKey(rand.Reader, rsaKeySize)
135-
return pk, errors.WithStack(err)
134+
return rsa.GenerateKey(rand.Reader, rsaKeySize)
136135
}
137136

138137
// EncodePrivateKeyPEMFromSigner converts a known private key type of RSA or ECDSA to
@@ -164,7 +163,7 @@ func EncodePrivateKeyPEMFromSigner(key crypto.PrivateKey) ([]byte, error) {
164163
func EncodePublicKeyPEMFromSigner(key crypto.PublicKey) ([]byte, error) {
165164
der, err := x509.MarshalPKIXPublicKey(key)
166165
if err != nil {
167-
return []byte{}, errors.WithStack(err)
166+
return []byte{}, err
168167
}
169168
block := pem.Block{
170169
Type: "PUBLIC KEY",
@@ -173,9 +172,9 @@ func EncodePublicKeyPEMFromSigner(key crypto.PublicKey) ([]byte, error) {
173172
return pem.EncodeToMemory(&block), nil
174173
}
175174

176-
// rsaKeySizeFromAlgorithmType takes a known RSA algorithm defined in the kubeadm API
177-
// and returns its key size. For unknown types it returns 0. For an empty type it returns
178-
// the default size of 2048.
175+
// rsaKeySizeFromAlgorithmType takes a known RSA algorithm defined in the kubeadm API and returns its key size.
176+
// For unknown types it returns 0.
177+
// For an empty type ("") which is the default (zero value) on the API field it returns the default size of 2048.
179178
func rsaKeySizeFromAlgorithmType(keyEncryptionAlgorithm bootstrapv1.EncryptionAlgorithmType) int {
180179
switch keyEncryptionAlgorithm {
181180
case bootstrapv1.EncryptionAlgorithmRSA2048, "":

util/kubeconfig/options.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import bootstrapv1 "sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2"
2020

2121
// KubeConfigOption helps to modify KubeConfigOptions.
2222
type KubeConfigOption interface { //nolint:revive
23-
// ApplyKubeConfigurationOption applies this options to the given kube configuration options.
24-
ApplyKubeConfigurationOption(*KubeConfigOptions)
23+
// ApplyKubeConfigOption applies this options to the given KubeConfigOptions options.
24+
ApplyKubeConfigOption(*KubeConfigOptions)
2525
}
2626

27-
// KubeConfigOptions allows to set options for generating kube configuration.
27+
// KubeConfigOptions allows to set options for generating a kubeconfig.
2828
type KubeConfigOptions struct { //nolint:revive
2929
keyEncryptionAlgorithm bootstrapv1.EncryptionAlgorithmType
3030
}
@@ -33,14 +33,14 @@ type KubeConfigOptions struct { //nolint:revive
3333
// and then returns itself (for convenient chaining).
3434
func (o *KubeConfigOptions) ApplyOptions(opts []KubeConfigOption) {
3535
for _, opt := range opts {
36-
opt.ApplyKubeConfigurationOption(o)
36+
opt.ApplyKubeConfigOption(o)
3737
}
3838
}
3939

4040
// KeyEncryptionAlgorithm allows to specify the key encryption algorithm type.
41-
type KeyEncryptionAlgorithm string
41+
type KeyEncryptionAlgorithm bootstrapv1.EncryptionAlgorithmType
4242

43-
// ApplyKubeConfigurationOption applies this configuration to the given kube configuration options.
44-
func (t KeyEncryptionAlgorithm) ApplyKubeConfigurationOption(opts *KubeConfigOptions) {
43+
// ApplyKubeConfigOption applies this configuration to the given kube configuration options.
44+
func (t KeyEncryptionAlgorithm) ApplyKubeConfigOption(opts *KubeConfigOptions) {
4545
opts.keyEncryptionAlgorithm = bootstrapv1.EncryptionAlgorithmType(t)
4646
}

0 commit comments

Comments
 (0)