Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse SSH public key with correct function. #594

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
13 changes: 12 additions & 1 deletion cmd/metal-api/internal/service/machine-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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= [email protected]"},
Role: metal.RoleMachine,
},
isError: false,
name: "valid ssh",
},
{
spec: machineAllocationSpec{
UUID: "gopher-uuid",
Expand Down
Loading