Skip to content

Commit e50810e

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 e50810e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/openstackbaremetalset/baremetalhost.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ 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+
74+
// Import from https://github.com/openstack-k8s-operators/osp-director-operator/pull/1043
75+
// Split the keys into a list of separate strings, as cloud-init wants a list
76+
// (a single-key string also works, but if there multiple keys in that string
77+
// then passing the keys as a string results in *none* of them working, so it
78+
// is better to create a list always)
79+
splitKeys := strings.Split(strings.TrimSuffix(string(sshSecret), "\n"), "\n")
80+
templateParameters["AuthorizedKeys"] = splitKeys
81+
7482
templateParameters["HostName"] = bmhStatus.Hostname
7583
//If Hostname is fqdn, use it
7684
if !hostNameIsFQDN(bmhStatus.Hostname) && instance.Spec.DomainName != "" {

templates/openstackbaremetalset/cloudinit/userdata

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ 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+
{{ if not (eq $ssh_key "") }}
10+
- {{ $ssh_key }}
11+
{{ end }}
12+
{{ end }}
813
sudo: ['ALL=(ALL) NOPASSWD:ALL']
914
shell: /bin/bash
1015
{{- if (index . "NodeRootPassword") }}

0 commit comments

Comments
 (0)