From 173442c429807f25e69d93a0ba03817128637cae Mon Sep 17 00:00:00 2001 From: pormirza Date: Wed, 21 Oct 2026 12:02:08 +0200 Subject: [PATCH 1/4] allow passing multiple ssh public keys to machine create --- pkg/helpers/machine.go | 45 +++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/pkg/helpers/machine.go b/pkg/helpers/machine.go index 233a695..312b42e 100644 --- a/pkg/helpers/machine.go +++ b/pkg/helpers/machine.go @@ -91,35 +91,47 @@ func MachineCreateRequestFromCLI(c *config.Config) (*apiv2.MachineServiceCreateR allocationType apiv2.MachineAllocationType firewallSpec *apiv2.FirewallSpec - sshPublicKeyArgument = viper.GetString("ssh-public-key") + sshPublicKeyArgument = viper.GetStringSlice("ssh-public-key") dnsServersArgument = viper.GetStringSlice("dns-servers") ntpServersArgument = viper.GetStringSlice("ntp-servers") ) - - if strings.HasPrefix(sshPublicKeyArgument, "@") { - var err error - sshPublicKeyArgument, err = readFromFile(c.Fs, sshPublicKeyArgument[1:]) - if err != nil { - return nil, err + for _, k := range sshPublicKeyArgument { + if strings.HasPrefix(k, "@") { + var err error + k, err = readFromFile(c.Fs, k[1:]) + if err != nil { + return nil, err + } } + keys = append(keys, k) } - - if len(sshPublicKeyArgument) == 0 { + /* + if strings.HasPrefix(sshPublicKeyArgument, "@") { + var err error + sshPublicKeyArgument, err = readFromFile(c.Fs, sshPublicKeyArgument[1:]) + if err != nil { + return nil, err + } + } + */ + if len(keys) == 0 { sshKey, err := SearchSSHKey() if err != nil { return nil, err } sshPublicKey := sshKey + ".pub" - sshPublicKeyArgument, err = readFromFile(c.Fs, sshPublicKey) + key, err := readFromFile(c.Fs, sshPublicKey) if err != nil { return nil, err } + keys = append(keys, key) } - if sshPublicKeyArgument != "" { - keys = append(keys, sshPublicKeyArgument) - } - + /* + if sshPublicKeyArgument != "" { + keys = append(keys, sshPublicKeyArgument) + } + */ userDataArgument := viper.GetString("userdata") if strings.HasPrefix(userDataArgument, "@") { var err error @@ -548,9 +560,10 @@ func AddMachineCreateFlags(cmd *cobra.Command, name string, completion *completi cmd.Flags().StringP("project", "p", "", "Project where the "+name+" should belong to. [required]") cmd.Flags().String("size", "", "Size of the "+name+". [required, except for reserved machines]") cmd.Flags().String("allocation-type", "machine", "allocation type, can be either machine|firewall") - cmd.Flags().StringP("ssh-public-key", "i", "", + cmd.Flags().StringArrayP("ssh-public-key", "i", []string{}, `SSH public key for access via ssh and console. [optional] -Can be either the public key as string, or pointing to the public key file to use e.g.: "@~/.ssh/id_rsa.pub". + Multiple keys can be passed by doing -i [key] -i [key] ... +Can be either the public keys as strings, or pointing to the public keys file to use e.g.: "@~/.ssh/id_rsa.pub". If ~/.ssh/[id_ed25519.pub | id_rsa.pub | id_dsa.pub] is present it will be picked as default, matching the first one in this order.`) cmd.Flags().StringSlice("labels", []string{}, "labels to add to the "+name+", use it like: --labels \"a=b\" or --labels \"a=\".") cmd.Flags().String("userdata", "", `cloud-init.io compatible userdata. [optional] From 9975388bf6468f9457f96862d7164b8f55835f13 Mon Sep 17 00:00:00 2001 From: pormirza Date: Wed, 21 Oct 2026 12:02:08 +0200 Subject: [PATCH 2/4] delete commented old code --- pkg/helpers/machine.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/pkg/helpers/machine.go b/pkg/helpers/machine.go index 312b42e..c6ba2da 100644 --- a/pkg/helpers/machine.go +++ b/pkg/helpers/machine.go @@ -105,15 +105,7 @@ func MachineCreateRequestFromCLI(c *config.Config) (*apiv2.MachineServiceCreateR } keys = append(keys, k) } - /* - if strings.HasPrefix(sshPublicKeyArgument, "@") { - var err error - sshPublicKeyArgument, err = readFromFile(c.Fs, sshPublicKeyArgument[1:]) - if err != nil { - return nil, err - } - } - */ + if len(keys) == 0 { sshKey, err := SearchSSHKey() if err != nil { @@ -127,11 +119,6 @@ func MachineCreateRequestFromCLI(c *config.Config) (*apiv2.MachineServiceCreateR keys = append(keys, key) } - /* - if sshPublicKeyArgument != "" { - keys = append(keys, sshPublicKeyArgument) - } - */ userDataArgument := viper.GetString("userdata") if strings.HasPrefix(userDataArgument, "@") { var err error From 1b9c1ac1df76bb59ab1a37b0b462c79a9617b295 Mon Sep 17 00:00:00 2001 From: pormirza Date: Wed, 21 Oct 2026 12:02:08 +0200 Subject: [PATCH 3/4] fixed formating issue --- pkg/helpers/machine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/helpers/machine.go b/pkg/helpers/machine.go index c6ba2da..b2836e2 100644 --- a/pkg/helpers/machine.go +++ b/pkg/helpers/machine.go @@ -549,7 +549,7 @@ func AddMachineCreateFlags(cmd *cobra.Command, name string, completion *completi cmd.Flags().String("allocation-type", "machine", "allocation type, can be either machine|firewall") cmd.Flags().StringArrayP("ssh-public-key", "i", []string{}, `SSH public key for access via ssh and console. [optional] - Multiple keys can be passed by doing -i [key] -i [key] ... +Multiple keys can be passed by doing -i [key] -i [key] ... Can be either the public keys as strings, or pointing to the public keys file to use e.g.: "@~/.ssh/id_rsa.pub". If ~/.ssh/[id_ed25519.pub | id_rsa.pub | id_dsa.pub] is present it will be picked as default, matching the first one in this order.`) cmd.Flags().StringSlice("labels", []string{}, "labels to add to the "+name+", use it like: --labels \"a=b\" or --labels \"a=\".") From 32bcb4d1fa61029ef7677bcccc079cf3c21d3883 Mon Sep 17 00:00:00 2001 From: pormirza Date: Wed, 21 Oct 2026 12:02:08 +0200 Subject: [PATCH 4/4] add second ssh key to tests --- tests/e2e/admin/machine_test.go | 3 ++- tests/e2e/api/machine_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/e2e/admin/machine_test.go b/tests/e2e/admin/machine_test.go index 28b694f..b6ab8b9 100644 --- a/tests/e2e/admin/machine_test.go +++ b/tests/e2e/admin/machine_test.go @@ -288,6 +288,7 @@ func Test_MachineCmd_Create(t *testing.T) { "--partition", testresources.Machine2().Partition.Id, "--size", testresources.Machine2().Size.Id, "--ssh-public-key", "@.ssh/id_rsa.pub", + "--ssh-public-key", "ssh-ed25519 AAAA test", "--labels", "a=b", "--userdata", "@ignition.json", "--placement-labels", "cluster-id=cluster-uuid", @@ -311,7 +312,7 @@ func Test_MachineCmd_Create(t *testing.T) { Size: &testresources.Machine2().Size.Id, Image: testresources.Machine2().Allocation.Image.Id, FilesystemLayout: new("fsl1"), - SshPublicKeys: []string{"12345"}, + SshPublicKeys: []string{"12345", "ssh-ed25519 AAAA test"}, Userdata: new(base64.StdEncoding.EncodeToString([]byte("{}"))), Labels: &apiv2.Labels{ Labels: map[string]string{ diff --git a/tests/e2e/api/machine_test.go b/tests/e2e/api/machine_test.go index 97acf60..1f872b5 100644 --- a/tests/e2e/api/machine_test.go +++ b/tests/e2e/api/machine_test.go @@ -141,6 +141,7 @@ func Test_MachineCmd_Create(t *testing.T) { "--partition", testresources.Machine2().Partition.Id, "--size", testresources.Machine2().Size.Id, "--ssh-public-key", "@.ssh/id_rsa.pub", + "--ssh-public-key", "ssh-ed25519 AAAA test", "--labels", "a=b", "--userdata", "@ignition.json", "--placement-labels", "cluster-id=cluster-uuid", @@ -163,7 +164,7 @@ func Test_MachineCmd_Create(t *testing.T) { Size: &testresources.Machine2().Size.Id, Image: testresources.Machine2().Allocation.Image.Id, FilesystemLayout: new("fsl1"), - SshPublicKeys: []string{"12345"}, + SshPublicKeys: []string{"12345", "ssh-ed25519 AAAA test"}, Userdata: new(base64.StdEncoding.EncodeToString([]byte("{}"))), Labels: &apiv2.Labels{ Labels: map[string]string{