Skip to content

Commit 992e29d

Browse files
cjeannerpablintino
andcommitted
Ensure ssh_authorized_keys is a list in cloud-init
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]>
1 parent 9a04c56 commit 992e29d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pkg/openstackbaremetalset/baremetalhost.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ func BaremetalHostProvision(
7070
// User data cloud-init secret
7171
if userDataSecret == nil {
7272
templateParameters := make(map[string]interface{})
73-
templateParameters["AuthorizedKeys"] = strings.TrimSuffix(string(sshSecret.Data["authorized_keys"]), "\n")
73+
// Prepare ssh_authorized_keys list for template
74+
splitKeys := strings.Split(strings.TrimSuffix(string(sshSecret.Data["authorized_keys"]), "\n"), "\n")
75+
sshKeys := make([]string, len(splitKeys))
76+
sshKeys = append(sshKeys, splitKeys...)
77+
templateParameters["AuthorizedKeys"] = sshKeys
7478
templateParameters["HostName"] = bmhStatus.Hostname
7579
//If Hostname is fqdn, use it
7680
if !hostNameIsFQDN(bmhStatus.Hostname) && instance.Spec.DomainName != "" {

templates/openstackbaremetalset/cloudinit/userdata

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ hostname: {{ .HostName }}
44
fqdn: {{ .FQDN }}
55
users:
66
- name: {{ .CloudUserName }}
7-
ssh-authorized-keys: {{ .AuthorizedKeys }}
7+
ssh_authorized_keys:
8+
{{ range $ssh_key := .AuthorizedKeys }}
9+
- {{ $ssh_key }}
10+
{{ end }}
811
sudo: ['ALL=(ALL) NOPASSWD:ALL']
912
shell: /bin/bash
1013
{{- if (index . "NodeRootPassword") }}

0 commit comments

Comments
 (0)