From 4d4f0414d0861aea16ce86670d4d06439e3f42d1 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Thu, 16 Jan 2025 16:12:31 +0100 Subject: [PATCH] Addressed review comments --- config/crd/bases/metal.ironcore.dev_bmcs.yaml | 2 +- config/crd/bases/metal.ironcore.dev_bmcsecrets.yaml | 2 +- config/crd/bases/metal.ironcore.dev_endpoints.yaml | 2 +- .../metal.ironcore.dev_serverbootconfigurations.yaml | 2 +- config/crd/bases/metal.ironcore.dev_serverclaims.yaml | 2 +- config/crd/bases/metal.ironcore.dev_servers.yaml | 2 +- internal/controller/server_controller.go | 11 +++++------ internal/controller/server_controller_test.go | 8 ++++++-- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/config/crd/bases/metal.ironcore.dev_bmcs.yaml b/config/crd/bases/metal.ironcore.dev_bmcs.yaml index d310379..be9de9f 100644 --- a/config/crd/bases/metal.ironcore.dev_bmcs.yaml +++ b/config/crd/bases/metal.ironcore.dev_bmcs.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.17.1 name: bmcs.metal.ironcore.dev spec: group: metal.ironcore.dev diff --git a/config/crd/bases/metal.ironcore.dev_bmcsecrets.yaml b/config/crd/bases/metal.ironcore.dev_bmcsecrets.yaml index e0a7bb6..3097e32 100644 --- a/config/crd/bases/metal.ironcore.dev_bmcsecrets.yaml +++ b/config/crd/bases/metal.ironcore.dev_bmcsecrets.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.17.1 name: bmcsecrets.metal.ironcore.dev spec: group: metal.ironcore.dev diff --git a/config/crd/bases/metal.ironcore.dev_endpoints.yaml b/config/crd/bases/metal.ironcore.dev_endpoints.yaml index b7787b5..a8c53de 100644 --- a/config/crd/bases/metal.ironcore.dev_endpoints.yaml +++ b/config/crd/bases/metal.ironcore.dev_endpoints.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.17.1 name: endpoints.metal.ironcore.dev spec: group: metal.ironcore.dev diff --git a/config/crd/bases/metal.ironcore.dev_serverbootconfigurations.yaml b/config/crd/bases/metal.ironcore.dev_serverbootconfigurations.yaml index b8423fb..9a9f841 100644 --- a/config/crd/bases/metal.ironcore.dev_serverbootconfigurations.yaml +++ b/config/crd/bases/metal.ironcore.dev_serverbootconfigurations.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.17.1 name: serverbootconfigurations.metal.ironcore.dev spec: group: metal.ironcore.dev diff --git a/config/crd/bases/metal.ironcore.dev_serverclaims.yaml b/config/crd/bases/metal.ironcore.dev_serverclaims.yaml index fe97561..c94d7b5 100644 --- a/config/crd/bases/metal.ironcore.dev_serverclaims.yaml +++ b/config/crd/bases/metal.ironcore.dev_serverclaims.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.17.1 name: serverclaims.metal.ironcore.dev spec: group: metal.ironcore.dev diff --git a/config/crd/bases/metal.ironcore.dev_servers.yaml b/config/crd/bases/metal.ironcore.dev_servers.yaml index be46967..9935d33 100644 --- a/config/crd/bases/metal.ironcore.dev_servers.yaml +++ b/config/crd/bases/metal.ironcore.dev_servers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.17.1 name: servers.metal.ironcore.dev spec: group: metal.ironcore.dev diff --git a/internal/controller/server_controller.go b/internal/controller/server_controller.go index 8d2f2d3..baf91ad 100644 --- a/internal/controller/server_controller.go +++ b/internal/controller/server_controller.go @@ -7,7 +7,6 @@ import ( "context" "crypto/rand" "crypto/rsa" - "crypto/x509" "encoding/json" "encoding/pem" "fmt" @@ -567,11 +566,11 @@ func generateSSHKeyPairAndPassword() ([]byte, []byte, []byte, error) { return nil, nil, nil, fmt.Errorf("failed to generate private key: %w", err) } - privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey) - privateKeyPem := pem.EncodeToMemory(&pem.Block{ - Type: "RSA PRIVATE KEY", - Bytes: privateKeyBytes, - }) + privateKeyBlock, err := ssh.MarshalPrivateKey(privateKey, "") + if err != nil { + return nil, nil, nil, err + } + privateKeyPem := pem.EncodeToMemory(privateKeyBlock) sshPubKey, err := ssh.NewPublicKey(&privateKey.PublicKey) if err != nil { diff --git a/internal/controller/server_controller_test.go b/internal/controller/server_controller_test.go index d068101..9b02fe0 100644 --- a/internal/controller/server_controller_test.go +++ b/internal/controller/server_controller_test.go @@ -25,7 +25,7 @@ import ( . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" ) -var _ = FDescribe("Server Controller", func() { +var _ = Describe("Server Controller", func() { ns := SetupTest() It("Should initialize a Server from Endpoint", func(ctx SpecContext) { @@ -306,6 +306,10 @@ var _ = FDescribe("Server Controller", func() { HaveField("Data", HaveKeyWithValue(SSHKeyPairSecretPrivateKeyName, Not(BeEmpty()))), HaveField("Data", HaveKeyWithValue(SShKeyPairSecretPasswordKeyName, Not(BeEmpty()))), )) + _, err := ssh.ParsePrivateKey(sshSecret.Data[SSHKeyPairSecretPrivateKeyName]) + Expect(err).NotTo(HaveOccurred()) + _, _, _, _, err = ssh.ParseAuthorizedKey(sshSecret.Data[SSHKeyPairSecretPublicKeyName]) + Expect(err).NotTo(HaveOccurred()) By("Ensuring that the default ignition configuration has been created") ignitionSecret := &v1.Secret{ @@ -339,7 +343,7 @@ var _ = FDescribe("Server Controller", func() { ignitionData, err := ignition.GenerateDefaultIgnitionData(ignition.Config{ Image: "foo:latest", Flags: "--registry-url=http://localhost:30000 --server-uuid=38947555-7742-3448-3784-823347823834", - SSHPublicKey: string(sshSecret.Data["public"]), + SSHPublicKey: string(sshSecret.Data[SSHKeyPairSecretPublicKeyName]), PasswordHash: passwordHash, }) Expect(err).NotTo(HaveOccurred())