Skip to content

Commit

Permalink
Merge pull request #1511 from steiler/srlsshkeys
Browse files Browse the repository at this point in the history
SSH Keys on SRL improvement
  • Loading branch information
hellt authored Aug 10, 2023
2 parents 9227b18 + e68469b commit 01ca47f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions nodes/srl/sshkey.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package srl

import (
"bytes"
"fmt"
"strings"

Expand All @@ -12,29 +13,24 @@ import (
// cli config command to set the ssh public keys
// for users.
func catenateKeys(in []ssh.PublicKey) string {
var keys string

for i, k := range in {
// marshall the publickey in authorizedKeys format
// and trim spaces (cause there will be a trailing newline)
ks := strings.TrimSpace(string(ssh.MarshalAuthorizedKey(k)))
// catenate all ssh keys into a single quoted string accepted in CLI
keys += fmt.Sprintf("%q", ks)
// only add a space after the key if it is not the last one
if i < len(in)-1 {
keys += " "
}
var keys strings.Builder
// iterate through keys
for _, k := range in {
// extract the keys in AuthorizedKeys format (e.g. "ssh-rsa <KEY>")
ks := bytes.TrimSpace(ssh.MarshalAuthorizedKey(k))
// add a seperator, leading quote, the key string and trailing quote
fmt.Fprintf(&keys, " \"%s\"", ks)
}

return keys
// return all but the first leading seperator of the string builders content as string
return keys.String()[1:]
}

// filterSSHPubKeys removes non-rsa keys from n.sshPubKeys until srl adds support for them.
func (n *srl) filterSSHPubKeys() {
filteredKeys := []ssh.PublicKey{}
var filteredKeys []ssh.PublicKey

for _, k := range n.sshPubKeys {
if k.Type() == "ssh-rsa" {
if k.Type() == ssh.KeyAlgoRSA {
filteredKeys = append(filteredKeys, k)
}
}
Expand Down

0 comments on commit 01ca47f

Please sign in to comment.