Skip to content

Commit

Permalink
Ensure ssh_authorized_keys is a list in cloud-init
Browse files Browse the repository at this point in the history
According to the official documentation[1], `ssh_authorized_keys` is a
list, not a string.

This patch should hopefully correct the issue we faced while trying to
inject multiple authorized keys: the cloud-init configuration file was
broken, preventing to apply any credential related data, leading to
failures when RHOSO deploy actually started.

[1] https://cloudinit.readthedocs.io/en/latest/reference/examples.html#configure-instance-s-ssh-keys

Co-Authored-By: @pablintino <[email protected]>
  • Loading branch information
cjeanner and pablintino committed Apr 30, 2024
1 parent 9a04c56 commit 432faf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/openstackbaremetalset/baremetalhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ func BaremetalHostProvision(
// User data cloud-init secret
if userDataSecret == nil {
templateParameters := make(map[string]interface{})
templateParameters["AuthorizedKeys"] = strings.TrimSuffix(string(sshSecret.Data["authorized_keys"]), "\n")
// Prepare ssh_authorized_keys list for template
splitKeys := strings.Split(strings.TrimSuffix(string(sshSecret.Data["authorized_keys"]), "\n"), "\n")
sshKeys := make([]string, len(splitKeys))
for _, key := range splitKeys {
sshKeys = append(sshKeys, key)
}
templateParameters["AuthorizedKeys"] = sshKeys
templateParameters["HostName"] = bmhStatus.Hostname
//If Hostname is fqdn, use it
if !hostNameIsFQDN(bmhStatus.Hostname) && instance.Spec.DomainName != "" {
Expand Down
5 changes: 4 additions & 1 deletion templates/openstackbaremetalset/cloudinit/userdata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ hostname: {{ .HostName }}
fqdn: {{ .FQDN }}
users:
- name: {{ .CloudUserName }}
ssh-authorized-keys: {{ .AuthorizedKeys }}
ssh_authorized_keys:
{{ range $ssh_key := .AuthorizedKeys }}
- {{ $ssh_key }}
{{ end }}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
shell: /bin/bash
{{- if (index . "NodeRootPassword") }}
Expand Down

0 comments on commit 432faf0

Please sign in to comment.