Bug 1821024

Summary: Cloud init ssh authorized keys is not applied on the imported VM
Product: OpenShift Container Platform Reporter: Ilanit Stein <istein>
Component: Console Kubevirt PluginAssignee: Tomas Jelinek <tjelinek>
Status: CLOSED ERRATA QA Contact: Ilanit Stein <istein>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.2.0CC: aos-bugs, cnv-qe-bugs, fdeutsch, mlibra
Target Milestone: ---   
Target Release: 4.5.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: The VM wizard did not generate the cloud-init in correct format. Consequence: If the cloud-init configuration was used in the wizard, it was not applyed on the VM Fix: corrected the format generated by the wizard Result: the cloud-init configuration provided in the VM wizard is applyed on the VM.
Story Points: ---
Clone Of:
: 1821753 (view as bug list) Environment:
Last Closed: 2020-07-13 17:25:33 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1821753    
Attachments:
Description Flags
VM_yaml_file_screen_shot none

Description Ilanit Stein 2020-04-05 13:15:36 UTC
Created attachment 1676404 [details]
VM_yaml_file_screen_shot

Description of problem:
Import a RHEL7.6 VM that has cloud-init package installed, and cloud-init service enabled,
In the Import VM dialog, cloud init screen fill this custom script:

write_files:
-     path: "/tmp/test.txt"  
      content: Here is a line.

Import the VM, and then start the VM.
The file was not created on the VM, as expected, according to the provided custom script.

In the VM yaml file the cloudInitNoCloud section is in the attached cloud-init-in-yaml.png 

Version-Release number of selected component (if applicable):
CNV-2.2.0-10

Comment 1 Ilanit Stein 2020-04-05 14:51:46 UTC
This bug was initially reported in Bug 1786350, and was separated to this current bug.

Comment 2 Marek Libra 2020-04-06 11:48:54 UTC
With patch [1] applied, I followed:

- create Fedora 29 VM with cloud-init hostname and ssh_authorized_keys set via form in the UI
- and subsequently see /home/fedora/.ssh/authorized_keys to be filled with the key (so IIUC, this issue is fixed)

Next,
- turn off the VM
- edit VM's YAML to contain following:
```
       - cloudInitNoCloud:
            userData: |
              #cloud-config
              name: default
              hostname: my-host
              password: fedora
              chpasswd: { expire: False }
              write_files:
                - path: "/tmp/test.txt"
                  content: Here is a line.
              ssh_authorized_keys:
                - >-
                  ssh-rsa
                  AAAAB3ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ0Ig22WIK1rsnmvV2b0zbJEkRlDBaXOa1N/H/bC1YpKRWi2kiMVfh023vkTwOt/P4D8Db1tNEQxV8JS97JNli+6Oxas+mI6BdS+iSXjORCg5Dvghx8rHFvimHTJz35KW7
                  mlibra.redhat.com
          name: cloudinitdisk
```
- once the VM is started, I can still see proper content in the authorized_keys file, same as the expected content in the `/tmp/test.txt` file.

Next,
- Custom script entered by the UI form works as well (means: is executed).

So far I did not try on rhel-7.6 since I have difficulties to get the image. Will keep trying. 
I did not try within the v2v flow but the behavior should be the same in this part.

Ilanit, can you please confirm that this is the expected behavior?
And verify for both create and import RHEL-7.6 flows, please?

[1] https://github.com/openshift/console/pull/4923

Comment 3 Marek Libra 2020-04-06 12:16:52 UTC
Update: I have just succeeded with the steps above on RHEL 7.6 too

The only thing missing to be tested is v2v Import flow but the code is shared with the Create VM flow.

Comment 8 Ilanit Stein 2020-04-08 07:14:33 UTC
Based on Marek's verification, for cloud-init, both by form fill with ssh key, and custom script, in VM creation,
moving bug to verified.

Comment 9 errata-xmlrpc 2020-07-13 17:25:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:2409