Skip to content

Commit

Permalink
Use list format for SSH authorized keys in OSBMS cloud-init
Browse files Browse the repository at this point in the history
  • Loading branch information
abays authored and openshift-cherrypick-robot committed May 6, 2024
1 parent 50c9289 commit 4619a27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion controllers/openstackbaremetalset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,14 @@ func (r *OpenStackBaremetalSetReconciler) cloudInitProvision(ctx context.Context
// Automatically generate user data cloud-init secret (i.e. user did not
// already manually create it for the BMH)
templateParameters := make(map[string]interface{})
templateParameters["AuthorizedKeys"] = sshSecret

// 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"] = hostName
templateParameters["DomainName"] = osNetCfg.Spec.DomainName

Expand Down
7 changes: 6 additions & 1 deletion templates/baremetalset/cloudinit/userdata
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
fqdn: {{ .Hostname }}{{ if .DomainName }}.{{ .DomainName }}{{ end }}
users:
- name: cloud-admin
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 .NodeRootPassword }}
Expand Down

0 comments on commit 4619a27

Please sign in to comment.