From b792d60157dc0a0fc1577127629804b1f9c56ed6 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 13 Nov 2024 11:28:52 +0100 Subject: [PATCH] Parse SSH public key with correct function. (#594) --- cmd/metal-api/internal/service/machine-service.go | 2 +- .../internal/service/machine-service_test.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/metal-api/internal/service/machine-service.go b/cmd/metal-api/internal/service/machine-service.go index ed39f4f2..69e6fd11 100644 --- a/cmd/metal-api/internal/service/machine-service.go +++ b/cmd/metal-api/internal/service/machine-service.go @@ -1380,7 +1380,7 @@ func validateAllocationSpec(allocationSpec *machineAllocationSpec) error { for _, pubKey := range allocationSpec.SSHPubKeys { _, _, _, _, err := ssh.ParseAuthorizedKey([]byte(pubKey)) if err != nil { - return fmt.Errorf("invalid public SSH key: %s", pubKey) + return fmt.Errorf("invalid public SSH key: %s error:%w", pubKey, err) } } diff --git a/cmd/metal-api/internal/service/machine-service_test.go b/cmd/metal-api/internal/service/machine-service_test.go index 39a66251..c4fb836e 100644 --- a/cmd/metal-api/internal/service/machine-service_test.go +++ b/cmd/metal-api/internal/service/machine-service_test.go @@ -645,9 +645,20 @@ func Test_validateAllocationSpec(t *testing.T) { Role: metal.RoleMachine, }, isError: true, - expected: `invalid public SSH key: 42`, + expected: `invalid public SSH key: 42 error:ssh: no key found`, name: "invalid ssh", }, + { + spec: machineAllocationSpec{ + UUID: "43", + Creator: testEmail, + ProjectID: "123", + SSHPubKeys: []string{"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBH9uyBvRBTUJFFAOKB/ZH/5Mm/MrqEDhkB4wTPWbJaJ5zHirBrLS1qk2Ut0yEL4vZvfnafnrzsed3n75/1BSmSg= test@metal-stack.io"}, + Role: metal.RoleMachine, + }, + isError: false, + name: "valid ssh", + }, { spec: machineAllocationSpec{ UUID: "gopher-uuid",