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 May 6, 2024
1 parent 9a04c56 commit e50810e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/openstackbaremetalset/baremetalhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ 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")

// Import from https://github.com/openstack-k8s-operators/osp-director-operator/pull/1043
// Split the keys into a list of separate strings, as cloud-init wants a list
// (a single-key string also works, but if there multiple keys in that string
// then passing the keys as a string results in *none* of them working, so it
// is better to create a list always)
splitKeys := strings.Split(strings.TrimSuffix(string(sshSecret), "\n"), "\n")
templateParameters["AuthorizedKeys"] = splitKeys

templateParameters["HostName"] = bmhStatus.Hostname
//If Hostname is fqdn, use it
if !hostNameIsFQDN(bmhStatus.Hostname) && instance.Spec.DomainName != "" {
Expand Down
7 changes: 6 additions & 1 deletion templates/openstackbaremetalset/cloudinit/userdata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ hostname: {{ .HostName }}
fqdn: {{ .FQDN }}
users:
- name: {{ .CloudUserName }}
ssh-authorized-keys: {{ .AuthorizedKeys }}
ssh_authorized_keys:
{{ range $ssh_key := .AuthorizedKeys }}
{{ if not (eq $ssh_key "") }}
- {{ $ssh_key }}
{{ end }}
{{ end }}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
shell: /bin/bash
{{- if (index . "NodeRootPassword") }}
Expand Down

0 comments on commit e50810e

Please sign in to comment.