134b57
From 5691fd1ce3eb430c8da19538b5988eba7da6d2be Mon Sep 17 00:00:00 2001
134b57
From: Eduardo Otubo <otubo@redhat.com>
134b57
Date: Thu, 21 Jan 2021 09:57:53 +0100
134b57
Subject: [PATCH] DataSourceAzure: update password for defuser if exists (#671)
134b57
134b57
RH-Author: Eduardo Terrell Ferrari Otubo (eterrell)
134b57
RH-MergeRequest: 36: DataSourceAzure: update password for defuser if exists (#671)
134b57
RH-Commit: [1/1] a834a44ca127480512137b4258ff01e993fbee41 (eterrell/cloud-init)
134b57
RH-Bugzilla: 1916839
134b57
134b57
commit eea754492f074e00b601cf77aa278e3623857c5a
134b57
Author: Anh Vo <anhvo@microsoft.com>
134b57
Date:   Thu Nov 19 00:35:46 2020 -0500
134b57
134b57
    DataSourceAzure: update password for defuser if exists (#671)
134b57
134b57
    cc_set_password will only update the password for the default user if
134b57
    cfg['password'] is set. The existing code of datasource Azure will fail
134b57
    to update the default user's password because it does not set that
134b57
    metadata. If the default user doesn't exist in the image, the current
134b57
    code works fine because the password is set during user create and
134b57
    not in cc_set_password
134b57
134b57
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
134b57
---
134b57
 cloudinit/sources/DataSourceAzure.py          | 2 +-
134b57
 tests/unittests/test_datasource/test_azure.py | 3 +++
134b57
 2 files changed, 4 insertions(+), 1 deletion(-)
134b57
134b57
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
134b57
index 6fb889c4..69454c40 100755
134b57
--- a/cloudinit/sources/DataSourceAzure.py
134b57
+++ b/cloudinit/sources/DataSourceAzure.py
134b57
@@ -1206,7 +1206,7 @@ def read_azure_ovf(contents):
134b57
     if password:
134b57
         defuser['lock_passwd'] = False
134b57
         if DEF_PASSWD_REDACTION != password:
134b57
-            defuser['passwd'] = encrypt_pass(password)
134b57
+            defuser['passwd'] = cfg['password'] = encrypt_pass(password)
134b57
 
134b57
     if defuser:
134b57
         cfg['system_info'] = {'default_user': defuser}
134b57
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
134b57
index a809fd87..f141dc6c 100644
134b57
--- a/tests/unittests/test_datasource/test_azure.py
134b57
+++ b/tests/unittests/test_datasource/test_azure.py
134b57
@@ -899,6 +899,9 @@ scbus-1 on xpt0 bus 0
134b57
                          crypt.crypt(odata['UserPassword'],
134b57
                                      defuser['passwd'][0:pos]))
134b57
 
134b57
+        # the same hashed value should also be present in cfg['password']
134b57
+        self.assertEqual(defuser['passwd'], dsrc.cfg['password'])
134b57
+
134b57
     def test_user_not_locked_if_password_redacted(self):
134b57
         odata = {'HostName': "myhost", 'UserName': "myuser",
134b57
                  'UserPassword': dsaz.DEF_PASSWD_REDACTION}
134b57
-- 
134b57
2.18.4
134b57